From 43306171c234448c3d84914b41fcff84000e09c0 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Tue, 22 Apr 2025 19:45:08 +0800 Subject: [PATCH 1/2] add --- .../services/cos/resource_tc_cos_bucket.go | 66 ++++++++++--------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/tencentcloud/services/cos/resource_tc_cos_bucket.go b/tencentcloud/services/cos/resource_tc_cos_bucket.go index 3f814ff212..3d92256ae6 100644 --- a/tencentcloud/services/cos/resource_tc_cos_bucket.go +++ b/tencentcloud/services/cos/resource_tc_cos_bucket.go @@ -1489,41 +1489,45 @@ func resourceTencentCloudCosBucketWebsiteUpdate(ctx context.Context, meta interf if v, ok := w["routing_rules"]; ok { websiteRoutingRules := cos.WebsiteRoutingRules{} - for _, item := range v.([]interface{}) { - rules := item.(map[string]interface{}) - if v, ok := rules["rules"]; ok { - wbRules := []cos.WebsiteRoutingRule{} - for _, rule := range v.([]interface{}) { - dMap := rule.(map[string]interface{}) - wbRule := cos.WebsiteRoutingRule{} - if v, ok := dMap["condition_error_code"].(string); ok && v != "" { - wbRule.ConditionErrorCode = v + if len(v.([]interface{})) > 0 { + for _, item := range v.([]interface{}) { + if rules, ok := item.(map[string]interface{}); ok && rules != nil { + if v, ok := rules["rules"]; ok { + wbRules := []cos.WebsiteRoutingRule{} + for _, rule := range v.([]interface{}) { + if dMap, ok := rule.(map[string]interface{}); ok && rules != nil { + wbRule := cos.WebsiteRoutingRule{} + if v, ok := dMap["condition_error_code"].(string); ok && v != "" { + wbRule.ConditionErrorCode = v + } + + if v, ok := dMap["condition_prefix"].(string); ok && v != "" { + wbRule.ConditionPrefix = v + } + + if v, ok := dMap["redirect_protocol"].(string); ok && v != "" { + wbRule.RedirectProtocol = v + } + + if v, ok := dMap["redirect_replace_key"].(string); ok && v != "" { + wbRule.RedirectReplaceKey = v + } + + if v, ok := dMap["redirect_replace_key_prefix"].(string); ok && v != "" { + wbRule.RedirectReplaceKeyPrefix = v + } + + wbRules = append(wbRules, wbRule) + } + } + + websiteRoutingRules.Rules = wbRules } - - if v, ok := dMap["condition_prefix"].(string); ok && v != "" { - wbRule.ConditionPrefix = v - } - - if v, ok := dMap["redirect_protocol"].(string); ok && v != "" { - wbRule.RedirectProtocol = v - } - - if v, ok := dMap["redirect_replace_key"].(string); ok && v != "" { - wbRule.RedirectReplaceKey = v - } - - if v, ok := dMap["redirect_replace_key_prefix"].(string); ok && v != "" { - wbRule.RedirectReplaceKeyPrefix = v - } - - wbRules = append(wbRules, wbRule) } - - websiteRoutingRules.Rules = wbRules } - } - websiteConfiguration.RoutingRules = &websiteRoutingRules + websiteConfiguration.RoutingRules = &websiteRoutingRules + } } request := websiteConfiguration From 199b021731c43c0f016374afee495f8a2d778409 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Tue, 22 Apr 2025 19:47:15 +0800 Subject: [PATCH 2/2] add --- .changelog/3323.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/3323.txt diff --git a/.changelog/3323.txt b/.changelog/3323.txt new file mode 100644 index 0000000000..6864b0a17e --- /dev/null +++ b/.changelog/3323.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_cos_bucket: optimize `website` params +``` \ No newline at end of file