Skip to content

Commit 76d015d

Browse files
authored
fix(cos): [120150898] tencentcloud_cos_bucket params website add new redirect_all_requests_to (#2897)
* add * add
1 parent 977bfc8 commit 76d015d

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

.changelog/2897.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_cos_bucket: `website` add new `redirect_all_requests_to` params
3+
```

tencentcloud/services/cos/resource_tc_cos_bucket.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,13 @@ func ResourceTencentCloudCosBucket() *schema.Resource {
477477
Optional: true,
478478
Description: "An absolute path to the document to return in case of a 4XX error.",
479479
},
480+
"redirect_all_requests_to": {
481+
Type: schema.TypeString,
482+
Optional: true,
483+
Computed: true,
484+
ValidateFunc: tccommon.ValidateAllowedStringValue([]string{"http", "https"}),
485+
Description: "Redirects all request configurations. Valid values: http, https. Default is `http`.",
486+
},
480487
"endpoint": {
481488
Type: schema.TypeString,
482489
Computed: true,
@@ -1406,19 +1413,28 @@ func resourceTencentCloudCosBucketWebsiteUpdate(ctx context.Context, meta interf
14061413
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
14071414
logId, "delete bucket website", request.String(), response.String())
14081415
} else {
1416+
if cdcId != "" {
1417+
return fmt.Errorf("cdc cos not support set website.\n")
1418+
}
1419+
14091420
var w map[string]interface{}
14101421
if website[0] != nil {
14111422
w = website[0].(map[string]interface{})
14121423
} else {
14131424
w = make(map[string]interface{})
14141425
}
14151426
var indexDocument, errorDocument string
1427+
var redirectAllRequestsTo = "http"
14161428
if v, ok := w["index_document"]; ok {
14171429
indexDocument = v.(string)
14181430
}
14191431
if v, ok := w["error_document"]; ok {
14201432
errorDocument = v.(string)
14211433
}
1434+
if v, ok := w["redirect_all_requests_to"]; ok && v != "" {
1435+
redirectAllRequestsTo = v.(string)
1436+
}
1437+
endPointUrl := fmt.Sprintf("%s.cos-website.%s.myqcloud.com", d.Id(), meta.(tccommon.ProviderMeta).GetAPIV3Conn().Region)
14221438
request := s3.PutBucketWebsiteInput{
14231439
Bucket: aws.String(bucket),
14241440
WebsiteConfiguration: &s3.WebsiteConfiguration{
@@ -1428,6 +1444,10 @@ func resourceTencentCloudCosBucketWebsiteUpdate(ctx context.Context, meta interf
14281444
ErrorDocument: &s3.ErrorDocument{
14291445
Key: aws.String(errorDocument),
14301446
},
1447+
RedirectAllRequestsTo: &s3.RedirectAllRequestsTo{
1448+
HostName: aws.String(endPointUrl),
1449+
Protocol: aws.String(redirectAllRequestsTo),
1450+
},
14311451
},
14321452
}
14331453
response, err := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseCosClientNew(cdcId).PutBucketWebsite(&request)

tencentcloud/services/cos/resource_tc_cos_bucket.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,9 @@ resource "tencentcloud_cos_bucket" "bucket_with_static_website" {
234234
bucket = "bucket-with-static-website-${local.app_id}"
235235
236236
website {
237-
index_document = "index.html"
238-
error_document = "error.html"
237+
index_document = "index.html"
238+
error_document = "error.html"
239+
redirect_all_requests_to = "https"
239240
}
240241
}
241242

tencentcloud/services/cos/service_tencentcloud_cos.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,9 @@ func (me *CosService) GetBucketWebsite(ctx context.Context, bucket string, cdcId
777777
if response.ErrorDocument != nil {
778778
website["error_document"] = *response.ErrorDocument.Key
779779
}
780+
if response.RedirectAllRequestsTo != nil {
781+
website["redirect_all_requests_to"] = *response.RedirectAllRequestsTo.Protocol
782+
}
780783
if len(website) > 0 {
781784
websites = append(websites, website)
782785
}

website/docs/r/cos_bucket.html.markdown

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,9 @@ resource "tencentcloud_cos_bucket" "bucket_with_static_website" {
245245
bucket = "bucket-with-static-website-${local.app_id}"
246246
247247
website {
248-
index_document = "index.html"
249-
error_document = "error.html"
248+
index_document = "index.html"
249+
error_document = "error.html"
250+
redirect_all_requests_to = "https"
250251
}
251252
}
252253
@@ -505,6 +506,7 @@ The `website` object supports the following:
505506

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

509511
## Attributes Reference
510512

0 commit comments

Comments
 (0)