Skip to content

Commit

Permalink
Fix updating minio_iam_user name (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjsier authored Nov 12, 2022
1 parent 1767110 commit fdc30f5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
18 changes: 1 addition & 17 deletions minio/resource_minio_iam_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func resourceMinioIAMUser() *schema.Resource {
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateMinioIamUserName,
},
"force_destroy": {
Expand Down Expand Up @@ -107,23 +108,6 @@ func minioUpdateUser(ctx context.Context, d *schema.ResourceData, meta interface
}
}

if d.HasChange(iamUserConfig.MinioIAMName) {
on, nn := d.GetChange(iamUserConfig.MinioIAMName)

log.Println("[DEBUG] Update IAM User:", iamUserConfig.MinioIAMName)
err := iamUserConfig.MinioAdmin.RemoveUser(ctx, on.(string))
if err != nil {
return NewResourceError("error updating IAM User %s: %s", d.Id(), err)
}

err = iamUserConfig.MinioAdmin.AddUser(ctx, nn.(string), secretKey)
if err != nil {
return NewResourceError("error updating IAM User %s: %s", d.Id(), err)
}

d.SetId(nn.(string))
}

userStatus := UserStatus{
AccessKey: iamUserConfig.MinioIAMName,
SecretKey: secretKey,
Expand Down
29 changes: 29 additions & 0 deletions minio/resource_minio_iam_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,35 @@ func TestAccAWSUser_basic(t *testing.T) {
})
}

func TestAccAWSUser_UpdateName(t *testing.T) {
var user madmin.UserInfo

name := fmt.Sprintf("test-user-%d", acctest.RandInt())
status := "enabled"
resourceName := "minio_iam_user.test"
updatedName := fmt.Sprintf("test-user-%d", acctest.RandInt())

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviders,
CheckDestroy: testAccCheckMinioUserDestroy,
Steps: []resource.TestStep{
{
Config: testAccMinioUserConfig(name),
Check: resource.ComposeTestCheckFunc(
testAccCheckMinioUserExists(resourceName, &user),
),
},
{
Config: testAccMinioUserConfig(updatedName),
Check: resource.ComposeTestCheckFunc(
testAccCheckMinioUserAttributes(resourceName, updatedName, status),
),
},
},
})
}

func TestAccAWSUser_DisableUser(t *testing.T) {
var user madmin.UserInfo

Expand Down

0 comments on commit fdc30f5

Please sign in to comment.