Skip to content

Commit 1a5b09d

Browse files
tongyimingmikatong
andauthored
support download cos object && update gaap proxy doc (#1947)
* support download cos object && update gaap proxy doc * add changelog * clean file --------- Co-authored-by: mikatong <mikatong@tencent.com>
1 parent 7e0f746 commit 1a5b09d

8 files changed

+180
-4
lines changed

.changelog/1947.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-resource
2+
tencentcloud_cos_object_download_operation
3+
```

tencentcloud/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ Cloud Object Storage(COS)
363363
tencentcloud_cos_object_copy_operation
364364
tencentcloud_cos_object_restore_operation
365365
tencentcloud_cos_bucket_generate_inventory_immediately_operation
366+
tencentcloud_cos_object_download_operation
366367
367368
Cloud Virtual Machine(CVM)
368369
Data Source
@@ -2635,6 +2636,7 @@ func Provider() *schema.Provider {
26352636
"tencentcloud_cos_object_copy_operation": resourceTencentCloudCosObjectCopyOperation(),
26362637
"tencentcloud_cos_object_restore_operation": resourceTencentCloudCosObjectRestoreOperation(),
26372638
"tencentcloud_cos_bucket_generate_inventory_immediately_operation": resourceTencentCloudCosBucketGenerateInventoryImmediatelyOperation(),
2639+
"tencentcloud_cos_object_download_operation": resourceTencentCloudCosObjectDownloadOperation(),
26382640
"tencentcloud_address_template": resourceTencentCloudAddressTemplate(),
26392641
"tencentcloud_address_template_group": resourceTencentCloudAddressTemplateGroup(),
26402642
"tencentcloud_protocol_template": resourceTencentCloudProtocolTemplate(),
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
Provides a resource to download object
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "tencentcloud_cos_object_download_operation" "object_download" {
8+
bucket = "xxxxxxx"
9+
key = "test.txt"
10+
download_path = "/tmp/test.txt"
11+
}
12+
```
13+
*/
14+
package tencentcloud
15+
16+
import (
17+
"context"
18+
"io"
19+
"log"
20+
"os"
21+
22+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
23+
)
24+
25+
func resourceTencentCloudCosObjectDownloadOperation() *schema.Resource {
26+
return &schema.Resource{
27+
Create: resourceTencentCloudCosObjectDownloadOperationCreate,
28+
Read: resourceTencentCloudCosObjectDownloadOperationRead,
29+
Delete: resourceTencentCloudCosObjectDownloadOperationDelete,
30+
31+
Schema: map[string]*schema.Schema{
32+
"bucket": {
33+
Required: true,
34+
ForceNew: true,
35+
Type: schema.TypeString,
36+
Description: "Bucket.",
37+
},
38+
"key": {
39+
Required: true,
40+
ForceNew: true,
41+
Type: schema.TypeString,
42+
Description: "Object key.",
43+
},
44+
"download_path": {
45+
Required: true,
46+
ForceNew: true,
47+
Type: schema.TypeString,
48+
Description: "Download path.",
49+
},
50+
},
51+
}
52+
}
53+
54+
func resourceTencentCloudCosObjectDownloadOperationCreate(d *schema.ResourceData, meta interface{}) error {
55+
defer logElapsed("resource.tencentcloud_cos_object_download_operation.create")()
56+
defer inconsistentCheck(d, meta)()
57+
58+
logId := getLogId(contextNil)
59+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
60+
bucket := d.Get("bucket").(string)
61+
key := d.Get("key").(string)
62+
downloadPath := d.Get("download_path").(string)
63+
resp, err := meta.(*TencentCloudClient).apiV3Conn.UseTencentCosClient(bucket).Object.Get(ctx, key, nil)
64+
if err != nil {
65+
log.Printf("[CRITAL]%s object download failed, reason:%+v", logId, err)
66+
return err
67+
}
68+
defer resp.Body.Close()
69+
70+
fd, err := os.OpenFile(downloadPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0660)
71+
if err != nil {
72+
return err
73+
}
74+
75+
_, err = io.Copy(fd, resp.Body)
76+
fd.Close()
77+
if err != nil {
78+
return err
79+
}
80+
81+
d.SetId(bucket + FILED_SP + key)
82+
83+
return resourceTencentCloudCosObjectDownloadOperationRead(d, meta)
84+
}
85+
86+
func resourceTencentCloudCosObjectDownloadOperationRead(d *schema.ResourceData, meta interface{}) error {
87+
defer logElapsed("resource.tencentcloud_cos_object_download_operation.read")()
88+
defer inconsistentCheck(d, meta)()
89+
90+
return nil
91+
}
92+
93+
func resourceTencentCloudCosObjectDownloadOperationDelete(d *schema.ResourceData, meta interface{}) error {
94+
defer logElapsed("resource.tencentcloud_cos_object_download_operation.delete")()
95+
defer inconsistentCheck(d, meta)()
96+
97+
return nil
98+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudCosObjectDownloadOperationResource(t *testing.T) {
10+
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() { testAccPreCheck(t) },
13+
Providers: testAccProviders,
14+
Steps: []resource.TestStep{
15+
{
16+
Config: testAccCosObjectDownloadOperation,
17+
Check: resource.ComposeAggregateTestCheckFunc(
18+
resource.TestCheckResourceAttrSet("tencentcloud_cos_object_download_operation.object_download", "id"),
19+
),
20+
},
21+
},
22+
})
23+
}
24+
25+
const testAccCosObjectDownloadOperation = `
26+
resource "tencentcloud_cos_object_download_operation" "object_download" {
27+
bucket = "keep-test-1308919341"
28+
key = "download.txt"
29+
download_path = "./download.txt"
30+
}
31+
`

tencentcloud/resource_tc_gaap_proxy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ func resourceTencentCloudGaapProxy() *schema.Resource {
7979
Type: schema.TypeString,
8080
Required: true,
8181
ForceNew: true,
82-
Description: "Access region of the GAAP proxy. Valid value: `NorthChina`, `EastChina`, `SouthChina`, `SouthwestChina`, `Hongkong`, `SL_TAIWAN`, `SoutheastAsia`, `Korea`, `SL_India`, `SL_Australia`, `Europe`, `SL_UK`, `SL_SouthAmerica`, `NorthAmerica`, `SL_MiddleUSA`, `Canada`, `SL_VIET`, `WestIndia`, `Thailand`, `Virginia`, `Russia`, `Japan` and `SL_Indonesia`.",
82+
Description: "Access region of the GAAP proxy. Valid value: `Hongkong`, `SoutheastAsia`, `Korea`, `Europe`, `NorthAmerica`, `Canada`, `WestIndia`, `Thailand`, `Virginia`, `Japan`, `Taipei`, `SL_AZURE_NorthUAE`, `SL_AZURE_EastAUS`, `SL_AZURE_NorthCentralUSA`, `SL_AZURE_SouthIndia`, `SL_AZURE_SouthBrazil`, `SL_AZURE_NorthZAF`, `SL_AZURE_SoutheastAsia`, `SL_AZURE_CentralFrance`, `SL_AZURE_SouthEngland`, `SL_AZURE_EastUS`, `SL_AZURE_WestUS`, `SL_AZURE_SouthCentralUSA`, `Jakarta`, `Beijing`, `Shanghai`, `Guangzhou`, `Chengdu`, `SL_AZURE_NorwayEast`, `Chongqing`, `Nanjing`, `SaoPaulo`, `SL_AZURE_JapanEast`, `Changsha`, `Xian`, `Wuhan`, `Fuzhou`, `Shenyang`, `Zhengzhou`, `Jinan`, `Hangzhou`, `Shijiazhuang`, `Hefei`.",
8383
},
8484
"realserver_region": {
8585
Type: schema.TypeString,
8686
Required: true,
8787
ForceNew: true,
88-
Description: "Region of the GAAP realserver. Valid value: `NorthChina`, `EastChina`, `SouthChina`, `SouthwestChina`, `Hongkong`, `SL_TAIWAN`, `SoutheastAsia`, `Korea`, `SL_India`, `SL_Australia`, `Europe`, `SL_UK`, `SL_SouthAmerica`, `NorthAmerica`, `SL_MiddleUSA`, `Canada`, `SL_VIET`, `WestIndia`, `Thailand`, `Virginia`, `Russia`, `Japan` and `SL_Indonesia`.",
88+
Description: "Region of the GAAP realserver. Valid value: `Hongkong`, `SoutheastAsia`, `Korea`, `Europe`, `NorthAmerica`, `Canada`, `WestIndia`, `Thailand`, `Virginia`, `Japan`, `Taipei`, `SL_AZURE_NorthUAE`, `SL_AZURE_EastAUS`, `SL_AZURE_NorthCentralUSA`, `SL_AZURE_SouthIndia`, `SL_AZURE_SouthBrazil`, `SL_AZURE_NorthZAF`, `SL_AZURE_SoutheastAsia`, `SL_AZURE_CentralFrance`, `SL_AZURE_SouthEngland`, `SL_AZURE_EastUS`, `SL_AZURE_WestUS`, `SL_AZURE_SouthCentralUSA`, `Jakarta`, `Beijing`, `Shanghai`, `Guangzhou`, `Chengdu`, `SL_AZURE_NorwayEast`, `Chongqing`, `Nanjing`, `SaoPaulo`, `SL_AZURE_JapanEast`.",
8989
},
9090
"enable": {
9191
Type: schema.TypeBool,
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
subcategory: "Cloud Object Storage(COS)"
3+
layout: "tencentcloud"
4+
page_title: "TencentCloud: tencentcloud_cos_object_download_operation"
5+
sidebar_current: "docs-tencentcloud-resource-cos_object_download_operation"
6+
description: |-
7+
Provides a resource to download object
8+
---
9+
10+
# tencentcloud_cos_object_download_operation
11+
12+
Provides a resource to download object
13+
14+
## Example Usage
15+
16+
```hcl
17+
resource "tencentcloud_cos_object_download_operation" "object_download" {
18+
bucket = "xxxxxxx"
19+
key = "test.txt"
20+
download_path = "/tmp/test.txt"
21+
}
22+
```
23+
24+
## Argument Reference
25+
26+
The following arguments are supported:
27+
28+
* `bucket` - (Required, String, ForceNew) Bucket.
29+
* `download_path` - (Required, String, ForceNew) Download path.
30+
* `key` - (Required, String, ForceNew) Object key.
31+
32+
## Attributes Reference
33+
34+
In addition to all arguments above, the following attributes are exported:
35+
36+
* `id` - ID of the resource.
37+
38+
39+

website/docs/r/gaap_proxy.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ resource "tencentcloud_gaap_proxy" "foo" {
3131

3232
The following arguments are supported:
3333

34-
* `access_region` - (Required, String, ForceNew) Access region of the GAAP proxy. Valid value: `NorthChina`, `EastChina`, `SouthChina`, `SouthwestChina`, `Hongkong`, `SL_TAIWAN`, `SoutheastAsia`, `Korea`, `SL_India`, `SL_Australia`, `Europe`, `SL_UK`, `SL_SouthAmerica`, `NorthAmerica`, `SL_MiddleUSA`, `Canada`, `SL_VIET`, `WestIndia`, `Thailand`, `Virginia`, `Russia`, `Japan` and `SL_Indonesia`.
34+
* `access_region` - (Required, String, ForceNew) Access region of the GAAP proxy. Valid value: `Hongkong`, `SoutheastAsia`, `Korea`, `Europe`, `NorthAmerica`, `Canada`, `WestIndia`, `Thailand`, `Virginia`, `Japan`, `Taipei`, `SL_AZURE_NorthUAE`, `SL_AZURE_EastAUS`, `SL_AZURE_NorthCentralUSA`, `SL_AZURE_SouthIndia`, `SL_AZURE_SouthBrazil`, `SL_AZURE_NorthZAF`, `SL_AZURE_SoutheastAsia`, `SL_AZURE_CentralFrance`, `SL_AZURE_SouthEngland`, `SL_AZURE_EastUS`, `SL_AZURE_WestUS`, `SL_AZURE_SouthCentralUSA`, `Jakarta`, `Beijing`, `Shanghai`, `Guangzhou`, `Chengdu`, `SL_AZURE_NorwayEast`, `Chongqing`, `Nanjing`, `SaoPaulo`, `SL_AZURE_JapanEast`, `Changsha`, `Xian`, `Wuhan`, `Fuzhou`, `Shenyang`, `Zhengzhou`, `Jinan`, `Hangzhou`, `Shijiazhuang`, `Hefei`.
3535
* `bandwidth` - (Required, Int) Maximum bandwidth of the GAAP proxy, unit is Mbps. Valid value: `10`, `20`, `50`, `100`, `200`, `500`, `1000`, `2000`, `5000` and `10000`. To set `2000`, `5000` or `10000`, you need to apply for a whitelist from Tencent Cloud.
3636
* `concurrent` - (Required, Int) Maximum concurrency of the GAAP proxy, unit is 10k. Valid value: `2`, `5`, `10`, `20`, `30`, `40`, `50`, `60`, `70`, `80`, `90`, `100`, `150`, `200`, `250` and `300`. To set `150`, `200`, `250` or `300`, you need to apply for a whitelist from Tencent Cloud.
3737
* `name` - (Required, String) Name of the GAAP proxy, the maximum length is 30.
38-
* `realserver_region` - (Required, String, ForceNew) Region of the GAAP realserver. Valid value: `NorthChina`, `EastChina`, `SouthChina`, `SouthwestChina`, `Hongkong`, `SL_TAIWAN`, `SoutheastAsia`, `Korea`, `SL_India`, `SL_Australia`, `Europe`, `SL_UK`, `SL_SouthAmerica`, `NorthAmerica`, `SL_MiddleUSA`, `Canada`, `SL_VIET`, `WestIndia`, `Thailand`, `Virginia`, `Russia`, `Japan` and `SL_Indonesia`.
38+
* `realserver_region` - (Required, String, ForceNew) Region of the GAAP realserver. Valid value: `Hongkong`, `SoutheastAsia`, `Korea`, `Europe`, `NorthAmerica`, `Canada`, `WestIndia`, `Thailand`, `Virginia`, `Japan`, `Taipei`, `SL_AZURE_NorthUAE`, `SL_AZURE_EastAUS`, `SL_AZURE_NorthCentralUSA`, `SL_AZURE_SouthIndia`, `SL_AZURE_SouthBrazil`, `SL_AZURE_NorthZAF`, `SL_AZURE_SoutheastAsia`, `SL_AZURE_CentralFrance`, `SL_AZURE_SouthEngland`, `SL_AZURE_EastUS`, `SL_AZURE_WestUS`, `SL_AZURE_SouthCentralUSA`, `Jakarta`, `Beijing`, `Shanghai`, `Guangzhou`, `Chengdu`, `SL_AZURE_NorwayEast`, `Chongqing`, `Nanjing`, `SaoPaulo`, `SL_AZURE_JapanEast`.
3939
* `enable` - (Optional, Bool) Indicates whether GAAP proxy is enabled, default value is `true`.
4040
* `network_type` - (Optional, String, ForceNew) Network type. `normal`: regular BGP, `cn2`: boutique BGP, `triple`: triple play.
4141
* `project_id` - (Optional, Int) ID of the project within the GAAP proxy, `0` means is default project.

website/tencentcloud.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,9 @@
11701170
<li>
11711171
<a href="/docs/providers/tencentcloud/r/cos_object_copy_operation.html">tencentcloud_cos_object_copy_operation</a>
11721172
</li>
1173+
<li>
1174+
<a href="/docs/providers/tencentcloud/r/cos_object_download_operation.html">tencentcloud_cos_object_download_operation</a>
1175+
</li>
11731176
<li>
11741177
<a href="/docs/providers/tencentcloud/r/cos_object_restore_operation.html">tencentcloud_cos_object_restore_operation</a>
11751178
</li>

0 commit comments

Comments
 (0)