Skip to content

Commit 28ac406

Browse files
authored
Merge pull request #661 from tencentcloudstack/feat/cos_enhancement
feature: cos - support aclXML config, multi available zone, origin-pull and origin domain rules
2 parents ab302b1 + 5db5b27 commit 28ac406

File tree

116 files changed

+17710
-233
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+17710
-233
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
## 1.58.5 (September 7, 2021)
2+
3+
ENHANCEMENTS:
4+
5+
* Resource `resource_tc_redis_backup_config.go ` change backup_period to optional
6+
* Resource `resource_tc_scf_function.go` enable public net config and eip config
7+
* Resource `resource_tc_cos_bucket.go` support MAZ, ACL XML body, Origin-Pull rules and origin domain rules
8+
19
## 1.58.4 (Aug 24, 2021)
210

311
ENHANCEMENTS:
12+
413
* Resource `resource_tc_kubernetes_node_pool.go` support `backup_instance_type` for `auto_scaling_config`
514

615
## 1.58.3 (Aug 18, 2021)
@@ -27,7 +36,7 @@ ENHANCEMENTS:
2736

2837
* Resource `resource_tc_mysql_instance.go` add cpu params for mysql
2938

30-
BUG_FIXES:
39+
BUG FIXES:
3140

3241
* Resource `resource_tc_instance.go` fix read cvm data_disks bug
3342

examples/tencentcloud-cos/main.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,9 @@ data "tencentcloud_cos_buckets" "data_bucket" {
5858
resource "tencentcloud_cos_bucket_policy" "cos_policy" {
5959
bucket = "mycos-1258798060"
6060
policy = var.policy
61+
}
62+
63+
resource "tencentcloud_cos_buckets" "verbose_acl_bucket" {
64+
bucket_prefix = "mycos-1258798060"
65+
acl_body = var.acl_body
6166
}

examples/tencentcloud-cos/variables.tf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,34 @@ variable "policy" {
3737
]
3838
}
3939
EOF
40+
}
41+
42+
variable "acl_body" {
43+
default = <<EOF
44+
<AccessControlPolicy>
45+
<Owner>
46+
<ID>qcs::cam::uin/100000000001:uin/100000000001</ID>
47+
</Owner>
48+
<AccessControlList>
49+
<Grant>
50+
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Group">
51+
<URI>http://cam.qcloud.com/groups/global/AllUsers</URI>
52+
</Grantee>
53+
<Permission>READ</Permission>
54+
</Grant>
55+
<Grant>
56+
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
57+
<ID>qcs::cam::uin/100000000001:uin/100000000001</ID>
58+
</Grantee>
59+
<Permission>WRITE</Permission>
60+
</Grant>
61+
<Grant>
62+
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
63+
<ID>qcs::cam::uin/100000000001:uin/100000000001</ID>
64+
</Grantee>
65+
<Permission>READ_ACP</Permission>
66+
</Grant>
67+
</AccessControlList>
68+
</AccessControlPolicy>
69+
EOF
4070
}

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ require (
99
github.com/client9/misspell v0.3.4
1010
github.com/fatih/color v1.9.0
1111
github.com/golangci/golangci-lint v1.27.0
12+
github.com/google/go-querystring v1.1.0 // indirect
1213
github.com/hashicorp/hcl/v2 v2.6.0
1314
github.com/hashicorp/terraform-plugin-sdk v1.14.0
1415
github.com/katbyte/terrafmt v0.2.0
1516
github.com/mattn/go-colorable v0.1.6 // indirect
1617
github.com/mitchellh/go-homedir v1.1.0
18+
github.com/mozillazg/go-httpheader v0.3.0 // indirect
1719
github.com/pkg/errors v0.9.1
1820
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway v1.0.199
1921
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.199
@@ -49,6 +51,7 @@ require (
4951
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod v1.0.199
5052
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.199
5153
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wss v1.0.199
54+
github.com/tencentyun/cos-go-sdk-v5 v0.7.31-0.20210902132439-360bc9b1be6b
5255
github.com/yangwenmai/ratelimit v0.0.0-20180104140304-44221c2292e1
5356
github.com/zclconf/go-cty v1.4.2 // indirect
5457
golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect

go.sum

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ github.com/Djarvur/go-err113 v0.0.0-20200410182137-af658d038157/go.mod h1:4UJr5H
1515
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
1616
github.com/OpenPeeDeeP/depguard v1.0.1 h1:VlW4R6jmBIv3/u1JNlawEvJMM4J+dPORPaZasQee8Us=
1717
github.com/OpenPeeDeeP/depguard v1.0.1/go.mod h1:xsIw86fROiiwelg+jB2uM9PiKihMMmUx/1V+TNhjQvM=
18+
github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mod h1:1pk82RBxDY/JZnPQrtqHlUFfCctgdorsd9M06fMynOM=
1819
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
1920
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
2021
github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
@@ -174,6 +175,11 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a
174175
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
175176
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
176177
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
178+
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
179+
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
180+
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
181+
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
182+
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
177183
github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no=
178184
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
179185
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
@@ -339,6 +345,9 @@ github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx
339345
github.com/mitchellh/reflectwalk v1.0.1 h1:FVzMWA5RllMAKIdUSC8mdWo3XtwoecrH79BY70sEEpE=
340346
github.com/mitchellh/reflectwalk v1.0.1/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
341347
github.com/mozilla/tls-observatory v0.0.0-20200317151703-4fa42e1c2dee/go.mod h1:SrKMQvPiws7F7iqYp8/TX+IhxCYhzr6N/1yb8cwHsGk=
348+
github.com/mozillazg/go-httpheader v0.2.1/go.mod h1:jJ8xECTlalr6ValeXYdOF8fFUISeBAdw6E61aqQma60=
349+
github.com/mozillazg/go-httpheader v0.3.0 h1:3brX5z8HTH+0RrNA1362Rc3HsaxyWEKtGY45YrhuINM=
350+
github.com/mozillazg/go-httpheader v0.3.0/go.mod h1:PuT8h0pw6efvp8ZeUec1Rs7dwjK08bt6gKSReGMqtdA=
342351
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
343352
github.com/nakabonne/nestif v0.3.0 h1:+yOViDGhg8ygGrmII72nV9B/zGxY188TYpfolntsaPw=
344353
github.com/nakabonne/nestif v0.3.0/go.mod h1:dI314BppzXjJ4HsCnbo7XzrJHPszZsjnk5wEBSYHI2c=
@@ -458,6 +467,7 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.199 h1:G69HwV7
458467
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.199/go.mod h1:zgARzAnsLzpLhdpAHrHTUilOXytH9aEJy5ssCdizVV0=
459468
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.199 h1:o41qFAFJGPDTLNWXs7nLw4fsDxFUCe5gkO2YXI9Ye6Q=
460469
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.199/go.mod h1:b7dNjabPys0/iLwRFd8MVE5EkJTNAh4qtaHQOOLchx4=
470+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.194/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
461471
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.199 h1:TeLKOemumLTjWpkRKNVNhpb7VMDlOPaVEuukrWmab30=
462472
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.199/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
463473
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.234 h1:yAtw4jVBsQZ/KcM2nMHRzcpIfSXRw0Alt7wVTR9OodM=
@@ -474,6 +484,7 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/es v1.0.199 h1:qMFzKYXp
474484
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/es v1.0.199/go.mod h1:UegCt4vv9jAlzpgDu31ZJTuRP5T2BTV8w+jZBTsZIzg=
475485
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap v1.0.199 h1:tmjUPp0VBKuzjTqt0IQ5PT6iYt0yLmvM2DUzMFF7SGk=
476486
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap v1.0.199/go.mod h1:tuPVv7O2B2fIpoDsrV/kvC62FO4CE4FihUxZY0JX2ek=
487+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.194/go.mod h1:yrBKWhChnDqNz1xuXdSbWXG56XawEq0G5j1lg4VwBD4=
477488
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.199 h1:rSDQeqvV4khOJUyg6xmMYF26CRd+WtSYvfwP6N72NP0=
478489
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.199/go.mod h1:yrBKWhChnDqNz1xuXdSbWXG56XawEq0G5j1lg4VwBD4=
479490
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mongodb v1.0.199 h1:2jsGprrewRIP3smcTsY5GpEuOuJ+qyV/BN3Py0Ivf1o=
@@ -510,6 +521,10 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.199 h1:UDZ59pv
510521
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.199/go.mod h1:SKgeSsIfPEM6BeoIFiGHsWG9UsEXzkK0SkWx51H/OS8=
511522
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wss v1.0.199 h1:hMBLtiJPnZ9GvA677cTB6ELBR6B68wCR2QY1sNoGQc4=
512523
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wss v1.0.199/go.mod h1:nnY91/H3j/Gu7V/oCA6Zeg8T5D3q36EUdBh4EjmHwqY=
524+
github.com/tencentyun/cos-go-sdk-v5 v0.7.29 h1:uwRBzc70Wgtc5iQQCowqecfRT0OpCXUOZzodZHOOEDs=
525+
github.com/tencentyun/cos-go-sdk-v5 v0.7.29/go.mod h1:4E4+bQ2gBVJcgEC9Cufwylio4mXOct2iu05WjgEBx1o=
526+
github.com/tencentyun/cos-go-sdk-v5 v0.7.31-0.20210902132439-360bc9b1be6b h1:rLl5sAeLt382023Kd3X4TaOEaT2hdgXWwTGyKiy16Zo=
527+
github.com/tencentyun/cos-go-sdk-v5 v0.7.31-0.20210902132439-360bc9b1be6b/go.mod h1:4E4+bQ2gBVJcgEC9Cufwylio4mXOct2iu05WjgEBx1o=
513528
github.com/tetafro/godot v0.3.7 h1:+mecr7RKrUKB5UQ1gwqEMn13sDKTyDR8KNIquB9mm+8=
514529
github.com/tetafro/godot v0.3.7/go.mod h1:/7NLHhv08H1+8DNj0MElpAACw1ajsCuf3TKNQxA5S+0=
515530
github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e h1:RumXZ56IrCj4CL+g1b9OL/oH0QnsF976bC8xQFYUD5Q=

tencentcloud/connectivity/client.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ package connectivity
22

33
import (
44
"fmt"
5+
"github.com/tencentyun/cos-go-sdk-v5"
6+
"net/http"
7+
"net/url"
8+
"time"
59

610
"github.com/aws/aws-sdk-go/aws"
711
"github.com/aws/aws-sdk-go/aws/credentials"
@@ -53,6 +57,7 @@ type TencentCloudClient struct {
5357
Domain string
5458

5559
cosConn *s3.S3
60+
tencentCosConn *cos.Client
5661
mysqlConn *cdb.Client
5762
redisConn *redis.Client
5863
asConn *as.Client
@@ -132,6 +137,28 @@ func (me *TencentCloudClient) UseCosClient() *s3.S3 {
132137
return s3.New(sess)
133138
}
134139

140+
// UseTencentCosClient tencent cloud own client for service instead of aws
141+
func (me *TencentCloudClient) UseTencentCosClient(bucket string) *cos.Client {
142+
if me.tencentCosConn != nil {
143+
return me.tencentCosConn
144+
}
145+
146+
u, _ := url.Parse(fmt.Sprintf("https://%s.cos.%s.myqcloud.com", bucket, me.Region))
147+
baseUrl := &cos.BaseURL{
148+
BucketURL: u,
149+
}
150+
151+
me.tencentCosConn = cos.NewClient(baseUrl, &http.Client{
152+
Timeout: 100 * time.Second,
153+
Transport: &cos.AuthorizationTransport{
154+
SecretID: me.Credential.SecretId,
155+
SecretKey: me.Credential.SecretKey,
156+
},
157+
})
158+
159+
return me.tencentCosConn
160+
}
161+
135162
// UseMysqlClient returns mysql(cdb) client for service
136163
func (me *TencentCloudClient) UseMysqlClient() *cdb.Client {
137164
if me.mysqlConn != nil {

tencentcloud/data_source_tc_cos_buckets.go

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,114 @@ func dataSourceTencentCloudCosBuckets() *schema.Resource {
168168
},
169169
},
170170
},
171+
"origin_pull_rules": {
172+
Type: schema.TypeList,
173+
Computed: true,
174+
Description: "Bucket Origin-Pull rules.",
175+
Elem: &schema.Resource{
176+
Schema: map[string]*schema.Schema{
177+
"priority": {
178+
Type: schema.TypeInt,
179+
Required: true,
180+
Description: "Priority of origin-pull rules, do not set the same value for multiple rules.",
181+
},
182+
"sync_back_to_source": {
183+
Type: schema.TypeBool,
184+
Optional: true,
185+
Default: false,
186+
Description: "If `true`, COS will not return 3XX status code when pulling data from an origin server. Currently available zone: ap-beijing, ap-shanghai, ap-singapore, ap-mumbai.",
187+
},
188+
"prefix": {
189+
Type: schema.TypeString,
190+
Optional: true,
191+
Default: "",
192+
Description: "Triggers the origin-pull rule when the requested file name matches this prefix.",
193+
},
194+
"protocol": {
195+
Type: schema.TypeString,
196+
Optional: true,
197+
Default: "",
198+
Description: "the protocol used for COS to access the specified origin server. The available value include `HTTP`, `HTTPS` and `FOLLOW`.",
199+
},
200+
"host": {
201+
Type: schema.TypeString,
202+
Required: true,
203+
Description: "Allows only a domain name or IP address. You can optionally append a port number to the address.",
204+
},
205+
"follow_query_string": {
206+
Type: schema.TypeBool,
207+
Optional: true,
208+
Default: true,
209+
Description: "Specifies whether to pass through COS request query string when accessing the origin server.",
210+
},
211+
"follow_redirection": {
212+
Type: schema.TypeBool,
213+
Optional: true,
214+
Default: true,
215+
Description: "Specifies whether to follow 3XX redirect to another origin server to pull data from.",
216+
},
217+
//"copy_origin_data": {
218+
// Type: schema.TypeBool,
219+
// Optional: true,
220+
// Default: true,
221+
// Description: "",
222+
//},
223+
"follow_http_headers": {
224+
Type: schema.TypeList,
225+
Optional: true,
226+
Description: "Specifies the pass through headers when accessing the origin server.",
227+
Elem: &schema.Schema{Type: schema.TypeString},
228+
},
229+
"custom_http_headers": {
230+
Type: schema.TypeMap,
231+
Optional: true,
232+
Description: "Specifies the custom headers that you can add for COS to access your origin server.",
233+
},
234+
//"redirect_prefix": {
235+
// Type: schema.TypeString,
236+
// Optional: true,
237+
// Description: "Prefix for the file to which a request is redirected when the origin-pull rule is triggered.",
238+
//},
239+
//"redirect_suffix": {
240+
// Type: schema.TypeString,
241+
// Optional: true,
242+
// Description: "Suffix for the file to which a request is redirected when the origin-pull rule is triggered.",
243+
//},
244+
},
245+
},
246+
},
247+
"origin_domain_rules": {
248+
Type: schema.TypeList,
249+
Computed: true,
250+
Description: "Bucket origin domain rules.",
251+
Elem: &schema.Resource{
252+
Schema: map[string]*schema.Schema{
253+
"domain": {
254+
Type: schema.TypeString,
255+
Required: true,
256+
Description: "Specify domain host.",
257+
},
258+
"type": {
259+
Type: schema.TypeString,
260+
Optional: true,
261+
Default: "REST",
262+
Description: "Specify origin domain type, available values: `REST`, `WEBSITE`, `ACCELERATE`, default: `REST`.",
263+
},
264+
"status": {
265+
Type: schema.TypeString,
266+
Optional: true,
267+
Default: "ENABLED",
268+
Description: "Domain status, default: `ENABLED`.",
269+
ValidateFunc: validateAllowedStringValue([]string{"ENABLED", "DISABLED"}),
270+
},
271+
},
272+
},
273+
},
274+
"acl_body": {
275+
Type: schema.TypeString,
276+
Computed: true,
277+
Description: "Bucket acl configurations.",
278+
},
171279
"tags": {
172280
Type: schema.TypeMap,
173281
Computed: true,
@@ -211,22 +319,42 @@ LOOP:
211319
}
212320

213321
bucket["bucket"] = *v.Name
322+
214323
corsRules, err := cosService.GetBucketCors(ctx, *v.Name)
215324
if err != nil {
216325
return err
217326
}
218327
bucket["cors_rules"] = corsRules
328+
219329
lifecycleRules, err := cosService.GetDataSourceBucketLifecycle(ctx, *v.Name)
220330
if err != nil {
221331
return err
222332
}
223333
bucket["lifecycle_rules"] = lifecycleRules
334+
224335
website, err := cosService.GetBucketWebsite(ctx, *v.Name)
225336
if err != nil {
226337
return err
227338
}
228339
bucket["website"] = website
229340

341+
originRules, err := cosService.GetBucketPullOrigin(ctx, *v.Name)
342+
if err != nil {
343+
return err
344+
}
345+
bucket["origin_pull_rules"] = originRules
346+
347+
domainRules, err := cosService.GetBucketOriginDomain(ctx, *v.Name)
348+
if err == nil {
349+
bucket["origin_domain_rules"] = domainRules
350+
}
351+
352+
aclBody, err := cosService.GetBucketACLXML(ctx, *v.Name)
353+
if err != nil {
354+
return err
355+
}
356+
bucket["acl_body"] = aclBody
357+
230358
respTags, err := cosService.GetBucketTags(ctx, *v.Name)
231359
if err != nil {
232360
return err

0 commit comments

Comments
 (0)