Skip to content

Commit

Permalink
provider/aws: Don't fail if login profile exists
Browse files Browse the repository at this point in the history
If an IAM user already has a login profile, we bring it under management
- we will NOT modify it - but we cannot set the password.
  • Loading branch information
jen20 committed Oct 25, 2016
1 parent dba3ec2 commit 586ad44
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions builtin/providers/aws/resource_aws_iam_user_login_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"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/errwrap"
"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -147,6 +148,13 @@ func resourceAwsIamUserLoginProfileCreate(d *schema.ResourceData, meta interface
log.Println("[DEBUG] Create IAM User Login Profile request:", request)
createResp, err := iamconn.CreateLoginProfile(request)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "EntityAlreadyExists" {
// If there is already a login profile, bring it under management (to prevent
// resource creation diffs) - we will never modify it, but obviously cannot
// set the password.
d.SetId(*createResp.LoginProfile.UserName)
return nil
}
return errwrap.Wrapf(fmt.Sprintf("Error creating IAM User Login Profile for %q: {{err}}", username), err)
}

Expand Down

0 comments on commit 586ad44

Please sign in to comment.