Skip to content

Commit 0393cf4

Browse files
authored
feat(cos): [118298226] support cos_domain, thus support cdc (#2841)
* fix: support cos cdc * fix: 过滤不支持cdc接口 * fix: 过滤不支持cdc接口 * fix: 过滤不支持cdc接口 * fix: 过滤不支持cdc接口 * fix: 过滤不支持cdc接口 * fix: Added cdc cos example * fix: optimize cos url * fix: modify cdc cos doc
1 parent 98cfc23 commit 0393cf4

22 files changed

+121
-18
lines changed

tencentcloud/connectivity/client.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ type TencentCloudClient struct {
118118
Region string
119119
Protocol string
120120
Domain string
121+
CosDomain string
121122

122123
cosConn *s3.S3
123124
tencentCosConn *cos.Client
@@ -266,8 +267,12 @@ func (me *TencentCloudClient) UseCosClient() *s3.S3 {
266267

267268
resolver := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) {
268269
if service == endpoints.S3ServiceID {
270+
cosUrl := fmt.Sprintf("https://cos.%s.myqcloud.com", region)
271+
if me.CosDomain != "" {
272+
cosUrl = me.CosDomain
273+
}
269274
return endpoints.ResolvedEndpoint{
270-
URL: fmt.Sprintf("https://cos.%s.myqcloud.com", region),
275+
URL: cosUrl,
271276
SigningRegion: region,
272277
}, nil
273278
}
@@ -317,7 +322,14 @@ func (me *TencentCloudClient) UseTencentCosClientNew(bucket string, cdcId ...str
317322

318323
// UseTencentCosClient tencent cloud own client for service instead of aws
319324
func (me *TencentCloudClient) UseTencentCosClient(bucket string) *cos.Client {
320-
u, _ := url.Parse(fmt.Sprintf("https://%s.cos.%s.myqcloud.com", bucket, me.Region))
325+
cosUrl := fmt.Sprintf("https://%s.cos.%s.myqcloud.com", bucket, me.Region)
326+
if me.CosDomain != "" {
327+
parsedURL, _ := url.Parse(me.CosDomain)
328+
parsedURL.Host = bucket + "." + parsedURL.Host
329+
cosUrl = parsedURL.String()
330+
}
331+
332+
u, _ := url.Parse(cosUrl)
321333

322334
if me.tencentCosConn != nil && me.tencentCosConn.BaseURL.BucketURL == u {
323335
return me.tencentCosConn
@@ -1319,7 +1331,12 @@ func (me *TencentCloudClient) UseDtsClient() *dts.Client {
13191331

13201332
// UseCosBatchClient returns ci client for service
13211333
func (me *TencentCloudClient) UseCosBatchClient(uin string) *cos.Client {
1322-
u, _ := url.Parse(fmt.Sprintf("https://%s.cos-control.%s.myqcloud.com", uin, me.Region))
1334+
cosUrl := fmt.Sprintf("https://%s.cos-control.%s.myqcloud.com", uin, me.Region)
1335+
if me.CosDomain != "" {
1336+
cosUrl = me.CosDomain
1337+
}
1338+
1339+
u, _ := url.Parse(cosUrl)
13231340

13241341
if me.cosBatchConn != nil && me.cosBatchConn.BaseURL.BatchURL == u {
13251342
return me.cosBatchConn

tencentcloud/provider.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ const (
125125
PROVIDER_REGION = "TENCENTCLOUD_REGION"
126126
PROVIDER_PROTOCOL = "TENCENTCLOUD_PROTOCOL"
127127
PROVIDER_DOMAIN = "TENCENTCLOUD_DOMAIN"
128+
PROVIDER_COS_DOMAIN = "TENCENTCLOUD_COS_DOMAIN"
128129
//internal version: replace envYunti begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
129130
//internal version: replace envYunti end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
130131
PROVIDER_ASSUME_ROLE_ARN = "TENCENTCLOUD_ASSUME_ROLE_ARN"
@@ -204,6 +205,12 @@ func Provider() *schema.Provider {
204205
DefaultFunc: schema.EnvDefaultFunc(PROVIDER_DOMAIN, nil),
205206
Description: "The root domain of the API request, Default is `tencentcloudapi.com`.",
206207
},
208+
"cos_domain": {
209+
Type: schema.TypeString,
210+
Optional: true,
211+
DefaultFunc: schema.EnvDefaultFunc(PROVIDER_COS_DOMAIN, nil),
212+
Description: "The cos domain of the API request, Default is `https://cos.{region}.myqcloud.com`, Other Examples: `https://cluster-123456.cos-cdc.ap-guangzhou.myqcloud.com`.",
213+
},
207214
//internal version: replace enableBpass begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
208215
//internal version: replace enableBpass end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
209216
"assume_role": {
@@ -2156,6 +2163,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
21562163
region string
21572164
protocol string
21582165
domain string
2166+
cosDomain string
21592167
camRoleName string
21602168
)
21612169

@@ -2195,6 +2203,10 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
21952203
domain = v.(string)
21962204
}
21972205

2206+
if v, ok := d.GetOk("cos_domain"); ok {
2207+
cosDomain = v.(string)
2208+
}
2209+
21982210
if v, ok := d.GetOk("cam_role_name"); ok {
21992211
camRoleName = v.(string)
22002212
}
@@ -2207,9 +2219,10 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
22072219
secretKey,
22082220
securityToken,
22092221
),
2210-
Region: region,
2211-
Protocol: protocol,
2212-
Domain: domain,
2222+
Region: region,
2223+
Protocol: protocol,
2224+
Domain: domain,
2225+
CosDomain: cosDomain,
22132226
}
22142227

22152228
// get auth from CAM role name

tencentcloud/services/cos/data_source_tc_cos_batchs.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Use this data source to query the COS batch.
22

3+
~> **NOTE:** The current resource does not support `cos_domain`.
4+
35
Example Usage
46

57
```hcl

tencentcloud/services/cos/data_source_tc_cos_bucket_inventorys.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Use this data source to query the COS bucket inventorys.
22

3+
~> **NOTE:** The current resource does not support cdc.
4+
35
Example Usage
46

57
```hcl

tencentcloud/services/cos/data_source_tc_cos_buckets.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -400,15 +400,18 @@ func dataSourceTencentCloudCosBucketsRead(d *schema.ResourceData, meta interface
400400
}
401401
bucket["website"] = website
402402

403-
originRules, err := cosService.GetBucketPullOrigin(ctx, *v.Name)
404-
if err != nil {
405-
return err
406-
}
407-
bucket["origin_pull_rules"] = originRules
403+
cosDomain := meta.(tccommon.ProviderMeta).GetAPIV3Conn().CosDomain
404+
if cosDomain == "" {
405+
originRules, err := cosService.GetBucketPullOrigin(ctx, *v.Name)
406+
if err != nil {
407+
return err
408+
}
409+
bucket["origin_pull_rules"] = originRules
408410

409-
domainRules, err := cosService.GetBucketOriginDomain(ctx, *v.Name)
410-
if err == nil {
411-
bucket["origin_domain_rules"] = domainRules
411+
domainRules, err := cosService.GetBucketOriginDomain(ctx, *v.Name)
412+
if err == nil {
413+
bucket["origin_domain_rules"] = domainRules
414+
}
412415
}
413416

414417
aclBody, err := cosService.GetBucketACL(ctx, *v.Name, "")

tencentcloud/services/cos/resource_tc_cos_batch.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Provides a resource to create a cos bucket batch.
22

3+
~> **NOTE:** The current resource does not support `cos_domain`.
4+
35
Example Usage
46

57
```hcl

tencentcloud/services/cos/resource_tc_cos_bucket.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"io/ioutil"
1010
"log"
11+
"net/url"
1112
"strings"
1213
"time"
1314

@@ -616,9 +617,14 @@ func resourceTencentCloudCosBucketRead(d *schema.ResourceData, meta interface{})
616617
_ = d.Set("multi_az", true)
617618
}
618619

620+
cosDomain := meta.(tccommon.ProviderMeta).GetAPIV3Conn().CosDomain
619621
var cosBucketUrl string
620-
if cdcId == "" {
622+
if cdcId == "" && cosDomain == "" {
621623
cosBucketUrl = fmt.Sprintf("%s.cos.%s.myqcloud.com", d.Id(), meta.(tccommon.ProviderMeta).GetAPIV3Conn().Region)
624+
} else if cosDomain != "" {
625+
parsedURL, _ := url.Parse(cosDomain)
626+
parsedURL.Host = bucket + "." + parsedURL.Host
627+
cosBucketUrl = parsedURL.String()
622628
} else {
623629
cosBucketUrl = fmt.Sprintf("https://%s.%s.cos-cdc.%s.myqcloud.com", bucket, cdcId, meta.(tccommon.ProviderMeta).GetAPIV3Conn().Region)
624630
}
@@ -656,7 +662,7 @@ func resourceTencentCloudCosBucketRead(d *schema.ResourceData, meta interface{})
656662
return fmt.Errorf("setting cors_rules error: %v", err)
657663
}
658664

659-
if cdcId == "" {
665+
if cdcId == "" && cosDomain == "" {
660666
originPullRules, err := cosService.GetBucketPullOrigin(ctx, bucket)
661667
if err != nil {
662668
return err
@@ -702,7 +708,7 @@ func resourceTencentCloudCosBucketRead(d *schema.ResourceData, meta interface{})
702708
if err != nil {
703709
return err
704710
}
705-
if len(website) > 0 {
711+
if len(website) > 0 && cosDomain == "" {
706712
// {bucket}.cos-website.{region}.myqcloud.com
707713
endPointUrl := fmt.Sprintf("%s.cos-website.%s.myqcloud.com", d.Id(), meta.(tccommon.ProviderMeta).GetAPIV3Conn().Region)
708714
website[0]["endpoint"] = endPointUrl

tencentcloud/services/cos/resource_tc_cos_bucket_domain_certificate_attachment.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Provides a resource to attach/detach the corresponding certificate for the domain name in specified cos bucket.
22

3+
~> **NOTE:** The current resource does not support cdc.
4+
35
Example Usage
46

57
```hcl

tencentcloud/services/cos/resource_tc_cos_bucket_generate_inventory_immediately_operation.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Provides a resource to generate a cos bucket inventory immediately
22

3+
~> **NOTE:** The current resource does not support cdc.
4+
35
Example Usage
46

57
```hcl

tencentcloud/services/cos/resource_tc_cos_bucket_inventory.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Provides a resource to create a cos bucket inventory
22

3+
~> **NOTE:** The current resource does not support cdc.
4+
35
Example Usage
46

57
```hcl

tencentcloud/services/cos/resource_tc_cos_bucket_referer.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Provides a resource to create a cos bucket_referer
22

3+
~> **NOTE:** The current resource does not support cdc.
4+
35
Example Usage
46

57
```hcl

tencentcloud/services/cos/resource_tc_cos_bucket_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func testSweepCosBuckets(region string) error {
7474
}
7575
log.Printf("[INFO] deleting cos bucket: %s", bucket)
7676

77-
if err = cosService.DeleteBucket(ctx, bucket, true, true); err != nil {
77+
if err = cosService.DeleteBucket(ctx, bucket, true, true, ""); err != nil {
7878
log.Printf("[ERROR] delete bucket %s error: %s", bucket, err.Error())
7979
}
8080
}

tencentcloud/services/cos/resource_tc_cos_object_restore_operation.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Provides a resource to restore object
22

3+
~> **NOTE:** The current resource does not support cdc.
4+
35
Example Usage
46

57
```hcl

website/docs/d/cos_batchs.html.markdown

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

1212
Use this data source to query the COS batch.
1313

14+
~> **NOTE:** The current resource does not support `cos_domain`.
15+
1416
## Example Usage
1517

1618
```hcl

website/docs/d/cos_bucket_inventorys.html.markdown

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

1212
Use this data source to query the COS bucket inventorys.
1313

14+
~> **NOTE:** The current resource does not support cdc.
15+
1416
## Example Usage
1517

1618
```hcl

website/docs/index.html.markdown

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,38 @@ $ export TENCENTCLOUD_ASSUME_ROLE_WEB_IDENTITY_TOKEN="my-web-identity-token"
236236
$ terraform plan
237237
```
238238

239+
### CDC cos usage
240+
241+
You can set the cos domain by setting the environment variable `TENCENTCLOUD_COS_DOMAIN`, and configure the cdc scenario as follows:
242+
243+
-> **Note:** Please note that not all cos resources are supported. Please pay attention to the prompts for each resource.
244+
245+
```hcl
246+
locals {
247+
region = "ap-guangzhou"
248+
cdc_id = "cluster_xxx"
249+
}
250+
251+
provider "tencentcloud" {
252+
region = local.region
253+
secret_id = "xxxxxx"
254+
secret_key = "xxxxxx"
255+
cos_domain = "https://${local.cdc_id}.cos-cdc.${local.region}.myqcloud.com/"
256+
}
257+
```
258+
259+
The `cos_domain` can also provided via `TENCENTCLOUD_COS_DOMAIN` environment variables.
260+
261+
Usage:
262+
263+
```shell
264+
$ export TENCENTCLOUD_SECRET_ID="my-secret-id"
265+
$ export TENCENTCLOUD_SECRET_KEY="my-secret-key"
266+
$ export TENCENTCLOUD_REGION="ap-guangzhou"
267+
$ export TENCENTCLOUD_COS_DOMAIN="https://cluster-xxxxxx.cos-cdc.ap-guangzhou.myqcloud.com/"
268+
$ terraform plan
269+
```
270+
239271
### Shared credentials
240272

241273
You can use [Tencent Cloud credentials](https://www.tencentcloud.com/document/product/1013/33464) to specify your credentials. The default location is `$HOME/.tccli` on Linux and macOS, And `"%USERPROFILE%\.tccli"` on Windows. You can optionally specify a different location in the Terraform configuration by providing the `shared_credentials_dir` argument or using the `TENCENTCLOUD_SHARED_CREDENTIALS_DIR` environment variable. This method also supports a `profile` configuration and matching `TENCENTCLOUD_PROFILE` environment variable:

website/docs/r/cos_batch.html.markdown

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

1212
Provides a resource to create a cos bucket batch.
1313

14+
~> **NOTE:** The current resource does not support `cos_domain`.
15+
1416
## Example Usage
1517

1618
```hcl

website/docs/r/cos_bucket_domain_certificate_attachment.html.markdown

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

1212
Provides a resource to attach/detach the corresponding certificate for the domain name in specified cos bucket.
1313

14+
~> **NOTE:** The current resource does not support cdc.
15+
1416
## Example Usage
1517

1618
```hcl

website/docs/r/cos_bucket_generate_inventory_immediately_operation.html.markdown

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

1212
Provides a resource to generate a cos bucket inventory immediately
1313

14+
~> **NOTE:** The current resource does not support cdc.
15+
1416
## Example Usage
1517

1618
```hcl

website/docs/r/cos_bucket_inventory.html.markdown

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

1212
Provides a resource to create a cos bucket inventory
1313

14+
~> **NOTE:** The current resource does not support cdc.
15+
1416
## Example Usage
1517

1618
```hcl

website/docs/r/cos_bucket_referer.html.markdown

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

1212
Provides a resource to create a cos bucket_referer
1313

14+
~> **NOTE:** The current resource does not support cdc.
15+
1416
## Example Usage
1517

1618
```hcl

website/docs/r/cos_object_restore_operation.html.markdown

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

1212
Provides a resource to restore object
1313

14+
~> **NOTE:** The current resource does not support cdc.
15+
1416
## Example Usage
1517

1618
```hcl

0 commit comments

Comments
 (0)