Skip to content

fix(cos): [120150898] tencentcloud_cos_bucket params website add new redirect_all_requests_to #2897

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 2 commits into from
Oct 18, 2024
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/2897.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_cos_bucket: `website` add new `redirect_all_requests_to` params
```
20 changes: 20 additions & 0 deletions tencentcloud/services/cos/resource_tc_cos_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,13 @@ func ResourceTencentCloudCosBucket() *schema.Resource {
Optional: true,
Description: "An absolute path to the document to return in case of a 4XX error.",
},
"redirect_all_requests_to": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: tccommon.ValidateAllowedStringValue([]string{"http", "https"}),
Description: "Redirects all request configurations. Valid values: http, https. Default is `http`.",
},
"endpoint": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -1406,19 +1413,28 @@ func resourceTencentCloudCosBucketWebsiteUpdate(ctx context.Context, meta interf
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
logId, "delete bucket website", request.String(), response.String())
} else {
if cdcId != "" {
return fmt.Errorf("cdc cos not support set website.\n")
}

var w map[string]interface{}
if website[0] != nil {
w = website[0].(map[string]interface{})
} else {
w = make(map[string]interface{})
}
var indexDocument, errorDocument string
var redirectAllRequestsTo = "http"
if v, ok := w["index_document"]; ok {
indexDocument = v.(string)
}
if v, ok := w["error_document"]; ok {
errorDocument = v.(string)
}
if v, ok := w["redirect_all_requests_to"]; ok && v != "" {
redirectAllRequestsTo = v.(string)
}
endPointUrl := fmt.Sprintf("%s.cos-website.%s.myqcloud.com", d.Id(), meta.(tccommon.ProviderMeta).GetAPIV3Conn().Region)
request := s3.PutBucketWebsiteInput{
Bucket: aws.String(bucket),
WebsiteConfiguration: &s3.WebsiteConfiguration{
Expand All @@ -1428,6 +1444,10 @@ func resourceTencentCloudCosBucketWebsiteUpdate(ctx context.Context, meta interf
ErrorDocument: &s3.ErrorDocument{
Key: aws.String(errorDocument),
},
RedirectAllRequestsTo: &s3.RedirectAllRequestsTo{
HostName: aws.String(endPointUrl),
Protocol: aws.String(redirectAllRequestsTo),
},
},
}
response, err := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseCosClientNew(cdcId).PutBucketWebsite(&request)
Expand Down
5 changes: 3 additions & 2 deletions tencentcloud/services/cos/resource_tc_cos_bucket.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,9 @@ resource "tencentcloud_cos_bucket" "bucket_with_static_website" {
bucket = "bucket-with-static-website-${local.app_id}"

website {
index_document = "index.html"
error_document = "error.html"
index_document = "index.html"
error_document = "error.html"
redirect_all_requests_to = "https"
}
}

Expand Down
3 changes: 3 additions & 0 deletions tencentcloud/services/cos/service_tencentcloud_cos.go
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,9 @@ func (me *CosService) GetBucketWebsite(ctx context.Context, bucket string, cdcId
if response.ErrorDocument != nil {
website["error_document"] = *response.ErrorDocument.Key
}
if response.RedirectAllRequestsTo != nil {
website["redirect_all_requests_to"] = *response.RedirectAllRequestsTo.Protocol
}
if len(website) > 0 {
websites = append(websites, website)
}
Expand Down
6 changes: 4 additions & 2 deletions website/docs/r/cos_bucket.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,9 @@ resource "tencentcloud_cos_bucket" "bucket_with_static_website" {
bucket = "bucket-with-static-website-${local.app_id}"

website {
index_document = "index.html"
error_document = "error.html"
index_document = "index.html"
error_document = "error.html"
redirect_all_requests_to = "https"
}
}

Expand Down Expand Up @@ -505,6 +506,7 @@ The `website` object supports the following:

* `error_document` - (Optional, String) An absolute path to the document to return in case of a 4XX error.
* `index_document` - (Optional, String) COS returns this index document when requests are made to the root domain or any of the subfolders.
* `redirect_all_requests_to` - (Optional, String) Redirects all request configurations. Valid values: http, https. Default is `http`.

## Attributes Reference

Expand Down
Loading