Skip to content
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

resource/aws_iam_user: Retry user login profile deletion on EntityTemporarilyUnmodifiable #4143

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions aws/resource_aws_iam_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"fmt"
"log"
"regexp"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/iam"

"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
)

Expand Down Expand Up @@ -218,13 +220,25 @@ func resourceAwsIamUserDelete(d *schema.ResourceData, meta interface{}) error {
}
}

_, err = iamconn.DeleteLoginProfile(&iam.DeleteLoginProfileInput{
UserName: aws.String(d.Id()),
err = resource.Retry(1*time.Minute, func() *resource.RetryError {
_, err = iamconn.DeleteLoginProfile(&iam.DeleteLoginProfileInput{
UserName: aws.String(d.Id()),
})
if err != nil {
if isAWSErr(err, iam.ErrCodeNoSuchEntityException, "") {
return nil
}
// EntityTemporarilyUnmodifiable: Login Profile for User XXX cannot be modified while login profile is being created.
if isAWSErr(err, iam.ErrCodeEntityTemporarilyUnmodifiableException, "") {
return resource.RetryableError(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if its required, but there is no return resource.NonRetryableError() so any error that is not iam.ErrCodeEntityTemporarilyUnmodifiableException will return a nil unlike in the resource_aws_iam_user_login_profile_test.go.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch, we definitely want that in there. Thanks and updated! 👍

return resource.NonRetryableError(err)
}
return nil
})

if err != nil {
if iamerr, ok := err.(awserr.Error); !ok || iamerr.Code() != "NoSuchEntity" {
return fmt.Errorf("Error deleting Account Login Profile: %s", err)
}
return fmt.Errorf("Error deleting Account Login Profile: %s", err)
}
}

Expand Down
6 changes: 5 additions & 1 deletion aws/resource_aws_iam_user_login_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,11 @@ func testDecryptPasswordAndTest(nProfile, nAccessKey, key string) resource.TestC
NewPassword: aws.String(generateIAMPassword(20)),
})
if err != nil {
if awserr, ok := err.(awserr.Error); ok && awserr.Code() == "InvalidClientTokenId" {
// EntityTemporarilyUnmodifiable: Login Profile for User XXX cannot be modified while login profile is being created.
if isAWSErr(err, iam.ErrCodeEntityTemporarilyUnmodifiableException, "") {
return resource.RetryableError(err)
}
if isAWSErr(err, "InvalidClientTokenId", "") {
return resource.RetryableError(err)
}

Expand Down