Skip to content

Commit 638e88d

Browse files
SevenEarthgitmkn
andauthored
fix(cos): [118298226] tencentcloud_cos_bucket support acl for cdc (#2860)
* add * add * fix: update cos doc --------- Co-authored-by: arunma <arunma@tencent.com>
1 parent 343cd45 commit 638e88d

File tree

8 files changed

+228
-17
lines changed

8 files changed

+228
-17
lines changed

.changelog/2860.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 for cdc
3+
```

tencentcloud/services/cos/resource_tc_cos_bucket.md

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Provides a COS resource to create a COS bucket and set its attributes.
22

3+
~> **NOTE:** The following capabilities do not support cdc scenarios: `multi_az`, `website`, and bucket replication `replica_role`.
4+
35
Example Usage
46

57
Private Bucket
@@ -20,6 +22,16 @@ resource "tencentcloud_cos_bucket" "private_bucket" {
2022
Private Bucket with CDC cluster
2123

2224
```hcl
25+
provider "tencentcloud" {
26+
cos_domain = "https://${local.cdc_id}.cos-cdc.${local.region}.myqcloud.com/"
27+
region = local.region
28+
}
29+
30+
locals {
31+
region = "ap-guangzhou"
32+
cdc_id = "cluster-262n63e8"
33+
}
34+
2335
data "tencentcloud_user_info" "info" {}
2436
2537
locals {
@@ -28,7 +40,6 @@ locals {
2840
2941
resource "tencentcloud_cos_bucket" "private_bucket" {
3042
bucket = "private-bucket-${local.app_id}"
31-
cdc_id = "cluster-262n63e8"
3243
acl = "private"
3344
versioning_enable = true
3445
force_clean = true
@@ -161,6 +172,55 @@ EOF
161172
}
162173
```
163174

175+
Using verbose acl with CDC cluster
176+
177+
```hcl
178+
provider "tencentcloud" {
179+
cos_domain = "https://${local.cdc_id}.cos-cdc.${local.region}.myqcloud.com/"
180+
region = local.region
181+
}
182+
183+
locals {
184+
region = "ap-guangzhou"
185+
cdc_id = "cluster-262n63e8"
186+
}
187+
188+
data "tencentcloud_user_info" "info" {}
189+
190+
locals {
191+
app_id = data.tencentcloud_user_info.info.app_id
192+
}
193+
194+
resource "tencentcloud_cos_bucket" "bucket_with_acl" {
195+
bucket = "private-bucket-${local.app_id}"
196+
acl = "private"
197+
acl_body = <<EOF
198+
<AccessControlPolicy>
199+
<Owner>
200+
<ID>qcs::cam::uin/100023201586:uin/100023201586</ID>
201+
<DisplayName>qcs::cam::uin/100023201586:uin/100023201586</DisplayName>
202+
</Owner>
203+
<AccessControlList>
204+
<Grant>
205+
<Grantee type="CanonicalUser">
206+
<ID>qcs::cam::uin/100015006748:uin/100015006748</ID>
207+
<DisplayName>qcs::cam::uin/100015006748:uin/100015006748</DisplayName>
208+
</Grantee>
209+
<Permission>WRITE</Permission>
210+
</Grant>
211+
<Grant>
212+
<Grantee type="CanonicalUser">
213+
<ID>qcs::cam::uin/100023201586:uin/100023201586</ID>
214+
<DisplayName>qcs::cam::uin/100023201586:uin/100023201586</DisplayName>
215+
</Grantee>
216+
<Permission>FULL_CONTROL</Permission>
217+
</Grant>
218+
</AccessControlList>
219+
</AccessControlPolicy>
220+
EOF
221+
}
222+
```
223+
164224
Static Website
165225

166226
```hcl
@@ -210,6 +270,16 @@ resource "tencentcloud_cos_bucket" "bucket_with_cors" {
210270
Using CORS with CDC
211271

212272
```hcl
273+
provider "tencentcloud" {
274+
cos_domain = "https://${local.cdc_id}.cos-cdc.${local.region}.myqcloud.com/"
275+
region = local.region
276+
}
277+
278+
locals {
279+
region = "ap-guangzhou"
280+
cdc_id = "cluster-262n63e8"
281+
}
282+
213283
data "tencentcloud_user_info" "info" {}
214284
215285
locals {
@@ -218,7 +288,6 @@ locals {
218288
219289
resource "tencentcloud_cos_bucket" "bucket_with_cors" {
220290
bucket = "bucket-with-cors-${local.app_id}"
221-
cdc_id = "cluster-262n63e8"
222291
223292
cors_rules {
224293
allowed_origins = ["http://*.abc.com"]
@@ -261,6 +330,16 @@ resource "tencentcloud_cos_bucket" "bucket_with_lifecycle" {
261330
Using object lifecycle with CDC
262331

263332
```hcl
333+
provider "tencentcloud" {
334+
cos_domain = "https://${local.cdc_id}.cos-cdc.${local.region}.myqcloud.com/"
335+
region = local.region
336+
}
337+
338+
locals {
339+
region = "ap-guangzhou"
340+
cdc_id = "cluster-262n63e8"
341+
}
342+
264343
data "tencentcloud_user_info" "info" {}
265344
266345
locals {
@@ -269,7 +348,6 @@ locals {
269348
270349
resource "tencentcloud_cos_bucket" "bucket_with_lifecycle" {
271350
bucket = "bucket-with-lifecycle-${local.app_id}"
272-
cdc_id = "cluster-262n63e8"
273351
acl = "private"
274352
275353
lifecycle_rules {

tencentcloud/services/cos/resource_tc_cos_bucket_policy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func ResourceTencentCloudCosBucketPolicy() *schema.Resource {
5252
flag := reflect.DeepEqual(oldJson, newJson)
5353
return flag
5454
},
55-
Description: "The text of the policy. For more info please refer to [Tencent official doc](https://intl.cloud.tencent.com/document/product/436/18023).",
55+
Description: "The text of the policy. For more info please refer to [Tencent official doc](https://intl.cloud.tencent.com/document/product/436/18023), The six-segment resource scenario example in the document is as follows: Example of specifying a bucket: `qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*`, In the cdc scenario: `qcs::cos:ap-guangzhou:uid/1250000000:cdc_cluster-123456_examplebucket-1250000000/*`; Example of specifying a folder: `qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/folder/*`, In the cdc scenario: `qcs::cos:ap-guangzhou:uid/1250000000:cdc_cluster-123456_examplebucket-1250000000/folder/*`; Specified object example: `qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/folder/exampleobject`, In the cdc scenario: `qcs::cos:ap-guangzhou:uid/1250000000:cdc_cluster-123456_examplebucket-1250000000/folder/exampleobject`.",
5656
},
5757
},
5858
}

tencentcloud/services/cos/resource_tc_cos_object_copy_operation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func ResourceTencentCloudCosObjectCopyOperation() *schema.Resource {
3232
Required: true,
3333
ForceNew: true,
3434
Type: schema.TypeString,
35-
Description: "Object key.",
35+
Description: "Source url. In the CDC scenario, the CDC source url is used.",
3636
},
3737
},
3838
}

tencentcloud/services/cos/service_tencentcloud_cos.go

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"log"
1010
"net/http"
11+
"regexp"
1112
"strings"
1213

1314
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
@@ -214,21 +215,72 @@ func (me *CosService) TencentCosPutBucketACLBody(
214215
cdcId string,
215216
) (errRet error) {
216217
logId := tccommon.GetLogId(ctx)
217-
218218
acl := &cos.ACLXml{}
219-
220219
opt := &cos.BucketPutACLOptions{}
221-
if reqBody != "" {
222-
err := xml.Unmarshal([]byte(reqBody), acl)
220+
if cdcId == "" && me.client.CosDomain == "" {
221+
if reqBody != "" {
222+
err := xml.Unmarshal([]byte(reqBody), acl)
223+
if err != nil {
224+
errRet = fmt.Errorf("cos [PutBucketACLBody] XML Unmarshal error: %s, bucket: %s", err.Error(), bucket)
225+
return
226+
}
223227

228+
opt.Body = acl
229+
} else if header != "" {
230+
opt.Header = &cos.ACLHeaderOptions{
231+
XCosACL: header,
232+
}
233+
}
234+
} else {
235+
err := xml.Unmarshal([]byte(reqBody), acl)
224236
if err != nil {
225237
errRet = fmt.Errorf("cos [PutBucketACLBody] XML Unmarshal error: %s, bucket: %s", err.Error(), bucket)
226238
return
227239
}
228-
opt.Body = acl
229-
} else if header != "" {
240+
241+
var (
242+
uin string
243+
fullControl string
244+
read string
245+
write string
246+
readAcp string
247+
writeAcp string
248+
)
249+
250+
for _, v := range acl.AccessControlList {
251+
tmpList := regexp.MustCompile(`\d+`).FindAllString(v.Grantee.ID, 1)
252+
if len(tmpList) > 0 {
253+
uin = tmpList[0]
254+
}
255+
256+
if v.Permission == "FULL_CONTROL" {
257+
fullControl = fmt.Sprintf("id=\"%s\"", uin)
258+
}
259+
260+
if v.Permission == "READ" {
261+
read = fmt.Sprintf("id=\"%s\"", uin)
262+
}
263+
264+
if v.Permission == "WRITE" {
265+
write = fmt.Sprintf("id=\"%s\"", uin)
266+
}
267+
268+
if v.Permission == "READ_ACP" {
269+
readAcp = fmt.Sprintf("id=\"%s\"", uin)
270+
}
271+
272+
if v.Permission == "WRITE_ACP" {
273+
writeAcp = fmt.Sprintf("id=\"%s\"", uin)
274+
}
275+
}
276+
230277
opt.Header = &cos.ACLHeaderOptions{
231-
XCosACL: header,
278+
XCosACL: header,
279+
XCosGrantFullControl: fullControl,
280+
XCosGrantRead: read,
281+
XCosGrantWrite: write,
282+
XCosGrantReadACP: readAcp,
283+
XCosGrantWriteACP: writeAcp,
232284
}
233285
}
234286

website/docs/r/cos_bucket.html.markdown

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ description: |-
1111

1212
Provides a COS resource to create a COS bucket and set its attributes.
1313

14+
~> **NOTE:** The following capabilities do not support cdc scenarios: `multi_az`, `website`, and bucket replication `replica_role`.
15+
1416
## Example Usage
1517

1618
### Private Bucket
@@ -31,6 +33,16 @@ resource "tencentcloud_cos_bucket" "private_bucket" {
3133
### Private Bucket with CDC cluster
3234

3335
```hcl
36+
provider "tencentcloud" {
37+
cos_domain = "https://${local.cdc_id}.cos-cdc.${local.region}.myqcloud.com/"
38+
region = local.region
39+
}
40+
41+
locals {
42+
region = "ap-guangzhou"
43+
cdc_id = "cluster-262n63e8"
44+
}
45+
3446
data "tencentcloud_user_info" "info" {}
3547
3648
locals {
@@ -39,7 +51,6 @@ locals {
3951
4052
resource "tencentcloud_cos_bucket" "private_bucket" {
4153
bucket = "private-bucket-${local.app_id}"
42-
cdc_id = "cluster-262n63e8"
4354
acl = "private"
4455
versioning_enable = true
4556
force_clean = true
@@ -172,6 +183,55 @@ EOF
172183
}
173184
```
174185

186+
### Using verbose acl with CDC cluster
187+
188+
```hcl
189+
provider "tencentcloud" {
190+
cos_domain = "https://${local.cdc_id}.cos-cdc.${local.region}.myqcloud.com/"
191+
region = local.region
192+
}
193+
194+
locals {
195+
region = "ap-guangzhou"
196+
cdc_id = "cluster-262n63e8"
197+
}
198+
199+
data "tencentcloud_user_info" "info" {}
200+
201+
locals {
202+
app_id = data.tencentcloud_user_info.info.app_id
203+
}
204+
205+
resource "tencentcloud_cos_bucket" "bucket_with_acl" {
206+
bucket = "private-bucket-${local.app_id}"
207+
acl = "private"
208+
acl_body = <<EOF
209+
<AccessControlPolicy>
210+
<Owner>
211+
<ID>qcs::cam::uin/100023201586:uin/100023201586</ID>
212+
<DisplayName>qcs::cam::uin/100023201586:uin/100023201586</DisplayName>
213+
</Owner>
214+
<AccessControlList>
215+
<Grant>
216+
<Grantee type="CanonicalUser">
217+
<ID>qcs::cam::uin/100015006748:uin/100015006748</ID>
218+
<DisplayName>qcs::cam::uin/100015006748:uin/100015006748</DisplayName>
219+
</Grantee>
220+
<Permission>WRITE</Permission>
221+
</Grant>
222+
<Grant>
223+
<Grantee type="CanonicalUser">
224+
<ID>qcs::cam::uin/100023201586:uin/100023201586</ID>
225+
<DisplayName>qcs::cam::uin/100023201586:uin/100023201586</DisplayName>
226+
</Grantee>
227+
<Permission>FULL_CONTROL</Permission>
228+
</Grant>
229+
</AccessControlList>
230+
</AccessControlPolicy>
231+
EOF
232+
}
233+
```
234+
175235
### Static Website
176236

177237
```hcl
@@ -221,6 +281,16 @@ resource "tencentcloud_cos_bucket" "bucket_with_cors" {
221281
### Using CORS with CDC
222282

223283
```hcl
284+
provider "tencentcloud" {
285+
cos_domain = "https://${local.cdc_id}.cos-cdc.${local.region}.myqcloud.com/"
286+
region = local.region
287+
}
288+
289+
locals {
290+
region = "ap-guangzhou"
291+
cdc_id = "cluster-262n63e8"
292+
}
293+
224294
data "tencentcloud_user_info" "info" {}
225295
226296
locals {
@@ -229,7 +299,6 @@ locals {
229299
230300
resource "tencentcloud_cos_bucket" "bucket_with_cors" {
231301
bucket = "bucket-with-cors-${local.app_id}"
232-
cdc_id = "cluster-262n63e8"
233302
234303
cors_rules {
235304
allowed_origins = ["http://*.abc.com"]
@@ -272,6 +341,16 @@ resource "tencentcloud_cos_bucket" "bucket_with_lifecycle" {
272341
### Using object lifecycle with CDC
273342

274343
```hcl
344+
provider "tencentcloud" {
345+
cos_domain = "https://${local.cdc_id}.cos-cdc.${local.region}.myqcloud.com/"
346+
region = local.region
347+
}
348+
349+
locals {
350+
region = "ap-guangzhou"
351+
cdc_id = "cluster-262n63e8"
352+
}
353+
275354
data "tencentcloud_user_info" "info" {}
276355
277356
locals {
@@ -280,7 +359,6 @@ locals {
280359
281360
resource "tencentcloud_cos_bucket" "bucket_with_lifecycle" {
282361
bucket = "bucket-with-lifecycle-${local.app_id}"
283-
cdc_id = "cluster-262n63e8"
284362
acl = "private"
285363
286364
lifecycle_rules {

website/docs/r/cos_bucket_policy.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ EOF
4747
The following arguments are supported:
4848

4949
* `bucket` - (Required, String, ForceNew) The name of a bucket to be created. Bucket format should be [custom name]-[appid], for example `mycos-1258798060`.
50-
* `policy` - (Required, String) The text of the policy. For more info please refer to [Tencent official doc](https://intl.cloud.tencent.com/document/product/436/18023).
50+
* `policy` - (Required, String) The text of the policy. For more info please refer to [Tencent official doc](https://intl.cloud.tencent.com/document/product/436/18023), The six-segment resource scenario example in the document is as follows: Example of specifying a bucket: `qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*`, In the cdc scenario: `qcs::cos:ap-guangzhou:uid/1250000000:cdc_cluster-123456_examplebucket-1250000000/*`; Example of specifying a folder: `qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/folder/*`, In the cdc scenario: `qcs::cos:ap-guangzhou:uid/1250000000:cdc_cluster-123456_examplebucket-1250000000/folder/*`; Specified object example: `qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/folder/exampleobject`, In the cdc scenario: `qcs::cos:ap-guangzhou:uid/1250000000:cdc_cluster-123456_examplebucket-1250000000/folder/exampleobject`.
5151

5252
## Attributes Reference
5353

0 commit comments

Comments
 (0)