Skip to content
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
3 changes: 3 additions & 0 deletions .changelog/3568.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_cos_object_download_operation: support custom timeouts
```
9 changes: 7 additions & 2 deletions tencentcloud/connectivity/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,19 @@ 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)
parsedURL.Host = bucket + "." + parsedURL.Host
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 {
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"log"
"os"
"time"

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

Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -68,7 +77,6 @@ func resourceTencentCloudCosObjectDownloadOperationCreate(d *schema.ResourceData
}

d.SetId(bucket + tccommon.FILED_SP + key)

return resourceTencentCloudCosObjectDownloadOperationRead(d, meta)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
```
17 changes: 13 additions & 4 deletions website/docs/r/cos_object_download_operation.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
```

Expand All @@ -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.

Loading