Skip to content

fix(cos): [124198801] tencentcloud_cos_bucket update origin_pull_rules add new params #3378

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

Merged
merged 3 commits into from
May 29, 2025
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/3378.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_cos_bucket: update `origin_pull_rules` add new params
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.1163
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wedata v1.0.792
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wss v1.0.199
github.com/tencentyun/cos-go-sdk-v5 v0.7.64
github.com/tencentyun/cos-go-sdk-v5 v0.7.66
github.com/yangwenmai/ratelimit v0.0.0-20180104140304-44221c2292e1
gopkg.in/yaml.v2 v2.4.0
)
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,10 @@ github.com/tencentyun/cos-go-sdk-v5 v0.7.64-0.20250324024831-9ab072216e10 h1:0YE
github.com/tencentyun/cos-go-sdk-v5 v0.7.64-0.20250324024831-9ab072216e10/go.mod h1:8+hG+mQMuRP/OIS9d83syAvXvrMj9HhkND6Q1fLghw0=
github.com/tencentyun/cos-go-sdk-v5 v0.7.64 h1:2ADzzr+hcWl4Fw44DwXe0btlVzAYkdvHQ4glUyR0+mM=
github.com/tencentyun/cos-go-sdk-v5 v0.7.64/go.mod h1:8+hG+mQMuRP/OIS9d83syAvXvrMj9HhkND6Q1fLghw0=
github.com/tencentyun/cos-go-sdk-v5 v0.7.66-0.20250526100824-edd430d7fffb h1:UtCUmXCVOZz1XtgUhizhtzkIcmb2yRbC+IL3f/7MSxs=
github.com/tencentyun/cos-go-sdk-v5 v0.7.66-0.20250526100824-edd430d7fffb/go.mod h1:8+hG+mQMuRP/OIS9d83syAvXvrMj9HhkND6Q1fLghw0=
github.com/tencentyun/cos-go-sdk-v5 v0.7.66 h1:O4O6EsozBoDjxWbltr3iULgkI7WPj/BFNlYTXDuE64E=
github.com/tencentyun/cos-go-sdk-v5 v0.7.66/go.mod h1:8+hG+mQMuRP/OIS9d83syAvXvrMj9HhkND6Q1fLghw0=
github.com/tenntenn/modver v1.0.1 h1:2klLppGhDgzJrScMpkj9Ujy3rXPUspSjAcev9tSEBgA=
github.com/tenntenn/modver v1.0.1/go.mod h1:bePIyQPb7UeioSRkw3Q0XeMhYZSMx9B8ePqg6SAMGH0=
github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3 h1:f+jULpRQGxTSkNYKJ51yaw6ChIqO+Je8UqsTKN/cDag=
Expand Down
45 changes: 37 additions & 8 deletions tencentcloud/services/cos/resource_tc_cos_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,23 @@ func originPullRules() *schema.Resource {
"sync_back_to_source": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Computed: true,
Deprecated: "It has been deprecated from version 1.81.196. Please use `back_to_source_mode` instead.",
Description: "If `true`, COS will not return 3XX status code when pulling data from an origin server. Current available zone: ap-beijing, ap-shanghai, ap-singapore, ap-mumbai.",
},
"back_to_source_mode": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: tccommon.ValidateAllowedStringValue([]string{"Proxy", "Mirror", "Redirect"}),
Description: "Back to source mode. Allow value: Proxy, Mirror, Redirect.",
},
"http_redirect_code": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Redirect code. Effective when `back_to_source_mode` is `Redirect`. ex: 301, 302, 307. Default is 302.",
},
"prefix": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -1659,7 +1673,7 @@ func resourceTencentCloudCosBucketOriginPullUpdate(ctx context.Context, service
HTTPStatusCode: "404",
},
OriginParameter: &cos.BucketOriginParameter{
CopyOriginData: true,
CopyOriginData: helper.Bool(true),
HttpHeader: &cos.BucketOriginHttpHeader{},
},
OriginInfo: &cos.BucketOriginInfo{
Expand All @@ -1670,10 +1684,25 @@ func resourceTencentCloudCosBucketOriginPullUpdate(ctx context.Context, service
}
)

if v := dMap["sync_back_to_source"]; v.(bool) {
item.OriginType = "Mirror"
} else {
item.OriginType = "Proxy"
// has deprecated
if v, ok := dMap["sync_back_to_source"]; ok {
if v.(bool) {
item.OriginType = "Mirror"
} else {
item.OriginType = "Proxy"
}
}

if v, ok := dMap["back_to_source_mode"].(string); ok && v != "" {
item.OriginType = v
}

if v, ok := dMap["http_redirect_code"].(string); ok && v != "" {
if item.OriginType == "Redirect" {
item.OriginParameter.HttpRedirectCode = v
} else {
return fmt.Errorf("Parameter `http_redirect_code` can be set only if `back_to_source_mode` is `Redirect`.")
}
}

if v, ok := dMap["priority"]; ok {
Expand All @@ -1691,10 +1720,10 @@ func resourceTencentCloudCosBucketOriginPullUpdate(ctx context.Context, service
item.OriginInfo.HostInfo = &tmpHost
}
if v, ok := dMap["follow_query_string"]; ok {
item.OriginParameter.FollowQueryString = v.(bool)
item.OriginParameter.FollowQueryString = helper.Bool(v.(bool))
}
if v, ok := dMap["follow_redirection"]; ok {
item.OriginParameter.FollowRedirection = v.(bool)
item.OriginParameter.FollowRedirection = helper.Bool(v.(bool))
}
//if v, ok := dMap["copy_origin_data"]; ok {
// item.OriginParameter.CopyOriginData = v.(bool)
Expand Down
25 changes: 25 additions & 0 deletions tencentcloud/services/cos/resource_tc_cos_bucket.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,31 @@ resource "tencentcloud_cos_bucket" "bucket_with_cors" {
}
```

Using Origin pull

```hcl
data "tencentcloud_user_info" "info" {}

locals {
app_id = data.tencentcloud_user_info.info.app_id
uin = data.tencentcloud_user_info.info.uin
owner_uin = data.tencentcloud_user_info.info.owner_uin
}

resource "tencentcloud_cos_bucket" "example" {
bucket = "tf-bucket-basic10-${local.app_id}"
acl = "public-read"
origin_pull_rules {
priority = 1
back_to_source_mode = "Redirect"
http_redirect_code = "301"
protocol = "FOLLOW"
host = "1.1.1.1"
follow_query_string = true
}
}
```

Using CORS with CDC

```hcl
Expand Down
24 changes: 18 additions & 6 deletions tencentcloud/services/cos/service_tencentcloud_cos.go
Original file line number Diff line number Diff line change
Expand Up @@ -1300,10 +1300,11 @@ func (me *CosService) GetBucketPullOrigin(ctx context.Context, bucket string) (r
return nil, errRet
}

header, _ := json.Marshal(response.Header)
resp, _ := json.Marshal(originConfig)

log.Printf("[DEBUG]%s api[%s] success, request body response body [%s]\n",
logId, "GetBucketPullOrigin", resp)
log.Printf("[DEBUG]%s api[%s] success, request body request header [%s], response body [%s]\n",
logId, "GetBucketPullOrigin", header, resp)

rules := make([]map[string]interface{}, 0)

Expand All @@ -1318,12 +1319,17 @@ func (me *CosService) GetBucketPullOrigin(ctx context.Context, bucket string) (r
item["prefix"] = helper.String(rule.OriginCondition.Prefix)
}

// has deprecated
if rule.OriginType == "Mirror" {
item["sync_back_to_source"] = helper.Bool(true)
} else if rule.OriginType == "Proxy" {
item["sync_back_to_source"] = helper.Bool(false)
}

if rule.OriginType != "" {
item["back_to_source_mode"] = helper.String(rule.OriginType)
}

if rule.OriginParameter != nil {
if rule.OriginParameter.HttpHeader != nil {
if len(rule.OriginParameter.HttpHeader.NewHttpHeaders) != 0 {
Expand All @@ -1345,9 +1351,14 @@ func (me *CosService) GetBucketPullOrigin(ctx context.Context, bucket string) (r
}

}

if rule.OriginParameter.HttpRedirectCode != "" && rule.OriginType == "Redirect" {
item["http_redirect_code"] = helper.String(rule.OriginParameter.HttpRedirectCode)
}

item["protocol"] = helper.String(rule.OriginParameter.Protocol)
item["follow_redirection"] = helper.Bool(rule.OriginParameter.FollowRedirection)
item["follow_query_string"] = helper.Bool(rule.OriginParameter.FollowQueryString)
item["follow_redirection"] = rule.OriginParameter.FollowRedirection
item["follow_query_string"] = rule.OriginParameter.FollowQueryString
}

if rule.OriginInfo.HostInfo != nil {
Expand All @@ -1374,6 +1385,7 @@ func (me *CosService) PutBucketPullOrigin(ctx context.Context, bucket string, ru
ratelimit.Check("PutBucketPullOrigin")
response, err := me.client.UseTencentCosClientNew(bucket, cdcId).Bucket.PutOrigin(ctx, opt)

header, _ := json.Marshal(response.Header)
req, _ := json.Marshal(opt)
resp, _ := json.Marshal(response.Response.Body)

Expand All @@ -1389,8 +1401,8 @@ func (me *CosService) PutBucketPullOrigin(ctx context.Context, bucket string, ru
return
}

log.Printf("[DEBUG]%s api[PutBucketPullOrigin] success, request body [%s], response body [%s]\n",
logId, req, resp)
log.Printf("[DEBUG]%s api[PutBucketPullOrigin] success, request header [%s], request body [%s], response body [%s]\n",
logId, header, req, resp)

return nil
}
Expand Down
53 changes: 40 additions & 13 deletions vendor/github.com/tencentyun/cos-go-sdk-v5/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions vendor/github.com/tencentyun/cos-go-sdk-v5/bucket_origin.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 21 additions & 4 deletions vendor/github.com/tencentyun/cos-go-sdk-v5/bucket_replication.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading