Skip to content

Commit 9b8900f

Browse files
authored
cos bucket supports acl_body import (#2417)
* cos bucket supports acl_body import * add changelog 2417.txt * update cos bucket import test * remove commented test code
1 parent baec893 commit 9b8900f

File tree

3 files changed

+39
-53
lines changed

3 files changed

+39
-53
lines changed

.changelog/2417.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_cos_bucket: Support `acl_body` import.
3+
```

tencentcloud/services/cos/resource_tc_cos_bucket.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func ResourceTencentCloudCosBucket() *schema.Resource {
175175
"acl_body": {
176176
Type: schema.TypeString,
177177
Optional: true,
178-
178+
Computed: true,
179179
DiffSuppressFunc: func(k, olds, news string, d *schema.ResourceData) bool {
180180
return ACLBodyDiffFunc(olds, news, d)
181181
},
@@ -607,13 +607,12 @@ func resourceTencentCloudCosBucketRead(d *schema.ResourceData, meta interface{})
607607
}
608608

609609
aclBody, err := xml.Marshal(aclResult)
610-
611610
if err != nil {
612-
log.Printf("[WARN] Marshal XML Error: %s", err.Error())
613-
} else if v, ok := d.Get("acl_body").(string); ok && v != "" {
614-
_ = d.Set("acl_body", string(aclBody))
611+
return err
615612
}
616613

614+
_ = d.Set("acl_body", string(aclBody))
615+
617616
acl := GetBucketPublicACL(aclResult)
618617

619618
_ = d.Set("acl", acl)

tencentcloud/services/cos/resource_tc_cos_bucket_test.go

Lines changed: 32 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,8 @@ func TestAccTencentCloudCosBucketResource_basic(t *testing.T) {
9494
),
9595
},
9696
{
97-
ResourceName: "tencentcloud_cos_bucket.bucket_basic",
98-
ImportState: true,
99-
ImportStateVerify: true,
100-
ImportStateVerifyIgnore: []string{"force_clean"},
97+
ResourceName: "tencentcloud_cos_bucket.bucket_basic",
98+
ImportState: true,
10199
},
102100
},
103101
})
@@ -129,10 +127,8 @@ func TestAccTencentCloudCosBucketResource_ACL(t *testing.T) {
129127
),
130128
},
131129
{
132-
ResourceName: "tencentcloud_cos_bucket.bucket_acl",
133-
ImportState: true,
134-
ImportStateVerify: true,
135-
ImportStateVerifyIgnore: []string{"acl_body"},
130+
ResourceName: "tencentcloud_cos_bucket.bucket_acl",
131+
ImportState: true,
136132
},
137133
},
138134
})
@@ -212,10 +208,8 @@ func TestAccTencentCloudCosBucketResource_cors(t *testing.T) {
212208
),
213209
},
214210
{
215-
ResourceName: "tencentcloud_cos_bucket.bucket_cors",
216-
ImportState: true,
217-
ImportStateVerify: true,
218-
ImportStateVerifyIgnore: []string{"acl"},
211+
ResourceName: "tencentcloud_cos_bucket.bucket_cors",
212+
ImportState: true,
219213
},
220214
},
221215
})
@@ -282,10 +276,8 @@ func TestAccTencentCloudCosBucketResource_lifecycle(t *testing.T) {
282276
),
283277
},
284278
{
285-
ResourceName: "tencentcloud_cos_bucket.bucket_lifecycle",
286-
ImportState: true,
287-
ImportStateVerify: true,
288-
ImportStateVerifyIgnore: []string{"acl"},
279+
ResourceName: "tencentcloud_cos_bucket.bucket_lifecycle",
280+
ImportState: true,
289281
},
290282
},
291283
})
@@ -321,10 +313,8 @@ func TestAccTencentCloudCosBucketResource_website(t *testing.T) {
321313
),
322314
},
323315
{
324-
ResourceName: "tencentcloud_cos_bucket.bucket_website",
325-
ImportState: true,
326-
ImportStateVerify: true,
327-
ImportStateVerifyIgnore: []string{"acl"},
316+
ResourceName: "tencentcloud_cos_bucket.bucket_website",
317+
ImportState: true,
328318
},
329319
},
330320
})
@@ -346,10 +336,8 @@ func TestAccTencentCloudCosBucketResource_MAZ(t *testing.T) {
346336
),
347337
},
348338
{
349-
ResourceName: "tencentcloud_cos_bucket.bucket_maz",
350-
ImportState: true,
351-
ImportStateVerify: true,
352-
ImportStateVerifyIgnore: []string{"acl", "multi_az"},
339+
ResourceName: "tencentcloud_cos_bucket.bucket_maz",
340+
ImportState: true,
353341
},
354342
},
355343
})
@@ -398,10 +386,8 @@ func TestAccTencentCloudCosBucketResource_originPull(t *testing.T) {
398386
),
399387
},
400388
{
401-
ResourceName: "tencentcloud_cos_bucket.with_origin",
402-
ImportState: true,
403-
ImportStateVerify: true,
404-
ImportStateVerifyIgnore: []string{"acl"},
389+
ResourceName: "tencentcloud_cos_bucket.with_origin",
390+
ImportState: true,
405391
},
406392
},
407393
})
@@ -485,10 +471,8 @@ func TestAccTencentCloudCosBucketResource_replication(t *testing.T) {
485471
),
486472
},
487473
{
488-
ResourceName: "tencentcloud_cos_bucket.with_replication",
489-
ImportState: true,
490-
ImportStateVerify: true,
491-
ImportStateVerifyIgnore: []string{"acl", "replica_role"},
474+
ResourceName: "tencentcloud_cos_bucket.with_replication",
475+
ImportState: true,
492476
},
493477
},
494478
})
@@ -570,8 +554,8 @@ resource "tencentcloud_cos_bucket" "bucket_acl" {
570554
acl_body = <<EOF
571555
<AccessControlPolicy>
572556
<Owner>
573-
<ID>qcs::cam::uin/${local.uin}:uin/${local.uin}</ID>
574-
<DisplayName>qcs::cam::uin/${local.uin}:uin/${local.uin}</DisplayName>
557+
<ID>qcs::cam::uin/${local.owner_uin}:uin/${local.owner_uin}</ID>
558+
<DisplayName>qcs::cam::uin/${local.owner_uin}:uin/${local.owner_uin}</DisplayName>
575559
</Owner>
576560
<AccessControlList>
577561
<Grant>
@@ -582,15 +566,15 @@ resource "tencentcloud_cos_bucket" "bucket_acl" {
582566
</Grant>
583567
<Grant>
584568
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
585-
<ID>qcs::cam::uin/${local.uin}:uin/${local.uin}</ID>
586-
<DisplayName>qcs::cam::uin/${local.uin}:uin/${local.uin}</DisplayName>
569+
<ID>qcs::cam::uin/${local.owner_uin}:uin/${local.owner_uin}</ID>
570+
<DisplayName>qcs::cam::uin/${local.owner_uin}:uin/${local.owner_uin}</DisplayName>
587571
</Grantee>
588572
<Permission>READ</Permission>
589573
</Grant>
590574
<Grant>
591575
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
592-
<ID>qcs::cam::uin/${local.uin}:uin/${local.uin}</ID>
593-
<DisplayName>qcs::cam::uin/${local.uin}:uin/${local.uin}</DisplayName>
576+
<ID>qcs::cam::uin/${local.owner_uin}:uin/${local.owner_uin}</ID>
577+
<DisplayName>qcs::cam::uin/${local.owner_uin}:uin/${local.owner_uin}</DisplayName>
594578
</Grantee>
595579
<Permission>FULL_CONTROL</Permission>
596580
</Grant>
@@ -611,8 +595,8 @@ resource "tencentcloud_cos_bucket" "bucket_acl" {
611595
acl_body = <<EOF
612596
<AccessControlPolicy>
613597
<Owner>
614-
<ID>qcs::cam::uin/${local.uin}:uin/${local.uin}</ID>
615-
<DisplayName>qcs::cam::uin/${local.uin}:uin/${local.uin}</DisplayName>
598+
<ID>qcs::cam::uin/${local.owner_uin}:uin/${local.owner_uin}</ID>
599+
<DisplayName>qcs::cam::uin/${local.owner_uin}:uin/${local.owner_uin}</DisplayName>
616600
</Owner>
617601
<AccessControlList>
618602
<Grant>
@@ -623,15 +607,15 @@ resource "tencentcloud_cos_bucket" "bucket_acl" {
623607
</Grant>
624608
<Grant>
625609
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
626-
<ID>qcs::cam::uin/${local.uin}:uin/${local.uin}</ID>
627-
<DisplayName>qcs::cam::uin/${local.uin}:uin/${local.uin}</DisplayName>
610+
<ID>qcs::cam::uin/${local.owner_uin}:uin/${local.owner_uin}</ID>
611+
<DisplayName>qcs::cam::uin/${local.owner_uin}:uin/${local.owner_uin}</DisplayName>
628612
</Grantee>
629613
<Permission>FULL_CONTROL</Permission>
630614
</Grant>
631615
<Grant>
632616
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
633-
<ID>qcs::cam::uin/${local.uin}:uin/${local.uin}</ID>
634-
<DisplayName>qcs::cam::uin/${local.uin}:uin/${local.uin}</DisplayName>
617+
<ID>qcs::cam::uin/${local.owner_uin}:uin/${local.owner_uin}</ID>
618+
<DisplayName>qcs::cam::uin/${local.owner_uin}:uin/${local.owner_uin}</DisplayName>
635619
</Grantee>
636620
<Permission>WRITE_ACP</Permission>
637621
</Grant>
@@ -643,15 +627,15 @@ resource "tencentcloud_cos_bucket" "bucket_acl" {
643627
</Grant>
644628
<Grant>
645629
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
646-
<ID>qcs::cam::uin/${local.uin}:uin/${local.uin}</ID>
647-
<DisplayName>qcs::cam::uin/${local.uin}:uin/${local.uin}</DisplayName>
630+
<ID>qcs::cam::uin/${local.owner_uin}:uin/${local.owner_uin}</ID>
631+
<DisplayName>qcs::cam::uin/${local.owner_uin}:uin/${local.owner_uin}</DisplayName>
648632
</Grantee>
649633
<Permission>READ</Permission>
650634
</Grant>
651635
<Grant>
652636
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
653-
<ID>qcs::cam::uin/${local.uin}:uin/${local.uin}</ID>
654-
<DisplayName>qcs::cam::uin/${local.uin}:uin/${local.uin}</DisplayName>
637+
<ID>qcs::cam::uin/${local.owner_uin}:uin/${local.owner_uin}</ID>
638+
<DisplayName>qcs::cam::uin/${local.owner_uin}:uin/${local.owner_uin}</DisplayName>
655639
</Grantee>
656640
<Permission>WRITE</Permission>
657641
</Grant>

0 commit comments

Comments
 (0)