-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
provider/aws: Added aws_iam_login_profile custom password setting #10734
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,7 +90,27 @@ func TestAccAWSUserLoginProfile_notAKey(t *testing.T) { | |
{ | ||
// We own this account but it doesn't have any key associated with it | ||
Config: testAccAWSUserLoginProfileConfig(username, "/", "lolimnotakey"), | ||
ExpectError: regexp.MustCompile(`Error encrypting password`), | ||
ExpectError: regexp.MustCompile(`Error encrypting Password`), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccAWSUserLoginProfile_customPassword(t *testing.T) { | ||
var conf iam.GetLoginProfileOutput | ||
|
||
username := fmt.Sprintf("test-user-%d", acctest.RandInt()) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAWSUserLoginProfileDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAWSUserLoginProfileConfigCustomPassword(username, "/", "MyP@ssw0rd@#$!@#$^&*()_+-=[]{}|'%"), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSUserLoginProfileExists("aws_iam_user_login_profile.user", &conf), | ||
), | ||
}, | ||
}, | ||
}) | ||
|
@@ -169,7 +189,7 @@ func testDecryptPasswordAndTest(nProfile, nAccessKey, key string) resource.TestC | |
NewPassword: aws.String(generatePassword(20)), | ||
}) | ||
if err != nil { | ||
if awserr, ok := err.(awserr.Error); ok && awserr.Code() == "InvalidClientTokenId" { | ||
if awserr, ok := err.(awserr.Error); ok && (awserr.Code() == "InvalidClientTokenId" || awserr.Code() == "EntityTemporarilyUnmodifiable") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is required since I encountered this error:
|
||
return resource.RetryableError(err) | ||
} | ||
|
||
|
@@ -206,46 +226,58 @@ func testAccCheckAWSUserLoginProfileExists(n string, res *iam.GetLoginProfileOut | |
} | ||
} | ||
|
||
func testAccAWSUserLoginProfileConfig(r, p, key string) string { | ||
return fmt.Sprintf(` | ||
const testAccAWSUserLoginProfileBaseConfig = ` | ||
resource "aws_iam_user" "user" { | ||
name = "%s" | ||
path = "%s" | ||
force_destroy = true | ||
name = "%s" | ||
path = "%s" | ||
force_destroy = true | ||
} | ||
|
||
data "aws_caller_identity" "current" {} | ||
|
||
data "aws_iam_policy_document" "user" { | ||
statement { | ||
effect = "Allow" | ||
actions = ["iam:GetAccountPasswordPolicy"] | ||
resources = ["*"] | ||
} | ||
statement { | ||
effect = "Allow" | ||
actions = ["iam:ChangePassword"] | ||
resources = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:user/&{aws:username}"] | ||
} | ||
statement { | ||
effect = "Allow" | ||
actions = ["iam:GetAccountPasswordPolicy"] | ||
resources = ["*"] | ||
} | ||
statement { | ||
effect = "Allow" | ||
actions = ["iam:ChangePassword"] | ||
resources = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:user/&{aws:username}"] | ||
} | ||
} | ||
|
||
resource "aws_iam_user_policy" "user" { | ||
name = "AllowChangeOwnPassword" | ||
user = "${aws_iam_user.user.name}" | ||
policy = "${data.aws_iam_policy_document.user.json}" | ||
name = "AllowChangeOwnPassword" | ||
user = "${aws_iam_user.user.name}" | ||
policy = "${data.aws_iam_policy_document.user.json}" | ||
} | ||
|
||
resource "aws_iam_access_key" "user" { | ||
user = "${aws_iam_user.user.name}" | ||
user = "${aws_iam_user.user.name}" | ||
} | ||
` | ||
|
||
func testAccAWSUserLoginProfileConfig(r, p, key string) string { | ||
return fmt.Sprintf(testAccAWSUserLoginProfileBaseConfig+` | ||
resource "aws_iam_user_login_profile" "user" { | ||
user = "${aws_iam_user.user.name}" | ||
pgp_key = "%s" | ||
pgp_key = <<EOF | ||
%sEOF | ||
} | ||
`, r, p, key) | ||
} | ||
|
||
func testAccAWSUserLoginProfileConfigCustomPassword(r, p, password string) string { | ||
return fmt.Sprintf(testAccAWSUserLoginProfileBaseConfig+` | ||
resource "aws_iam_user_login_profile" "user" { | ||
user = "${aws_iam_user.user.name}" | ||
password = "%s" | ||
} | ||
`, r, p, password) | ||
} | ||
|
||
const testPubKey1 = `mQENBFXbjPUBCADjNjCUQwfxKL+RR2GA6pv/1K+zJZ8UWIF9S0lk7cVIEfJiprzzwiMwBS5cD0da | ||
rGin1FHvIWOZxujA7oW0O2TUuatqI3aAYDTfRYurh6iKLC+VS+F7H+/mhfFvKmgr0Y5kDCF1j0T/ | ||
063QZ84IRGucR/X43IY7kAtmxGXH0dYOCzOe5UBX1fTn3mXGe2ImCDWBH7gOViynXmb6XNvXkP0f | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a typo here for
password
, with error: