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

Fix updating minio_iam_user name #383

Merged
merged 1 commit into from
Nov 12, 2022
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
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