Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3dda2a2

Browse files
committedSep 2, 2024·
add
1 parent 2128bf8 commit 3dda2a2

File tree

6 files changed

+478
-148
lines changed

6 files changed

+478
-148
lines changed
 

‎tencentcloud/connectivity/client.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,14 @@ func (me *TencentCloudClient) NewClientIntlProfile(timeout int) *intlProfile.Cli
253253
return cpf
254254
}
255255

256+
func (me *TencentCloudClient) UseCosClientNew(cdcId ...string) *s3.S3 {
257+
if cdcId[0] == "" {
258+
return me.UseCosClient()
259+
} else {
260+
return me.UseCosCdcClient(cdcId[0])
261+
}
262+
}
263+
256264
// UseCosClient returns cos client for service
257265
func (me *TencentCloudClient) UseCosClient() *s3.S3 {
258266
if me.cosConn != nil {
@@ -279,6 +287,37 @@ func (me *TencentCloudClient) UseCosClient() *s3.S3 {
279287
return s3.New(sess)
280288
}
281289

290+
// UseCosClient returns cos client for service with CDC
291+
func (me *TencentCloudClient) UseCosCdcClient(cdcId string) *s3.S3 {
292+
resolver := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) {
293+
if service == endpoints.S3ServiceID {
294+
endpointUrl := fmt.Sprintf("https://%s.cos-cdc.%s.myqcloud.com", cdcId, region)
295+
return endpoints.ResolvedEndpoint{
296+
URL: endpointUrl,
297+
SigningRegion: region,
298+
}, nil
299+
}
300+
return endpoints.DefaultResolver().EndpointFor(service, region, optFns...)
301+
}
302+
303+
creds := credentials.NewStaticCredentials(me.Credential.SecretId, me.Credential.SecretKey, me.Credential.Token)
304+
sess := session.Must(session.NewSession(&aws.Config{
305+
Credentials: creds,
306+
Region: aws.String(me.Region),
307+
EndpointResolver: endpoints.ResolverFunc(resolver),
308+
}))
309+
310+
return s3.New(sess)
311+
}
312+
313+
func (me *TencentCloudClient) UseTencentCosClientNew(bucket string, cdcId ...string) *cos.Client {
314+
if cdcId[0] == "" {
315+
return me.UseTencentCosClient(bucket)
316+
} else {
317+
return me.UseTencentCosCdcClient(bucket, cdcId[0])
318+
}
319+
}
320+
282321
// UseTencentCosClient tencent cloud own client for service instead of aws
283322
func (me *TencentCloudClient) UseTencentCosClient(bucket string) *cos.Client {
284323
u, _ := url.Parse(fmt.Sprintf("https://%s.cos.%s.myqcloud.com", bucket, me.Region))
@@ -303,6 +342,31 @@ func (me *TencentCloudClient) UseTencentCosClient(bucket string) *cos.Client {
303342
return me.tencentCosConn
304343
}
305344

345+
// UseTencentCosClient tencent cloud own client for service instead of aws with CDC
346+
func (me *TencentCloudClient) UseTencentCosCdcClient(bucket string, cdcId string) *cos.Client {
347+
var u *url.URL
348+
u, _ = url.Parse(fmt.Sprintf("https://%s.%s.cos-cdc.%s.myqcloud.com", bucket, cdcId, me.Region))
349+
350+
if me.tencentCosConn != nil && me.tencentCosConn.BaseURL.BucketURL == u {
351+
return me.tencentCosConn
352+
}
353+
354+
baseUrl := &cos.BaseURL{
355+
BucketURL: u,
356+
}
357+
358+
me.tencentCosConn = cos.NewClient(baseUrl, &http.Client{
359+
Timeout: 100 * time.Second,
360+
Transport: &cos.AuthorizationTransport{
361+
SecretID: me.Credential.SecretId,
362+
SecretKey: me.Credential.SecretKey,
363+
SessionToken: me.Credential.Token,
364+
},
365+
})
366+
367+
return me.tencentCosConn
368+
}
369+
306370
// UseMysqlClient returns mysql(cdb) client for service
307371
func (me *TencentCloudClient) UseMysqlClient(iacExtInfo ...IacExtInfo) *cdb.Client {
308372
var logRoundTripper LogRoundTripper

‎tencentcloud/services/cos/data_source_tc_cos_buckets.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ func dataSourceTencentCloudCosBucketsRead(d *schema.ResourceData, meta interface
362362
continue
363363
}
364364

365-
respTags, err := cosService.GetBucketTags(ctx, *v.Name)
365+
respTags, err := cosService.GetBucketTags(ctx, *v.Name, "")
366366
if err != nil {
367367
return err
368368
}
@@ -382,7 +382,7 @@ func dataSourceTencentCloudCosBucketsRead(d *schema.ResourceData, meta interface
382382

383383
bucket["bucket"] = *v.Name
384384

385-
corsRules, err := cosService.GetBucketCors(ctx, *v.Name)
385+
corsRules, err := cosService.GetBucketCors(ctx, *v.Name, "")
386386
if err != nil {
387387
return err
388388
}
@@ -394,7 +394,7 @@ func dataSourceTencentCloudCosBucketsRead(d *schema.ResourceData, meta interface
394394
}
395395
bucket["lifecycle_rules"] = lifecycleRules
396396

397-
website, err := cosService.GetBucketWebsite(ctx, *v.Name)
397+
website, err := cosService.GetBucketWebsite(ctx, *v.Name, "")
398398
if err != nil {
399399
return err
400400
}
@@ -411,7 +411,7 @@ func dataSourceTencentCloudCosBucketsRead(d *schema.ResourceData, meta interface
411411
bucket["origin_domain_rules"] = domainRules
412412
}
413413

414-
aclBody, err := cosService.GetBucketACL(ctx, *v.Name)
414+
aclBody, err := cosService.GetBucketACL(ctx, *v.Name, "")
415415

416416
if err != nil {
417417
return err

‎tencentcloud/services/cos/resource_tc_cos_bucket.go

Lines changed: 111 additions & 73 deletions
Large diffs are not rendered by default.

‎tencentcloud/services/cos/resource_tc_cos_bucket.md

Lines changed: 121 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,30 @@ locals {
1111
app_id = data.tencentcloud_user_info.info.app_id
1212
}
1313
14-
resource "tencentcloud_cos_bucket" "private_sbucket" {
14+
resource "tencentcloud_cos_bucket" "private_bucket" {
1515
bucket = "private-bucket-${local.app_id}"
1616
acl = "private"
1717
}
1818
```
1919

20+
Private Bucket with CDC cluster
21+
22+
```hcl
23+
data "tencentcloud_user_info" "info" {}
24+
25+
locals {
26+
app_id = data.tencentcloud_user_info.info.app_id
27+
}
28+
29+
resource "tencentcloud_cos_bucket" "private_bucket" {
30+
bucket = "private-bucket-${local.app_id}"
31+
cdc_id = "cluster-262n63e8"
32+
acl = "private"
33+
versioning_enable = true
34+
force_clean = true
35+
}
36+
```
37+
2038
Creation of multiple available zone bucket
2139

2240
```hcl
@@ -27,9 +45,9 @@ locals {
2745
}
2846
2947
resource "tencentcloud_cos_bucket" "multi_zone_bucket" {
30-
bucket = "multi-zone-bucket-${local.app_id}"
31-
acl = "private"
32-
multi_az = true
48+
bucket = "multi-zone-bucket-${local.app_id}"
49+
acl = "private"
50+
multi_az = true
3351
versioning_enable = true
3452
force_clean = true
3553
}
@@ -112,6 +130,46 @@ EOF
112130
}
113131
```
114132

133+
Using verbose acl with CDC
134+
135+
```hcl
136+
data "tencentcloud_user_info" "info" {}
137+
138+
locals {
139+
app_id = data.tencentcloud_user_info.info.app_id
140+
}
141+
142+
resource "tencentcloud_cos_bucket" "bucket_with_acl" {
143+
bucket = "bucketwith-acl-${local.app_id}"
144+
cdc_id = "cluster-262n63e8"
145+
# NOTE: Specify the acl_body by the priority sequence of permission and user type with the following sequence: `CanonicalUser with READ`, `CanonicalUser with WRITE`, `CanonicalUser with FULL_CONTROL`, `CanonicalUser with WRITE_ACP`, `CanonicalUser with READ_ACP`, then specify the `Group` of permissions same as `CanonicalUser`.
146+
acl_body = <<EOF
147+
<AccessControlPolicy
148+
xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
149+
<Owner>
150+
<ID>qcs::cam::uin/100023201586:uin/100023201586</ID>
151+
</Owner>
152+
<AccessControlList>
153+
<Grant>
154+
<Grantee
155+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
156+
<ID>qcs::cam::uin/100023201586:uin/100023201586</ID>
157+
</Grantee>
158+
<Permission>FULL_CONTROL</Permission>
159+
</Grant>
160+
<Grant>
161+
<Grantee
162+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
163+
<ID>100015006748</ID>
164+
</Grantee>
165+
<Permission>READ</Permission>
166+
</Grant>
167+
</AccessControlList>
168+
</AccessControlPolicy>
169+
EOF
170+
}
171+
```
172+
115173
Static Website
116174

117175
```hcl
@@ -158,6 +216,29 @@ resource "tencentcloud_cos_bucket" "bucket_with_cors" {
158216
}
159217
```
160218

219+
Using CORS with CDC
220+
221+
```hcl
222+
data "tencentcloud_user_info" "info" {}
223+
224+
locals {
225+
app_id = data.tencentcloud_user_info.info.app_id
226+
}
227+
228+
resource "tencentcloud_cos_bucket" "bucket_with_cors" {
229+
bucket = "bucket-with-cors-${local.app_id}"
230+
cdc_id = "cluster-262n63e8"
231+
232+
cors_rules {
233+
allowed_origins = ["http://*.abc.com"]
234+
allowed_methods = ["PUT", "POST"]
235+
allowed_headers = ["*"]
236+
max_age_seconds = 300
237+
expose_headers = ["Etag"]
238+
}
239+
}
240+
```
241+
161242
Using object lifecycle
162243

163244
```hcl
@@ -186,32 +267,57 @@ resource "tencentcloud_cos_bucket" "bucket_with_lifecycle" {
186267
}
187268
```
188269

189-
Using replication
270+
Using object lifecycle with CDC
271+
190272
```hcl
191273
data "tencentcloud_user_info" "info" {}
192274
193275
locals {
194276
app_id = data.tencentcloud_user_info.info.app_id
195-
uin = data.tencentcloud_user_info.info.uin
277+
}
278+
279+
resource "tencentcloud_cos_bucket" "bucket_with_lifecycle" {
280+
bucket = "bucket-with-lifecycle-${local.app_id}"
281+
cdc_id = "cluster-262n63e8"
282+
acl = "private"
283+
284+
lifecycle_rules {
285+
filter_prefix = "path1/"
286+
287+
expiration {
288+
days = 90
289+
}
290+
}
291+
}
292+
```
293+
294+
Using replication
295+
296+
```hcl
297+
data "tencentcloud_user_info" "info" {}
298+
299+
locals {
300+
app_id = data.tencentcloud_user_info.info.app_id
301+
uin = data.tencentcloud_user_info.info.uin
196302
owner_uin = data.tencentcloud_user_info.info.owner_uin
197-
region = "ap-guangzhou"
303+
region = "ap-guangzhou"
198304
}
199305
200306
resource "tencentcloud_cos_bucket" "bucket_replicate" {
201-
bucket = "bucket-replicate-${local.app_id}"
202-
acl = "private"
307+
bucket = "bucket-replicate-${local.app_id}"
308+
acl = "private"
203309
versioning_enable = true
204310
}
205311
206312
resource "tencentcloud_cos_bucket" "bucket_with_replication" {
207-
bucket = "bucket-with-replication-${local.app_id}"
208-
acl = "private"
313+
bucket = "bucket-with-replication-${local.app_id}"
314+
acl = "private"
209315
versioning_enable = true
210-
replica_role = "qcs::cam::uin/${local.owner_uin}:uin/${local.uin}"
316+
replica_role = "qcs::cam::uin/${local.owner_uin}:uin/${local.uin}"
211317
replica_rules {
212-
id = "test-rep1"
213-
status = "Enabled"
214-
prefix = "dist"
318+
id = "test-rep1"
319+
status = "Enabled"
320+
prefix = "dist"
215321
destination_bucket = "qcs::cos:${local.region}::${tencentcloud_cos_bucket.bucket_replicate.bucket}"
216322
}
217323
}

‎tencentcloud/services/cos/service_tencentcloud_cos.go

Lines changed: 71 additions & 55 deletions
Large diffs are not rendered by default.

‎website/docs/r/cos_bucket.html.markdown

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,30 @@ locals {
2222
app_id = data.tencentcloud_user_info.info.app_id
2323
}
2424
25-
resource "tencentcloud_cos_bucket" "private_sbucket" {
25+
resource "tencentcloud_cos_bucket" "private_bucket" {
2626
bucket = "private-bucket-${local.app_id}"
2727
acl = "private"
2828
}
2929
```
3030

31+
### Private Bucket with CDC cluster
32+
33+
```hcl
34+
data "tencentcloud_user_info" "info" {}
35+
36+
locals {
37+
app_id = data.tencentcloud_user_info.info.app_id
38+
}
39+
40+
resource "tencentcloud_cos_bucket" "private_bucket" {
41+
bucket = "private-bucket-${local.app_id}"
42+
cdc_id = "cluster-262n63e8"
43+
acl = "private"
44+
versioning_enable = true
45+
force_clean = true
46+
}
47+
```
48+
3149
### Creation of multiple available zone bucket
3250

3351
```hcl
@@ -123,6 +141,46 @@ EOF
123141
}
124142
```
125143

144+
### Using verbose acl with CDC
145+
146+
```hcl
147+
data "tencentcloud_user_info" "info" {}
148+
149+
locals {
150+
app_id = data.tencentcloud_user_info.info.app_id
151+
}
152+
153+
resource "tencentcloud_cos_bucket" "bucket_with_acl" {
154+
bucket = "bucketwith-acl-${local.app_id}"
155+
cdc_id = "cluster-262n63e8"
156+
# NOTE: Specify the acl_body by the priority sequence of permission and user type with the following sequence: `CanonicalUser with READ`, `CanonicalUser with WRITE`, `CanonicalUser with FULL_CONTROL`, `CanonicalUser with WRITE_ACP`, `CanonicalUser with READ_ACP`, then specify the `Group` of permissions same as `CanonicalUser`.
157+
acl_body = <<EOF
158+
<AccessControlPolicy
159+
xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
160+
<Owner>
161+
<ID>qcs::cam::uin/100023201586:uin/100023201586</ID>
162+
</Owner>
163+
<AccessControlList>
164+
<Grant>
165+
<Grantee
166+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
167+
<ID>qcs::cam::uin/100023201586:uin/100023201586</ID>
168+
</Grantee>
169+
<Permission>FULL_CONTROL</Permission>
170+
</Grant>
171+
<Grant>
172+
<Grantee
173+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
174+
<ID>100015006748</ID>
175+
</Grantee>
176+
<Permission>READ</Permission>
177+
</Grant>
178+
</AccessControlList>
179+
</AccessControlPolicy>
180+
EOF
181+
}
182+
```
183+
126184
### Static Website
127185

128186
```hcl
@@ -169,6 +227,29 @@ resource "tencentcloud_cos_bucket" "bucket_with_cors" {
169227
}
170228
```
171229

230+
### Using CORS with CDC
231+
232+
```hcl
233+
data "tencentcloud_user_info" "info" {}
234+
235+
locals {
236+
app_id = data.tencentcloud_user_info.info.app_id
237+
}
238+
239+
resource "tencentcloud_cos_bucket" "bucket_with_cors" {
240+
bucket = "bucket-with-cors-${local.app_id}"
241+
cdc_id = "cluster-262n63e8"
242+
243+
cors_rules {
244+
allowed_origins = ["http://*.abc.com"]
245+
allowed_methods = ["PUT", "POST"]
246+
allowed_headers = ["*"]
247+
max_age_seconds = 300
248+
expose_headers = ["Etag"]
249+
}
250+
}
251+
```
252+
172253
### Using object lifecycle
173254

174255
```hcl
@@ -197,6 +278,30 @@ resource "tencentcloud_cos_bucket" "bucket_with_lifecycle" {
197278
}
198279
```
199280

281+
### Using object lifecycle with CDC
282+
283+
```hcl
284+
data "tencentcloud_user_info" "info" {}
285+
286+
locals {
287+
app_id = data.tencentcloud_user_info.info.app_id
288+
}
289+
290+
resource "tencentcloud_cos_bucket" "bucket_with_lifecycle" {
291+
bucket = "bucket-with-lifecycle-${local.app_id}"
292+
cdc_id = "cluster-262n63e8"
293+
acl = "private"
294+
295+
lifecycle_rules {
296+
filter_prefix = "path1/"
297+
298+
expiration {
299+
days = 90
300+
}
301+
}
302+
}
303+
```
304+
200305
### Using replication
201306

202307
```hcl
@@ -237,6 +342,7 @@ The following arguments are supported:
237342
* `acceleration_enable` - (Optional, Bool) Enable bucket acceleration.
238343
* `acl_body` - (Optional, String) ACL XML body for multiple grant info. NOTE: this argument will overwrite `acl`. Check https://intl.cloud.tencent.com/document/product/436/7737 for more detail.
239344
* `acl` - (Optional, String) The canned ACL to apply. Valid values: private, public-read, and public-read-write. Defaults to private.
345+
* `cdc_id` - (Optional, String, ForceNew) CDC cluster ID.
240346
* `cors_rules` - (Optional, List) A rule of Cross-Origin Resource Sharing (documented below).
241347
* `enable_intelligent_tiering` - (Optional, Bool) Enable intelligent tiering. NOTE: When intelligent tiering configuration is enabled, it cannot be turned off or modified.
242348
* `encryption_algorithm` - (Optional, String) The server-side encryption algorithm to use. Valid value is `AES256`.

0 commit comments

Comments
 (0)
Please sign in to comment.