From 30e213cf6f45d88b4946656943bc02d2d1ca85b2 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Wed, 22 Oct 2025 14:32:11 +0800 Subject: [PATCH 1/2] add --- tencentcloud/connectivity/client.go | 9 +++++++-- ...esource_tc_cos_object_download_operation.go | 18 +++++++++++++----- ...esource_tc_cos_object_download_operation.md | 12 ++++++++---- ...cos_object_download_operation.html.markdown | 17 +++++++++++++---- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/tencentcloud/connectivity/client.go b/tencentcloud/connectivity/client.go index ac3613f87f..71aeb2fde3 100644 --- a/tencentcloud/connectivity/client.go +++ b/tencentcloud/connectivity/client.go @@ -349,7 +349,7 @@ 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 { +func (me *TencentCloudClient) UseTencentCosClient(bucket string, clientTimeout ...time.Duration) *cos.Client { cosUrl := fmt.Sprintf("https://%s.cos.%s.myqcloud.com", bucket, me.Region) if me.CosDomain != "" { parsedURL, _ := url.Parse(me.CosDomain) @@ -357,6 +357,11 @@ func (me *TencentCloudClient) UseTencentCosClient(bucket string) *cos.Client { cosUrl = parsedURL.String() } + tmpTimeout := 100 * time.Second + if len(clientTimeout) > 0 { + tmpTimeout = clientTimeout[0] + } + u, _ := url.Parse(cosUrl) if me.tencentCosConn != nil && me.tencentCosConn.BaseURL.BucketURL == u { @@ -368,7 +373,7 @@ func (me *TencentCloudClient) UseTencentCosClient(bucket string) *cos.Client { } me.tencentCosConn = cos.NewClient(baseUrl, &http.Client{ - Timeout: 100 * time.Second, + Timeout: tmpTimeout, Transport: &cos.AuthorizationTransport{ SecretID: me.Credential.SecretId, SecretKey: me.Credential.SecretKey, diff --git a/tencentcloud/services/cos/resource_tc_cos_object_download_operation.go b/tencentcloud/services/cos/resource_tc_cos_object_download_operation.go index b079142a69..762a19b286 100644 --- a/tencentcloud/services/cos/resource_tc_cos_object_download_operation.go +++ b/tencentcloud/services/cos/resource_tc_cos_object_download_operation.go @@ -5,6 +5,7 @@ import ( "io" "log" "os" + "time" tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" @@ -16,7 +17,9 @@ func ResourceTencentCloudCosObjectDownloadOperation() *schema.Resource { Create: resourceTencentCloudCosObjectDownloadOperationCreate, Read: resourceTencentCloudCosObjectDownloadOperationRead, Delete: resourceTencentCloudCosObjectDownloadOperationDelete, - + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(3 * time.Minute), + }, Schema: map[string]*schema.Schema{ "bucket": { Required: true, @@ -44,16 +47,22 @@ func resourceTencentCloudCosObjectDownloadOperationCreate(d *schema.ResourceData defer tccommon.LogElapsed("resource.tencentcloud_cos_object_download_operation.create")() defer tccommon.InconsistentCheck(d, meta)() - 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) key := d.Get("key").(string) downloadPath := d.Get("download_path").(string) - resp, err := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseTencentCosClient(bucket).Object.Get(ctx, key, nil) + + timeout := d.Timeout(schema.TimeoutCreate) + resp, err := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseTencentCosClient(bucket, timeout).Object.Get(ctx, key, nil) if err != nil { log.Printf("[CRITAL]%s object download failed, reason:%+v", logId, err) return err } + defer resp.Body.Close() fd, err := os.OpenFile(downloadPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0660) @@ -68,7 +77,6 @@ func resourceTencentCloudCosObjectDownloadOperationCreate(d *schema.ResourceData } d.SetId(bucket + tccommon.FILED_SP + key) - return resourceTencentCloudCosObjectDownloadOperationRead(d, meta) } diff --git a/tencentcloud/services/cos/resource_tc_cos_object_download_operation.md b/tencentcloud/services/cos/resource_tc_cos_object_download_operation.md index 307ec9d9eb..c5b1a9af2e 100644 --- a/tencentcloud/services/cos/resource_tc_cos_object_download_operation.md +++ b/tencentcloud/services/cos/resource_tc_cos_object_download_operation.md @@ -3,9 +3,13 @@ Provides a resource to download object Example Usage ```hcl -resource "tencentcloud_cos_object_download_operation" "object_download" { - bucket = "xxxxxxx" - key = "test.txt" - download_path = "/tmp/test.txt" +resource "tencentcloud_cos_object_download_operation" "example" { + bucket = "private-bucket-1309116523" + key = "demo.txt" + download_path = "/tmp/demo.txt" + + timeouts { + create = "10m" + } } ``` \ No newline at end of file diff --git a/website/docs/r/cos_object_download_operation.html.markdown b/website/docs/r/cos_object_download_operation.html.markdown index d6a360f8fb..69a4bcfaab 100644 --- a/website/docs/r/cos_object_download_operation.html.markdown +++ b/website/docs/r/cos_object_download_operation.html.markdown @@ -14,10 +14,14 @@ Provides a resource to download object ## Example Usage ```hcl -resource "tencentcloud_cos_object_download_operation" "object_download" { - bucket = "xxxxxxx" - key = "test.txt" - download_path = "/tmp/test.txt" +resource "tencentcloud_cos_object_download_operation" "example" { + bucket = "private-bucket-1309116523" + key = "demo.txt" + download_path = "/tmp/demo.txt" + + timeouts { + create = "10m" + } } ``` @@ -36,4 +40,9 @@ In addition to all arguments above, the following attributes are exported: * `id` - ID of the resource. +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts) for certain actions: + +* `create` - (Defaults to `3m`) Used when creating the resource. From 73c297ae8bd6b4bc2afeefce516d9b61aa10a74f Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Wed, 22 Oct 2025 14:34:25 +0800 Subject: [PATCH 2/2] add --- .changelog/3568.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/3568.txt diff --git a/.changelog/3568.txt b/.changelog/3568.txt new file mode 100644 index 0000000000..6a814d2805 --- /dev/null +++ b/.changelog/3568.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_cos_object_download_operation: support custom timeouts +``` \ No newline at end of file