diff --git a/.changelog/2897.txt b/.changelog/2897.txt new file mode 100644 index 0000000000..6f373f1177 --- /dev/null +++ b/.changelog/2897.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_cos_bucket: `website` add new `redirect_all_requests_to` params +``` \ No newline at end of file diff --git a/tencentcloud/services/cos/resource_tc_cos_bucket.go b/tencentcloud/services/cos/resource_tc_cos_bucket.go index cbb63f2cc8..1b6764c133 100644 --- a/tencentcloud/services/cos/resource_tc_cos_bucket.go +++ b/tencentcloud/services/cos/resource_tc_cos_bucket.go @@ -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, @@ -1406,6 +1413,10 @@ 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{}) @@ -1413,12 +1424,17 @@ func resourceTencentCloudCosBucketWebsiteUpdate(ctx context.Context, meta interf 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{ @@ -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) diff --git a/tencentcloud/services/cos/resource_tc_cos_bucket.md b/tencentcloud/services/cos/resource_tc_cos_bucket.md index dbb1c033f4..f56f4b233d 100644 --- a/tencentcloud/services/cos/resource_tc_cos_bucket.md +++ b/tencentcloud/services/cos/resource_tc_cos_bucket.md @@ -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" } } diff --git a/tencentcloud/services/cos/service_tencentcloud_cos.go b/tencentcloud/services/cos/service_tencentcloud_cos.go index a4bd856d8d..dd8cacc9ec 100644 --- a/tencentcloud/services/cos/service_tencentcloud_cos.go +++ b/tencentcloud/services/cos/service_tencentcloud_cos.go @@ -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) } diff --git a/website/docs/r/cos_bucket.html.markdown b/website/docs/r/cos_bucket.html.markdown index 8a943e2edb..fd8c5fde09 100644 --- a/website/docs/r/cos_bucket.html.markdown +++ b/website/docs/r/cos_bucket.html.markdown @@ -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" } } @@ -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