Skip to content

feat(cos): [118298226] support cos_domain, thus support cdc #2841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions tencentcloud/connectivity/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ type TencentCloudClient struct {
Region string
Protocol string
Domain string
CosDomain string

cosConn *s3.S3
tencentCosConn *cos.Client
Expand Down Expand Up @@ -266,8 +267,12 @@ func (me *TencentCloudClient) UseCosClient() *s3.S3 {

resolver := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) {
if service == endpoints.S3ServiceID {
cosUrl := fmt.Sprintf("https://cos.%s.myqcloud.com", region)
if me.CosDomain != "" {
cosUrl = me.CosDomain
}
return endpoints.ResolvedEndpoint{
URL: fmt.Sprintf("https://cos.%s.myqcloud.com", region),
URL: cosUrl,
SigningRegion: region,
}, nil
}
Expand Down Expand Up @@ -317,7 +322,14 @@ func (me *TencentCloudClient) UseTencentCosClientNew(bucket string, cdcId ...str

// UseTencentCosClient tencent cloud own client for service instead of aws
func (me *TencentCloudClient) UseTencentCosClient(bucket string) *cos.Client {
u, _ := url.Parse(fmt.Sprintf("https://%s.cos.%s.myqcloud.com", bucket, me.Region))
cosUrl := fmt.Sprintf("https://%s.cos.%s.myqcloud.com", bucket, me.Region)
if me.CosDomain != "" {
parsedURL, _ := url.Parse(me.CosDomain)
parsedURL.Host = bucket + "." + parsedURL.Host
cosUrl = parsedURL.String()
}

u, _ := url.Parse(cosUrl)

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

// UseCosBatchClient returns ci client for service
func (me *TencentCloudClient) UseCosBatchClient(uin string) *cos.Client {
u, _ := url.Parse(fmt.Sprintf("https://%s.cos-control.%s.myqcloud.com", uin, me.Region))
cosUrl := fmt.Sprintf("https://%s.cos-control.%s.myqcloud.com", uin, me.Region)
if me.CosDomain != "" {
cosUrl = me.CosDomain
}

u, _ := url.Parse(cosUrl)

if me.cosBatchConn != nil && me.cosBatchConn.BaseURL.BatchURL == u {
return me.cosBatchConn
Expand Down
19 changes: 16 additions & 3 deletions tencentcloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ const (
PROVIDER_REGION = "TENCENTCLOUD_REGION"
PROVIDER_PROTOCOL = "TENCENTCLOUD_PROTOCOL"
PROVIDER_DOMAIN = "TENCENTCLOUD_DOMAIN"
PROVIDER_COS_DOMAIN = "TENCENTCLOUD_COS_DOMAIN"
//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.
//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.
PROVIDER_ASSUME_ROLE_ARN = "TENCENTCLOUD_ASSUME_ROLE_ARN"
Expand Down Expand Up @@ -204,6 +205,12 @@ func Provider() *schema.Provider {
DefaultFunc: schema.EnvDefaultFunc(PROVIDER_DOMAIN, nil),
Description: "The root domain of the API request, Default is `tencentcloudapi.com`.",
},
"cos_domain": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc(PROVIDER_COS_DOMAIN, nil),
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`.",
},
//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.
//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.
"assume_role": {
Expand Down Expand Up @@ -2156,6 +2163,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
region string
protocol string
domain string
cosDomain string
camRoleName string
)

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

if v, ok := d.GetOk("cos_domain"); ok {
cosDomain = v.(string)
}

if v, ok := d.GetOk("cam_role_name"); ok {
camRoleName = v.(string)
}
Expand All @@ -2207,9 +2219,10 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
secretKey,
securityToken,
),
Region: region,
Protocol: protocol,
Domain: domain,
Region: region,
Protocol: protocol,
Domain: domain,
CosDomain: cosDomain,
}

// get auth from CAM role name
Expand Down
2 changes: 2 additions & 0 deletions tencentcloud/services/cos/data_source_tc_cos_batchs.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Use this data source to query the COS batch.

~> **NOTE:** The current resource does not support `cos_domain`.

Example Usage

```hcl
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Use this data source to query the COS bucket inventorys.

~> **NOTE:** The current resource does not support cdc.

Example Usage

```hcl
Expand Down
19 changes: 11 additions & 8 deletions tencentcloud/services/cos/data_source_tc_cos_buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,15 +400,18 @@ func dataSourceTencentCloudCosBucketsRead(d *schema.ResourceData, meta interface
}
bucket["website"] = website

originRules, err := cosService.GetBucketPullOrigin(ctx, *v.Name)
if err != nil {
return err
}
bucket["origin_pull_rules"] = originRules
cosDomain := meta.(tccommon.ProviderMeta).GetAPIV3Conn().CosDomain
if cosDomain == "" {
originRules, err := cosService.GetBucketPullOrigin(ctx, *v.Name)
if err != nil {
return err
}
bucket["origin_pull_rules"] = originRules

domainRules, err := cosService.GetBucketOriginDomain(ctx, *v.Name)
if err == nil {
bucket["origin_domain_rules"] = domainRules
domainRules, err := cosService.GetBucketOriginDomain(ctx, *v.Name)
if err == nil {
bucket["origin_domain_rules"] = domainRules
}
}

aclBody, err := cosService.GetBucketACL(ctx, *v.Name, "")
Expand Down
2 changes: 2 additions & 0 deletions tencentcloud/services/cos/resource_tc_cos_batch.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Provides a resource to create a cos bucket batch.

~> **NOTE:** The current resource does not support `cos_domain`.

Example Usage

```hcl
Expand Down
12 changes: 9 additions & 3 deletions tencentcloud/services/cos/resource_tc_cos_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"io/ioutil"
"log"
"net/url"
"strings"
"time"

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

cosDomain := meta.(tccommon.ProviderMeta).GetAPIV3Conn().CosDomain
var cosBucketUrl string
if cdcId == "" {
if cdcId == "" && cosDomain == "" {
cosBucketUrl = fmt.Sprintf("%s.cos.%s.myqcloud.com", d.Id(), meta.(tccommon.ProviderMeta).GetAPIV3Conn().Region)
} else if cosDomain != "" {
parsedURL, _ := url.Parse(cosDomain)
parsedURL.Host = bucket + "." + parsedURL.Host
cosBucketUrl = parsedURL.String()
} else {
cosBucketUrl = fmt.Sprintf("https://%s.%s.cos-cdc.%s.myqcloud.com", bucket, cdcId, meta.(tccommon.ProviderMeta).GetAPIV3Conn().Region)
}
Expand Down Expand Up @@ -656,7 +662,7 @@ func resourceTencentCloudCosBucketRead(d *schema.ResourceData, meta interface{})
return fmt.Errorf("setting cors_rules error: %v", err)
}

if cdcId == "" {
if cdcId == "" && cosDomain == "" {
originPullRules, err := cosService.GetBucketPullOrigin(ctx, bucket)
if err != nil {
return err
Expand Down Expand Up @@ -702,7 +708,7 @@ func resourceTencentCloudCosBucketRead(d *schema.ResourceData, meta interface{})
if err != nil {
return err
}
if len(website) > 0 {
if len(website) > 0 && cosDomain == "" {
// {bucket}.cos-website.{region}.myqcloud.com
endPointUrl := fmt.Sprintf("%s.cos-website.%s.myqcloud.com", d.Id(), meta.(tccommon.ProviderMeta).GetAPIV3Conn().Region)
website[0]["endpoint"] = endPointUrl
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Provides a resource to attach/detach the corresponding certificate for the domain name in specified cos bucket.

~> **NOTE:** The current resource does not support cdc.

Example Usage

```hcl
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Provides a resource to generate a cos bucket inventory immediately

~> **NOTE:** The current resource does not support cdc.

Example Usage

```hcl
Expand Down
2 changes: 2 additions & 0 deletions tencentcloud/services/cos/resource_tc_cos_bucket_inventory.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Provides a resource to create a cos bucket inventory

~> **NOTE:** The current resource does not support cdc.

Example Usage

```hcl
Expand Down
2 changes: 2 additions & 0 deletions tencentcloud/services/cos/resource_tc_cos_bucket_referer.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Provides a resource to create a cos bucket_referer

~> **NOTE:** The current resource does not support cdc.

Example Usage

```hcl
Expand Down
2 changes: 1 addition & 1 deletion tencentcloud/services/cos/resource_tc_cos_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func testSweepCosBuckets(region string) error {
}
log.Printf("[INFO] deleting cos bucket: %s", bucket)

if err = cosService.DeleteBucket(ctx, bucket, true, true); err != nil {
if err = cosService.DeleteBucket(ctx, bucket, true, true, ""); err != nil {
log.Printf("[ERROR] delete bucket %s error: %s", bucket, err.Error())
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Provides a resource to restore object

~> **NOTE:** The current resource does not support cdc.

Example Usage

```hcl
Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/cos_batchs.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ description: |-

Use this data source to query the COS batch.

~> **NOTE:** The current resource does not support `cos_domain`.

## Example Usage

```hcl
Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/cos_bucket_inventorys.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ description: |-

Use this data source to query the COS bucket inventorys.

~> **NOTE:** The current resource does not support cdc.

## Example Usage

```hcl
Expand Down
32 changes: 32 additions & 0 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,38 @@ $ export TENCENTCLOUD_ASSUME_ROLE_WEB_IDENTITY_TOKEN="my-web-identity-token"
$ terraform plan
```

### CDC cos usage

You can set the cos domain by setting the environment variable `TENCENTCLOUD_COS_DOMAIN`, and configure the cdc scenario as follows:

-> **Note:** Please note that not all cos resources are supported. Please pay attention to the prompts for each resource.

```hcl
locals {
region = "ap-guangzhou"
cdc_id = "cluster_xxx"
}

provider "tencentcloud" {
region = local.region
secret_id = "xxxxxx"
secret_key = "xxxxxx"
cos_domain = "https://${local.cdc_id}.cos-cdc.${local.region}.myqcloud.com/"
}
```

The `cos_domain` can also provided via `TENCENTCLOUD_COS_DOMAIN` environment variables.

Usage:

```shell
$ export TENCENTCLOUD_SECRET_ID="my-secret-id"
$ export TENCENTCLOUD_SECRET_KEY="my-secret-key"
$ export TENCENTCLOUD_REGION="ap-guangzhou"
$ export TENCENTCLOUD_COS_DOMAIN="https://cluster-xxxxxx.cos-cdc.ap-guangzhou.myqcloud.com/"
$ terraform plan
```

### Shared credentials

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:
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/cos_batch.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ description: |-

Provides a resource to create a cos bucket batch.

~> **NOTE:** The current resource does not support `cos_domain`.

## Example Usage

```hcl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ description: |-

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

~> **NOTE:** The current resource does not support cdc.

## Example Usage

```hcl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ description: |-

Provides a resource to generate a cos bucket inventory immediately

~> **NOTE:** The current resource does not support cdc.

## Example Usage

```hcl
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/cos_bucket_inventory.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ description: |-

Provides a resource to create a cos bucket inventory

~> **NOTE:** The current resource does not support cdc.

## Example Usage

```hcl
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/cos_bucket_referer.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ description: |-

Provides a resource to create a cos bucket_referer

~> **NOTE:** The current resource does not support cdc.

## Example Usage

```hcl
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/cos_object_restore_operation.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ description: |-

Provides a resource to restore object

~> **NOTE:** The current resource does not support cdc.

## Example Usage

```hcl
Expand Down
Loading