Skip to content

Commit b7382fb

Browse files
committed
add
1 parent 407637e commit b7382fb

File tree

3 files changed

+217
-13
lines changed

3 files changed

+217
-13
lines changed

tencentcloud/services/cos/resource_tc_cos_bucket.md

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ resource "tencentcloud_cos_bucket" "private_bucket" {
2020
Private Bucket with CDC cluster
2121

2222
```hcl
23+
provider "tencentcloud" {
24+
cos_domain = "https://${local.cdc_id}.cos-cdc.${local.region}.myqcloud.com/"
25+
region = local.region
26+
}
27+
28+
locals {
29+
region = "ap-guangzhou"
30+
cdc_id = "cluster-262n63e8"
31+
}
32+
2333
data "tencentcloud_user_info" "info" {}
2434
2535
locals {
@@ -28,7 +38,6 @@ locals {
2838
2939
resource "tencentcloud_cos_bucket" "private_bucket" {
3040
bucket = "private-bucket-${local.app_id}"
31-
cdc_id = "cluster-262n63e8"
3241
acl = "private"
3342
versioning_enable = true
3443
force_clean = true
@@ -161,6 +170,55 @@ EOF
161170
}
162171
```
163172

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

166224
```hcl
@@ -210,6 +268,16 @@ resource "tencentcloud_cos_bucket" "bucket_with_cors" {
210268
Using CORS with CDC
211269

212270
```hcl
271+
provider "tencentcloud" {
272+
cos_domain = "https://${local.cdc_id}.cos-cdc.${local.region}.myqcloud.com/"
273+
region = local.region
274+
}
275+
276+
locals {
277+
region = "ap-guangzhou"
278+
cdc_id = "cluster-262n63e8"
279+
}
280+
213281
data "tencentcloud_user_info" "info" {}
214282
215283
locals {
@@ -218,7 +286,6 @@ locals {
218286
219287
resource "tencentcloud_cos_bucket" "bucket_with_cors" {
220288
bucket = "bucket-with-cors-${local.app_id}"
221-
cdc_id = "cluster-262n63e8"
222289
223290
cors_rules {
224291
allowed_origins = ["http://*.abc.com"]
@@ -261,6 +328,16 @@ resource "tencentcloud_cos_bucket" "bucket_with_lifecycle" {
261328
Using object lifecycle with CDC
262329

263330
```hcl
331+
provider "tencentcloud" {
332+
cos_domain = "https://${local.cdc_id}.cos-cdc.${local.region}.myqcloud.com/"
333+
region = local.region
334+
}
335+
336+
locals {
337+
region = "ap-guangzhou"
338+
cdc_id = "cluster-262n63e8"
339+
}
340+
264341
data "tencentcloud_user_info" "info" {}
265342
266343
locals {
@@ -269,7 +346,6 @@ locals {
269346
270347
resource "tencentcloud_cos_bucket" "bucket_with_lifecycle" {
271348
bucket = "bucket-with-lifecycle-${local.app_id}"
272-
cdc_id = "cluster-262n63e8"
273349
acl = "private"
274350
275351
lifecycle_rules {

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: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ resource "tencentcloud_cos_bucket" "private_bucket" {
3131
### Private Bucket with CDC cluster
3232

3333
```hcl
34+
provider "tencentcloud" {
35+
cos_domain = "https://${local.cdc_id}.cos-cdc.${local.region}.myqcloud.com/"
36+
region = local.region
37+
}
38+
39+
locals {
40+
region = "ap-guangzhou"
41+
cdc_id = "cluster-262n63e8"
42+
}
43+
3444
data "tencentcloud_user_info" "info" {}
3545
3646
locals {
@@ -39,7 +49,6 @@ locals {
3949
4050
resource "tencentcloud_cos_bucket" "private_bucket" {
4151
bucket = "private-bucket-${local.app_id}"
42-
cdc_id = "cluster-262n63e8"
4352
acl = "private"
4453
versioning_enable = true
4554
force_clean = true
@@ -172,6 +181,55 @@ EOF
172181
}
173182
```
174183

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

177235
```hcl
@@ -221,6 +279,16 @@ resource "tencentcloud_cos_bucket" "bucket_with_cors" {
221279
### Using CORS with CDC
222280

223281
```hcl
282+
provider "tencentcloud" {
283+
cos_domain = "https://${local.cdc_id}.cos-cdc.${local.region}.myqcloud.com/"
284+
region = local.region
285+
}
286+
287+
locals {
288+
region = "ap-guangzhou"
289+
cdc_id = "cluster-262n63e8"
290+
}
291+
224292
data "tencentcloud_user_info" "info" {}
225293
226294
locals {
@@ -229,7 +297,6 @@ locals {
229297
230298
resource "tencentcloud_cos_bucket" "bucket_with_cors" {
231299
bucket = "bucket-with-cors-${local.app_id}"
232-
cdc_id = "cluster-262n63e8"
233300
234301
cors_rules {
235302
allowed_origins = ["http://*.abc.com"]
@@ -272,6 +339,16 @@ resource "tencentcloud_cos_bucket" "bucket_with_lifecycle" {
272339
### Using object lifecycle with CDC
273340

274341
```hcl
342+
provider "tencentcloud" {
343+
cos_domain = "https://${local.cdc_id}.cos-cdc.${local.region}.myqcloud.com/"
344+
region = local.region
345+
}
346+
347+
locals {
348+
region = "ap-guangzhou"
349+
cdc_id = "cluster-262n63e8"
350+
}
351+
275352
data "tencentcloud_user_info" "info" {}
276353
277354
locals {
@@ -280,7 +357,6 @@ locals {
280357
281358
resource "tencentcloud_cos_bucket" "bucket_with_lifecycle" {
282359
bucket = "bucket-with-lifecycle-${local.app_id}"
283-
cdc_id = "cluster-262n63e8"
284360
acl = "private"
285361
286362
lifecycle_rules {

0 commit comments

Comments
 (0)