From a44bb26b133cd4cce94a52027aa7e90424337592 Mon Sep 17 00:00:00 2001 From: "guangjun.hgj" Date: Mon, 1 Jul 2024 14:22:54 +0800 Subject: [PATCH] resource/alicloud_oss_bucket: Improved the filed resource_group_id. --- alicloud/resource_alicloud_oss_bucket.go | 17 +++++++++++++++-- alicloud/resource_alicloud_oss_bucket_test.go | 3 +++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/alicloud/resource_alicloud_oss_bucket.go b/alicloud/resource_alicloud_oss_bucket.go index d04619cf7cd0..1d8d9d22e92d 100644 --- a/alicloud/resource_alicloud_oss_bucket.go +++ b/alicloud/resource_alicloud_oss_bucket.go @@ -512,8 +512,21 @@ func resourceAlicloudOssBucketCreate(d *schema.ResourceData, meta interface{}) e oss.RedundancyType(oss.DataRedundancyType(d.Get("redundancy_type").(string))), oss.ACL(oss.ACLType(d.Get("acl").(string))), } + options := []oss.Option{ + req.StorageClassOption, + req.RedundancyTypeOption, + req.AclTypeOption, + } + + //resource_group_id + if resourceGroupId, ok := d.Get("resource_group_id").(string); ok { + if len(resourceGroupId) > 0 { + options = append(options, oss.SetHeader("x-oss-resource-group-id", resourceGroupId)) + } + } + raw, err = client.WithOssClient(func(ossClient *oss.Client) (interface{}, error) { - return nil, ossClient.CreateBucket(req.BucketName, req.StorageClassOption, req.RedundancyTypeOption, req.AclTypeOption) + return nil, ossClient.CreateBucket(req.BucketName, options...) }) if err != nil { return WrapErrorf(err, DefaultErrorMsg, "alicloud_oss_bucket", "CreateBucket", AliyunOssGoSdk) @@ -1043,7 +1056,7 @@ func resourceAlicloudOssBucketUpdate(d *schema.ResourceData, meta interface{}) e d.SetPartial("transfer_acceleration") } - if d.HasChange("resource_group_id") { + if !d.IsNewResource() && d.HasChange("resource_group_id") { resourceGroupId := d.Get("resource_group_id").(string) request := map[string]string{"bucketName": d.Id(), "resourceGroupId": resourceGroupId} var requestInfo *oss.Client diff --git a/alicloud/resource_alicloud_oss_bucket_test.go b/alicloud/resource_alicloud_oss_bucket_test.go index 343bee7f72bb..2ad97d146fc6 100644 --- a/alicloud/resource_alicloud_oss_bucket_test.go +++ b/alicloud/resource_alicloud_oss_bucket_test.go @@ -2225,6 +2225,7 @@ func TestAccAliCloudOssBucketResourceGroup(t *testing.T) { Config: testAccConfig(map[string]interface{}{ "bucket": name, "resource_group_id": "${data.alicloud_resource_manager_resource_groups.default.groups.1.id}", + "redundancy_type": "LRS", }), Check: resource.ComposeTestCheckFunc( testAccCheck(map[string]string{ @@ -2232,6 +2233,7 @@ func TestAccAliCloudOssBucketResourceGroup(t *testing.T) { "access_monitor.#": "1", "access_monitor.0.status": "Disabled", "resource_group_id": CHECKSET, + "redundancy_type": "LRS", }), ), }, @@ -2244,6 +2246,7 @@ func TestAccAliCloudOssBucketResourceGroup(t *testing.T) { { Config: testAccConfig(map[string]interface{}{ "resource_group_id": "${data.alicloud_resource_manager_resource_groups.default.groups.0.id}", + "force_destroy": true, }), Check: resource.ComposeTestCheckFunc( testAccCheck(map[string]string{