From 5d4d6a7b0e3c3cb2062a4e0b1d69a89a997032d2 Mon Sep 17 00:00:00 2001 From: Capybara DevCloud <127902387+asdevcapybara@users.noreply.github.com> Date: Tue, 11 Jul 2023 21:45:34 +0200 Subject: [PATCH] Fix the toggle of `disable_group` option in "minio_iam_group" resource (#484) Co-authored-by: Victor Nogueira --- minio/resource_minio_iam_group.go | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/minio/resource_minio_iam_group.go b/minio/resource_minio_iam_group.go index 7c1882ba..6a584fe7 100644 --- a/minio/resource_minio_iam_group.go +++ b/minio/resource_minio_iam_group.go @@ -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) @@ -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 { @@ -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 } @@ -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