Skip to content

Commit

Permalink
Implement bflads more beautiful code.
Browse files Browse the repository at this point in the history
  • Loading branch information
fbreckle committed Feb 14, 2019
1 parent a962934 commit 30a9583
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions aws/resource_aws_iam_user_login_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,24 @@ func resourceAwsIamUserLoginProfileCreate(d *schema.ResourceData, meta interface
passwordResetRequired := d.Get("password_reset_required").(bool)
passwordLength := d.Get("password_length").(int)

// DEPRECATED: Automatic import will be removed in a future major version update
// https://github.com/terraform-providers/terraform-provider-aws/issues/7536
_, err = iamconn.GetLoginProfile(&iam.GetLoginProfileInput{
UserName: aws.String(username),
})
if err != nil {
// Catch AccessDenid errors (e.g. because we have no iam:GetLoginProfile permissions)
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "AccessDenied" {
return err
}
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() != "NoSuchEntity" {
// 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(username)
d.Set("key_fingerprint", "")
d.Set("encrypted_password", "")
return nil
}

// 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.
if err == nil {
d.SetId(username)
d.Set("key_fingerprint", "")
d.Set("encrypted_password", "")
return nil
}

if !isAWSErr(err, iam.ErrCodeNoSuchEntityException, "") {
return fmt.Errorf("Error checking for existing IAM User Login Profile: %s", err)
}

initialPassword := generateIAMPassword(passwordLength)
Expand Down

0 comments on commit 30a9583

Please sign in to comment.