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 group status handling #484

Merged
merged 3 commits into from
Jul 11, 2023
Merged
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
31 changes: 23 additions & 8 deletions minio/resource_minio_iam_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ func minioCreateGroup(ctx context.Context, d *schema.ResourceData, meta interfac
return NewResourceError("creating group failed", d.Id(), err)
}

err = minioStatusGroup(ctx, d, meta)
if err != nil {
return NewResourceError("error updating IAM Group %s: %s", d.Id(), err)
}

d.SetId(aws.StringValue(&iamGroupConfig.MinioIAMName))

return minioReadGroup(ctx, d, meta)
Expand Down Expand Up @@ -97,11 +102,9 @@ func minioUpdateGroup(ctx context.Context, d *schema.ResourceData, meta interfac
d.SetId(nn.(string))
}

if iamGroupConfig.MinioDisableGroup {
err := minioDisableGroup(ctx, d, meta)
if err != nil {
return NewResourceError("error updating IAM Group %s: %s", d.Id(), err)
}
err := minioStatusGroup(ctx, d, meta)
if err != nil {
return NewResourceError("error updating IAM Group %s: %s", d.Id(), err)
}

if iamGroupConfig.MinioForceDestroy {
Expand Down Expand Up @@ -134,6 +137,10 @@ func minioReadGroup(ctx context.Context, d *schema.ResourceData, meta interface{
return NewResourceError("error reading IAM Group %s: %s", d.Id(), err)
}

if err := d.Set("disable_group", output.Status == string(madmin.GroupDisabled)); err != nil {
return NewResourceError("error reading IAM Group %s: %s", d.Id(), err)
}

return nil
}

Expand Down Expand Up @@ -185,16 +192,24 @@ func minioDeleteGroup(ctx context.Context, d *schema.ResourceData, meta interfac
return nil
}

func minioDisableGroup(ctx context.Context, d *schema.ResourceData, meta interface{}) error {
func minioStatusGroup(ctx context.Context, d *schema.ResourceData, meta interface{}) error {

var minioGroupStatus madmin.GroupStatus

iamGroupConfig := IAMGroupConfig(d, meta)

log.Println("[DEBUG] Disabling IAM Group request:", iamGroupConfig.MinioIAMName)

err := iamGroupConfig.MinioAdmin.SetGroupStatus(ctx, iamGroupConfig.MinioIAMName, madmin.GroupDisabled)
if iamGroupConfig.MinioDisableGroup {
minioGroupStatus = madmin.GroupDisabled
} else {
minioGroupStatus = madmin.GroupEnabled
}

err := iamGroupConfig.MinioAdmin.SetGroupStatus(ctx, iamGroupConfig.MinioIAMName, minioGroupStatus)

if err != nil {
return fmt.Errorf("error disabling IAM Group %s: %s", d.Id(), err)
return fmt.Errorf("error while enabling or disabling IAM Group %s: %s", d.Id(), err)
}

return nil
Expand Down