Skip to content

feat(cos): [118298226] support cdc cluster #2771

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

Closed
wants to merge 4 commits into from
Closed
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
25 changes: 18 additions & 7 deletions tencentcloud/connectivity/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,21 @@ func (me *TencentCloudClient) NewClientIntlProfile(timeout int) *intlProfile.Cli
}

// UseCosClient returns cos client for service
func (me *TencentCloudClient) UseCosClient() *s3.S3 {
if me.cosConn != nil {
return me.cosConn
}
func (me *TencentCloudClient) UseCosClient(cdcId string) *s3.S3 {
//if me.cosConn != nil {
// return me.cosConn
//}

resolver := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) {
if service == endpoints.S3ServiceID {
var endpointUrl string
if cdcId == "" {
endpointUrl = fmt.Sprintf("https://cos.%s.myqcloud.com", region)
} else {
endpointUrl = fmt.Sprintf("https://%s.cos-cdc.%s.myqcloud.com", cdcId, region)
}
return endpoints.ResolvedEndpoint{
URL: fmt.Sprintf("https://cos.%s.myqcloud.com", region),
URL: endpointUrl,
SigningRegion: region,
}, nil
}
Expand All @@ -278,8 +284,13 @@ func (me *TencentCloudClient) UseCosClient() *s3.S3 {
}

// 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))
func (me *TencentCloudClient) UseTencentCosClient(bucket string, cdcId string) *cos.Client {
var u *url.URL
if cdcId == "" {
u, _ = url.Parse(fmt.Sprintf("https://%s.cos.%s.myqcloud.com", bucket, me.Region))
} else {
u, _ = url.Parse(fmt.Sprintf("https://%s.%s.cos-cdc.%s.myqcloud.com", bucket, cdcId, me.Region))
}

if me.tencentCosConn != nil && me.tencentCosConn.BaseURL.BucketURL == u {
return me.tencentCosConn
Expand Down
8 changes: 4 additions & 4 deletions tencentcloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1266,10 +1266,6 @@ func Provider() *schema.Provider {
"tencentcloud_mysql_ro_start_replication": cdb.ResourceTencentCloudMysqlRoStartReplication(),
"tencentcloud_mysql_ro_stop_replication": cdb.ResourceTencentCloudMysqlRoStopReplication(),
"tencentcloud_mysql_switch_proxy": cdb.ResourceTencentCloudMysqlSwitchProxy(),
"tencentcloud_cos_bucket": cos.ResourceTencentCloudCosBucket(),
"tencentcloud_cos_bucket_object": cos.ResourceTencentCloudCosBucketObject(),
"tencentcloud_cos_bucket_referer": cos.ResourceTencentCloudCosBucketReferer(),
"tencentcloud_cos_bucket_version": cos.ResourceTencentCloudCosBucketVersion(),
"tencentcloud_cfs_file_system": cfs.ResourceTencentCloudCfsFileSystem(),
"tencentcloud_cfs_access_group": cfs.ResourceTencentCloudCfsAccessGroup(),
"tencentcloud_cfs_access_rule": cfs.ResourceTencentCloudCfsAccessRule(),
Expand Down Expand Up @@ -1591,6 +1587,10 @@ func Provider() *schema.Provider {
"tencentcloud_tdmq_send_rocketmq_message": trocket.ResourceTencentCloudTdmqSendRocketmqMessage(),
"tencentcloud_tdmq_professional_cluster": tpulsar.ResourceTencentCloudTdmqProfessionalCluster(),
"tencentcloud_tdmq_subscription": tpulsar.ResourceTencentCloudTdmqSubscription(),
"tencentcloud_cos_bucket": cos.ResourceTencentCloudCosBucket(),
"tencentcloud_cos_bucket_object": cos.ResourceTencentCloudCosBucketObject(),
"tencentcloud_cos_bucket_referer": cos.ResourceTencentCloudCosBucketReferer(),
"tencentcloud_cos_bucket_version": cos.ResourceTencentCloudCosBucketVersion(),
"tencentcloud_cos_bucket_policy": cos.ResourceTencentCloudCosBucketPolicy(),
"tencentcloud_cos_bucket_domain_certificate_attachment": cos.ResourceTencentCloudCosBucketDomainCertificateAttachment(),
"tencentcloud_cos_bucket_inventory": cos.ResourceTencentCloudCosBucketInventory(),
Expand Down
17 changes: 11 additions & 6 deletions tencentcloud/services/cos/data_source_tc_cos_batchs.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func DataSourceTencentCloudCosBatchs() *schema.Resource {
Optional: true,
Description: "The task status information you need to query. If you do not specify a task status, COS returns the status of all tasks that have been executed, including those that are in progress. If you specify a task status, COS returns the task in the specified state. Optional task states include: Active, Cancelled, Cancelling, Complete, Completing, Failed, Failing, New, Paused, Pausing, Preparing, Ready, Suspended.",
},
// computed
"jobs": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -113,19 +114,20 @@ func DataSourceTencentCloudCosBatchs() *schema.Resource {
func dataSourceTencentCloudCosBatchsRead(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("data_source.tencentcloud_cos_batchs.read")()

logId := tccommon.GetLogId(tccommon.ContextNil)
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
var (
logId = tccommon.GetLogId(tccommon.ContextNil)
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
)

uin := d.Get("uin").(string)
appid := d.Get("appid").(int)
jobs := make([]map[string]interface{}, 0)

opt := &cos.BatchListJobsOptions{}
if v, ok := d.GetOk("job_statuses"); ok {
opt.JobStatuses = v.(string)
}
headers := &cos.BatchRequestHeaders{
XCosAppid: appid,
}

headers := &cos.BatchRequestHeaders{XCosAppid: appid}
ids := make([]string, 0)
for {
req, _ := json.Marshal(opt)
Expand All @@ -135,6 +137,7 @@ func dataSourceTencentCloudCosBatchsRead(d *schema.ResourceData, meta interface{
if err != nil {
return err
}

for _, item := range result.Jobs.Members {
jobItem := make(map[string]interface{})
jobItem["creation_time"] = item.CreationTime
Expand All @@ -149,10 +152,12 @@ func dataSourceTencentCloudCosBatchsRead(d *schema.ResourceData, meta interface{
"number_of_tasks_succeeded": item.ProgressSummary.NumberOfTasksSucceeded,
"total_number_of_tasks": item.ProgressSummary.TotalNumberOfTasks,
}

jobItem["progress_summary"] = []interface{}{progressSummary}
ids = append(ids, item.JobId)
jobs = append(jobs, jobItem)
}

if result.NextToken != "" {
opt.NextToken = result.NextToken
} else {
Expand Down
34 changes: 24 additions & 10 deletions tencentcloud/services/cos/data_source_tc_cos_bucket_inventorys.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
"log"
"strconv"

tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)

Expand All @@ -23,6 +21,12 @@
Required: true,
Description: "Bucket.",
},
"cdc_id": {
Type: schema.TypeString,
Optional: true,
Description: "CDC cluster ID.",
},
// computed
"inventorys": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -78,8 +82,8 @@
},
},
"optional_fields": {
Type: schema.TypeList,
Optional: true,
Type: schema.TypeList,

Check failure on line 85 in tencentcloud/services/cos/data_source_tc_cos_bucket_inventorys.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofmt`-ed with `-s` (gofmt)
Optional: true,
Description: "Analysis items to include in the inventory result .",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -166,14 +170,18 @@
func dataSourceTencentCloudCosBucketInventorysRead(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("data_source.tencentcloud_cos_bucket_inventorys.read")()

logId := tccommon.GetLogId(tccommon.ContextNil)
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
var (
logId = tccommon.GetLogId(tccommon.ContextNil)
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
)

bucket := d.Get("bucket").(string)
cdcId := d.Get("cdc_id").(string)
inventoryConfigurations := make([]map[string]interface{}, 0)
token := ""
ids := make([]string, 0)
for {
result, response, err := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseTencentCosClient(bucket).Bucket.ListInventoryConfigurations(ctx, token)
result, response, err := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseTencentCosClient(bucket, cdcId).Bucket.ListInventoryConfigurations(ctx, token)
responseBody, _ := json.Marshal(response.Body)
log.Printf("[DEBUG]%s api[ListInventoryConfigurations] success, response body [%s]\n", logId, responseBody)
if err != nil {
Expand All @@ -194,20 +202,25 @@
if item.Filter.Period.StartTime != 0 {
periodMap["start_time"] = strconv.FormatInt(item.Filter.Period.StartTime, 10)
}

if item.Filter.Period.EndTime != 0 {
periodMap["end_time"] = strconv.FormatInt(item.Filter.Period.EndTime, 10)
}

filterMap["period"] = []interface{}{periodMap}
}

itemMap["filter"] = []interface{}{filterMap}
}

if item.OptionalFields != nil {
optionalFieldsMap := make(map[string]interface{})
fields := make([]string, 0)
if item.OptionalFields.BucketInventoryFields != nil {
fields = append(fields, item.OptionalFields.BucketInventoryFields...)
optionalFieldsMap["fields"] = fields
}

itemMap["optional_fields"] = []interface{}{optionalFieldsMap}
}

Expand All @@ -225,16 +238,17 @@
destinationMap["format"] = item.Destination.Format
if item.Destination.Encryption != nil && item.Destination.Encryption.SSECOS != "" {
encryptionMap := make(map[string]interface{})

encryptionMap["sse_cos"] = item.Destination.Encryption.SSECOS
destinationMap["encryption"] = []interface{}{encryptionMap}

}

itemMap["destination"] = []interface{}{destinationMap}
}

ids = append(ids, item.ID)
inventoryConfigurations = append(inventoryConfigurations, itemMap)
}

if result.NextContinuationToken != "" {
token = result.NextContinuationToken
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ func DataSourceTencentCloudCosBucketMultipartUploads() *schema.Resource {
Optional: true,
Description: "The returned Object key must be prefixed with Prefix. Note that when using the prefix query, the returned key still contains Prefix.",
},
"cdc_id": {
Type: schema.TypeString,
Optional: true,
Description: "CDC cluster ID.",
},
// computed
"uploads": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -117,27 +123,35 @@ func DataSourceTencentCloudCosBucketMultipartUploads() *schema.Resource {
func dataSourceTencentCloudCosBucketMultipartUploadsRead(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("data_source.tencentcloud_cos_bucket_multipart_uploads.read")()

logId := tccommon.GetLogId(tccommon.ContextNil)
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
var (
logId = tccommon.GetLogId(tccommon.ContextNil)
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
)

bucket := d.Get("bucket").(string)
cdcId := d.Get("cdc_id").(string)
multipartUploads := make([]map[string]interface{}, 0)
opt := &cos.ListMultipartUploadsOptions{}
if v, ok := d.GetOk("delimiter"); ok {
opt.Delimiter = v.(string)
}

if v, ok := d.GetOk("encoding_type"); ok {
opt.EncodingType = v.(string)
}

if v, ok := d.GetOk("prefix"); ok {
opt.Prefix = v.(string)
}

ids := make([]string, 0)
for {
result, response, err := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseTencentCosClient(bucket).Bucket.ListMultipartUploads(ctx, opt)
result, response, err := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseTencentCosClient(bucket, cdcId).Bucket.ListMultipartUploads(ctx, opt)
responseBody, _ := json.Marshal(response.Body)
if err != nil {
return err
}

log.Printf("[DEBUG]%s api[ListMultipartUploads] success, response body [%s]\n", logId, responseBody)
for _, item := range result.Uploads {
itemMap := make(map[string]interface{})
Expand All @@ -150,18 +164,23 @@ func dataSourceTencentCloudCosBucketMultipartUploadsRead(d *schema.ResourceData,
"display_name": item.Owner.DisplayName,
"id": item.Owner.ID,
}

itemMap["owner"] = []map[string]interface{}{owner}
}

if item.Initiator != nil {
initiator := map[string]interface{}{
"display_name": item.Initiator.DisplayName,
"id": item.Initiator.ID,
}

itemMap["initiator"] = []map[string]interface{}{initiator}
}

ids = append(ids, item.UploadID)
multipartUploads = append(multipartUploads, itemMap)
}

if result.IsTruncated {
opt.KeyMarker = result.KeyMarker
opt.UploadIDMarker = result.UploadIDMarker
Expand Down
28 changes: 22 additions & 6 deletions tencentcloud/services/cos/data_source_tc_cos_bucket_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@ func DataSourceTencentCloudCosBucketObject() *schema.Resource {
Required: true,
Description: "The full path to the object inside the bucket.",
},
"cdc_id": {
Type: schema.TypeString,
Optional: true,
Description: "CDC cluster ID.",
},
"result_output_file": {
Type: schema.TypeString,
Optional: true,
Description: "Used to save results.",
},
// computed
"cache_control": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -75,38 +81,47 @@ func DataSourceTencentCloudCosBucketObject() *schema.Resource {
func dataSourceTencentCloudCosBucketObjectsRead(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("data_source.tencentcloud_cos_bucket_object.read")()

logId := tccommon.GetLogId(tccommon.ContextNil)
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
var (
logId = tccommon.GetLogId(tccommon.ContextNil)
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
cosService = CosService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
)

bucket := d.Get("bucket").(string)
key := d.Get("key").(string)
cdcId := d.Get("cdc_id").(string)
outputMap := make(map[string]string)
outputMap["bucket"] = bucket
outputMap["key"] = key
cosService := CosService{
client: meta.(tccommon.ProviderMeta).GetAPIV3Conn(),
}
info, err := cosService.HeadObject(ctx, bucket, key)

info, err := cosService.HeadObject(ctx, bucket, key, cdcId)
if err != nil {
return err
}

ids := []string{bucket, key}
d.SetId(helper.DataResourceIdsHash(ids))
_ = d.Set("cache_control", info.CacheControl)

outputMap["cache_control"] = getStringValue(info.CacheControl)
_ = d.Set("content_disposition", info.ContentDisposition)

outputMap["content_disposition"] = getStringValue(info.ContentDisposition)
_ = d.Set("content_encoding", info.ContentEncoding)

outputMap["content_encoding"] = getStringValue(info.ContentEncoding)
_ = d.Set("content_type", info.ContentType)

outputMap["content_type"] = getStringValue(info.ContentType)
etag := getStringValue(info.ETag)
_ = d.Set("etag", strings.Trim(etag, `"`))

outputMap["etag"] = strings.Trim(etag, `"`)
_ = d.Set("last_modified", info.LastModified.Format(time.RFC1123))

outputMap["last_modified"] = info.LastModified.Format(time.RFC1123)
_ = d.Set("storage_class", s3.StorageClassStandard)

outputMap["storage_class"] = s3.StorageClassStandard
if info.StorageClass != nil {
_ = d.Set("storage_class", info.StorageClass)
Expand All @@ -127,5 +142,6 @@ func getStringValue(p *string) string {
if p == nil {
return ""
}

return *p
}
Loading
Loading