Skip to content

Commit 9f1cab3

Browse files
committed
add
1 parent fdac6ed commit 9f1cab3

File tree

4 files changed

+662
-191
lines changed

4 files changed

+662
-191
lines changed

tencentcloud/services/teo/resource_tc_teo_web_security_template.go

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,13 @@ func ResourceTencentCloudTeoWebSecurityTemplate() *schema.Resource {
4848
"custom_rules": {
4949
Type: schema.TypeList,
5050
Optional: true,
51-
Computed: true,
5251
MaxItems: 1,
5352
Description: "Custom rules. If the parameter is null or not filled, the configuration last set will be used by default.\nNote: This field may return null, indicating that no valid value can be obtained.",
5453
Elem: &schema.Resource{
5554
Schema: map[string]*schema.Schema{
5655
"rules": {
5756
Type: schema.TypeList,
5857
Optional: true,
59-
Computed: true,
6058
Description: "The custom rule. <br>when modifying the Web protection configuration using ModifySecurityPolicy: <br> - if the Rules parameter is not specified or the parameter length of Rules is zero: clear all custom rule configurations. <br> - if the Rules parameter is not specified: keep the existing custom rule configuration without modification.",
6159
Elem: &schema.Resource{
6260
Schema: map[string]*schema.Schema{
@@ -233,10 +231,12 @@ func ResourceTencentCloudTeoWebSecurityTemplate() *schema.Resource {
233231
"id": {
234232
Type: schema.TypeString,
235233
Optional: true,
234+
Computed: true,
236235
Description: "Custom rule ID. <br>Different rule configuration operations are supported by rule ID: <br> Add a new rule: ID is empty or the ID parameter is not specified; <br> Modify an existing rule: specify the rule ID that needs to be updated/modified; <br> Delete an existing rule: existing rules not included in the Rules parameter will be deleted.",
237236
},
238237
"rule_type": {
239238
Type: schema.TypeString,
239+
Optional: true,
240240
Computed: true,
241241
Description: "Type of custom rule. Values: <li>`BasicAccessRule`: basic access control;</li> <li>`PreciseMatchRule`: exact custom rule, default;</li> <li>`ManagedAccessRule`: expert customized rule, output parameter only.</li>The default value is PreciseMatchRule.",
242242
},
@@ -1652,21 +1652,20 @@ func ResourceTencentCloudTeoWebSecurityTemplate() *schema.Resource {
16521652
"rate_limiting_rules": {
16531653
Type: schema.TypeList,
16541654
Optional: true,
1655-
Computed: true,
16561655
MaxItems: 1,
16571656
Description: "Configures the rate limiting rule.",
16581657
Elem: &schema.Resource{
16591658
Schema: map[string]*schema.Schema{
16601659
"rules": {
16611660
Type: schema.TypeList,
16621661
Optional: true,
1663-
Computed: true,
16641662
Description: "Definition list of precise rate limiting. when using ModifySecurityPolicy to modify the Web protection configuration: <br> <li> if the Rules parameter is not specified or its length is zero: clear all precision rate limiting configurations.</li> <li> if the RateLimitingRules parameter value is unspecified in the SecurityPolicy parameter: retain the existing custom rule configuration without modification.</li>.",
16651663
Elem: &schema.Resource{
16661664
Schema: map[string]*schema.Schema{
16671665
"id": {
16681666
Type: schema.TypeString,
16691667
Optional: true,
1668+
Computed: true,
16701669
Description: "The ID of precise rate limiting. rule ID supports different rule configuration operations: <li><b>add</b> a new rule: leave the ID empty or do not specify the ID parameter.</li> <li><b>modify</b> an existing rule: specify the rule ID that needs to be updated/modified.</li> <li><b>delete</b> an existing rule: existing Rules not included in the Rules list under the RateLimitingRules parameter will be deleted.</li>.",
16711670
},
16721671
"name": {
@@ -1878,21 +1877,20 @@ func ResourceTencentCloudTeoWebSecurityTemplate() *schema.Resource {
18781877
"exception_rules": {
18791878
Type: schema.TypeList,
18801879
Optional: true,
1881-
Computed: true,
18821880
MaxItems: 1,
18831881
Description: "Exception rule configuration.",
18841882
Elem: &schema.Resource{
18851883
Schema: map[string]*schema.Schema{
18861884
"rules": {
18871885
Type: schema.TypeList,
18881886
Optional: true,
1889-
Computed: true,
18901887
Description: "Definition list of exception Rules. when using ModifySecurityPolicy to modify Web protection configuration: <li>if the Rules parameter is not specified or the parameter length is zero: clear all exception rule configurations.</li><li>if the ExceptionRules parameter value is not specified in SecurityPolicy: keep existing exception rule configurations without modification.</li>.",
18911888
Elem: &schema.Resource{
18921889
Schema: map[string]*schema.Schema{
18931890
"id": {
18941891
Type: schema.TypeString,
18951892
Optional: true,
1893+
Computed: true,
18961894
Description: "The ID of the exception rule. different rule configuration operations are supported by rule ID: <li> <b>add</b> a new rule: leave the ID empty or do not specify the ID parameter.</li> <li> <b>modify</b> an existing rule: specify the rule ID that needs to be updated/modified.</li> <li> <b>delete</b> an existing rule: existing Rules not included in the Rules list under the ExceptionRules parameter will be deleted.</li>.",
18971895
},
18981896
"name": {
@@ -2006,6 +2004,7 @@ func ResourceTencentCloudTeoWebSecurityTemplate() *schema.Resource {
20062004
"id": {
20072005
Type: schema.TypeString,
20082006
Optional: true,
2007+
Computed: true,
20092008
Description: "The ID of a Bot custom rule. different rule configuration operations are supported by rule ID: <li><b>add</b> a new rule: leave the ID empty or do not specify the ID parameter.</li> <li><b>modify</b> an existing rule: specify the rule ID that needs to be updated/modified.</li> <li><b>delete</b> an existing rule: existing Rules not included in the Rules list under the BotManagementCustomRules parameter will be deleted.</li>.",
20102009
},
20112010
"name": {
@@ -4279,6 +4278,7 @@ func ResourceTencentCloudTeoWebSecurityTemplate() *schema.Resource {
42794278
"id": {
42804279
Type: schema.TypeString,
42814280
Optional: true,
4281+
Computed: true,
42824282
Description: "Client authentication rule ID. supported rule configuration operations by rule ID: <li> <b>add</b> a new rule: leave the ID empty or do not specify the ID parameter.</li> <li> <b>modify</b> an existing rule: specify the rule ID that needs to be updated/modified.</li> <li> <b>delete</b> an existing rule: existing rules not included in the ClientAttestationRule list under BotManagement parameters will be deleted.</li>.",
42834283
},
42844284
"name": {
@@ -4826,6 +4826,7 @@ func ResourceTencentCloudTeoWebSecurityTemplate() *schema.Resource {
48264826
"id": {
48274827
Type: schema.TypeString,
48284828
Optional: true,
4829+
Computed: true,
48294830
Description: "Browser spoofing identification rule ID. rule ID supports different rule configuration operations: <li> <b>add</b> a new rule: ID is empty or without specifying the ID parameter;</li> <li> <b>modify</b> an existing rule: specify the rule ID that needs to be updated/modified;</li> <li> <b>delete</b> an existing rule: existing Rules not included in the Rules list of the BrowserImpersonationDetection parameter will be deleted.</li>.",
48304831
},
48314832
"name": {
@@ -6362,6 +6363,10 @@ func resourceTencentCloudTeoWebSecurityTemplateCreate(d *schema.ResourceData, me
63626363
customRule.Id = helper.String(v)
63636364
}
63646365

6366+
if v, ok := rulesMap["rule_type"].(string); ok && v != "" {
6367+
customRule.RuleType = helper.String(v)
6368+
}
6369+
63656370
if v, ok := rulesMap["priority"].(int); ok {
63666371
customRule.Priority = helper.IntInt64(v)
63676372
}
@@ -10221,7 +10226,7 @@ func resourceTencentCloudTeoWebSecurityTemplateRead(d *schema.ResourceData, meta
1022110226
if respData.CustomRules != nil {
1022210227
customRulesMap := map[string]interface{}{}
1022310228
rulesList := make([]map[string]interface{}, 0, len(respData.CustomRules.Rules))
10224-
if respData.CustomRules.Rules != nil {
10229+
if respData.CustomRules.Rules != nil && len(respData.CustomRules.Rules) > 0 {
1022510230
for _, rules := range respData.CustomRules.Rules {
1022610231
rulesMap := map[string]interface{}{}
1022710232

@@ -10359,9 +10364,8 @@ func resourceTencentCloudTeoWebSecurityTemplateRead(d *schema.ResourceData, meta
1035910364
}
1036010365

1036110366
customRulesMap["rules"] = rulesList
10367+
tmpMap["custom_rules"] = []interface{}{customRulesMap}
1036210368
}
10363-
10364-
tmpMap["custom_rules"] = []interface{}{customRulesMap}
1036510369
}
1036610370

1036710371
if respData.ManagedRules != nil {
@@ -11323,7 +11327,7 @@ func resourceTencentCloudTeoWebSecurityTemplateRead(d *schema.ResourceData, meta
1132311327
if respData.RateLimitingRules != nil {
1132411328
rateLimitingRulesMap := map[string]interface{}{}
1132511329
rulesList := make([]map[string]interface{}, 0, len(respData.RateLimitingRules.Rules))
11326-
if respData.RateLimitingRules.Rules != nil {
11330+
if respData.RateLimitingRules.Rules != nil && len(respData.RateLimitingRules.Rules) > 0 {
1132711331
for _, rules := range respData.RateLimitingRules.Rules {
1132811332
rulesMap := map[string]interface{}{}
1132911333

@@ -11473,15 +11477,14 @@ func resourceTencentCloudTeoWebSecurityTemplateRead(d *schema.ResourceData, meta
1147311477
}
1147411478

1147511479
rateLimitingRulesMap["rules"] = rulesList
11480+
tmpMap["rate_limiting_rules"] = []interface{}{rateLimitingRulesMap}
1147611481
}
11477-
11478-
tmpMap["rate_limiting_rules"] = []interface{}{rateLimitingRulesMap}
1147911482
}
1148011483

1148111484
if respData.ExceptionRules != nil {
1148211485
exceptionRulesMap := map[string]interface{}{}
1148311486
rulesList := make([]map[string]interface{}, 0, len(respData.ExceptionRules.Rules))
11484-
if respData.ExceptionRules.Rules != nil {
11487+
if respData.ExceptionRules.Rules != nil && len(respData.ExceptionRules.Rules) > 0 {
1148511488
for _, rules := range respData.ExceptionRules.Rules {
1148611489
rulesMap := map[string]interface{}{}
1148711490

@@ -11547,9 +11550,8 @@ func resourceTencentCloudTeoWebSecurityTemplateRead(d *schema.ResourceData, meta
1154711550
}
1154811551

1154911552
exceptionRulesMap["rules"] = rulesList
11553+
tmpMap["exception_rules"] = []interface{}{exceptionRulesMap}
1155011554
}
11551-
11552-
tmpMap["exception_rules"] = []interface{}{exceptionRulesMap}
1155311555
}
1155411556

1155511557
if respData.BotManagement != nil {
@@ -11562,7 +11564,7 @@ func resourceTencentCloudTeoWebSecurityTemplateRead(d *schema.ResourceData, meta
1156211564

1156311565
if respData.BotManagement.CustomRules != nil {
1156411566
rulesList := make([]map[string]interface{}, 0, len(respData.BotManagement.CustomRules.Rules))
11565-
if respData.BotManagement.CustomRules.Rules != nil {
11567+
if respData.BotManagement.CustomRules.Rules != nil && len(respData.CustomRules.Rules) > 0 {
1156611568
for _, rules := range respData.BotManagement.CustomRules.Rules {
1156711569
rulesMap := map[string]interface{}{}
1156811570

@@ -11710,8 +11712,8 @@ func resourceTencentCloudTeoWebSecurityTemplateRead(d *schema.ResourceData, meta
1171011712
}
1171111713

1171211714
customRulesMap["rules"] = rulesList
11715+
botManagementMap["custom_rules"] = []interface{}{customRulesMap}
1171311716
}
11714-
botManagementMap["custom_rules"] = []interface{}{customRulesMap}
1171511717
}
1171611718

1171711719
basicBotSettingsMap := map[string]interface{}{}
@@ -13102,7 +13104,7 @@ func resourceTencentCloudTeoWebSecurityTemplateRead(d *schema.ResourceData, meta
1310213104

1310313105
if respData.BotManagement.ClientAttestationRules != nil {
1310413106
rulesList := make([]map[string]interface{}, 0, len(respData.BotManagement.ClientAttestationRules.Rules))
13105-
if respData.BotManagement.ClientAttestationRules.Rules != nil {
13107+
if respData.BotManagement.ClientAttestationRules.Rules != nil && len(respData.BotManagement.ClientAttestationRules.Rules) > 0 {
1310613108
for _, rules := range respData.BotManagement.ClientAttestationRules.Rules {
1310713109
rulesMap := map[string]interface{}{}
1310813110

@@ -13474,15 +13476,15 @@ func resourceTencentCloudTeoWebSecurityTemplateRead(d *schema.ResourceData, meta
1347413476
}
1347513477

1347613478
clientAttestationRulesMap["rules"] = rulesList
13479+
botManagementMap["client_attestation_rules"] = []interface{}{clientAttestationRulesMap}
1347713480
}
13478-
botManagementMap["client_attestation_rules"] = []interface{}{clientAttestationRulesMap}
1347913481
}
1348013482

1348113483
browserImpersonationDetectionMap := map[string]interface{}{}
1348213484

1348313485
if respData.BotManagement.BrowserImpersonationDetection != nil {
1348413486
rulesList := make([]map[string]interface{}, 0, len(respData.BotManagement.BrowserImpersonationDetection.Rules))
13485-
if respData.BotManagement.BrowserImpersonationDetection.Rules != nil {
13487+
if respData.BotManagement.BrowserImpersonationDetection.Rules != nil && len(respData.BotManagement.BrowserImpersonationDetection.Rules) > 0 {
1348613488
for _, rules := range respData.BotManagement.BrowserImpersonationDetection.Rules {
1348713489
rulesMap := map[string]interface{}{}
1348813490

@@ -14416,8 +14418,8 @@ func resourceTencentCloudTeoWebSecurityTemplateRead(d *schema.ResourceData, meta
1441614418
}
1441714419

1441814420
browserImpersonationDetectionMap["rules"] = rulesList
14421+
botManagementMap["browser_impersonation_detection"] = []interface{}{browserImpersonationDetectionMap}
1441914422
}
14420-
botManagementMap["browser_impersonation_detection"] = []interface{}{browserImpersonationDetectionMap}
1442114423
}
1442214424

1442314425
tmpMap["bot_management"] = []interface{}{botManagementMap}
@@ -14583,6 +14585,10 @@ func resourceTencentCloudTeoWebSecurityTemplateUpdate(d *schema.ResourceData, me
1458314585
customRule.Id = helper.String(v)
1458414586
}
1458514587

14588+
if v, ok := rulesMap["rule_type"].(string); ok && v != "" {
14589+
customRule.RuleType = helper.String(v)
14590+
}
14591+
1458614592
if v, ok := rulesMap["priority"].(int); ok {
1458714593
customRule.Priority = helper.IntInt64(v)
1458814594
}
@@ -14592,6 +14598,8 @@ func resourceTencentCloudTeoWebSecurityTemplateUpdate(d *schema.ResourceData, me
1459214598
}
1459314599

1459414600
securityPolicy.CustomRules = &customRules
14601+
} else {
14602+
securityPolicy.CustomRules = &teov20220901.CustomRules{}
1459514603
}
1459614604

1459714605
if managedRulesMap, ok := helper.ConvertInterfacesHeadToMap(securityPolicyMap["managed_rules"]); ok {
@@ -15591,6 +15599,8 @@ func resourceTencentCloudTeoWebSecurityTemplateUpdate(d *schema.ResourceData, me
1559115599
}
1559215600

1559315601
securityPolicy.RateLimitingRules = &rateLimitingRules
15602+
} else {
15603+
securityPolicy.RateLimitingRules = &teov20220901.RateLimitingRules{}
1559415604
}
1559515605

1559615606
if exceptionRulesMap, ok := helper.ConvertInterfacesHeadToMap(securityPolicyMap["exception_rules"]); ok {
@@ -15672,6 +15682,8 @@ func resourceTencentCloudTeoWebSecurityTemplateUpdate(d *schema.ResourceData, me
1567215682
}
1567315683

1567415684
securityPolicy.ExceptionRules = &exceptionRules
15685+
} else {
15686+
securityPolicy.ExceptionRules = &teov20220901.ExceptionRules{}
1567515687
}
1567615688

1567715689
if botManagementMap, ok := helper.ConvertInterfacesHeadToMap(securityPolicyMap["bot_management"]); ok {
@@ -15822,6 +15834,8 @@ func resourceTencentCloudTeoWebSecurityTemplateUpdate(d *schema.ResourceData, me
1582215834
}
1582315835

1582415836
botManagement.CustomRules = &botManagementCustomRules
15837+
} else {
15838+
botManagement.CustomRules = &teov20220901.BotManagementCustomRules{}
1582515839
}
1582615840

1582715841
if basicBotSettingsMap, ok := helper.ConvertInterfacesHeadToMap(botManagementMap["basic_bot_settings"]); ok {
@@ -17122,6 +17136,8 @@ func resourceTencentCloudTeoWebSecurityTemplateUpdate(d *schema.ResourceData, me
1712217136
}
1712317137

1712417138
botManagement.BasicBotSettings = &basicBotSettings
17139+
} else {
17140+
botManagement.BasicBotSettings = &teov20220901.BasicBotSettings{}
1712517141
}
1712617142

1712717143
if clientAttestationRulesMap, ok := helper.ConvertInterfacesHeadToMap(botManagementMap["client_attestation_rules"]); ok {
@@ -17476,6 +17492,8 @@ func resourceTencentCloudTeoWebSecurityTemplateUpdate(d *schema.ResourceData, me
1747617492
}
1747717493

1747817494
botManagement.ClientAttestationRules = &clientAttestationRules
17495+
} else {
17496+
botManagement.ClientAttestationRules = &teov20220901.ClientAttestationRules{}
1747917497
}
1748017498

1748117499
if browserImpersonationDetectionMap, ok := helper.ConvertInterfacesHeadToMap(botManagementMap["browser_impersonation_detection"]); ok {
@@ -18353,6 +18371,8 @@ func resourceTencentCloudTeoWebSecurityTemplateUpdate(d *schema.ResourceData, me
1835318371
}
1835418372

1835518373
botManagement.BrowserImpersonationDetection = &browserImpersonationDetection
18374+
} else {
18375+
botManagement.BrowserImpersonationDetection = &teov20220901.BrowserImpersonationDetection{}
1835618376
}
1835718377

1835818378
securityPolicy.BotManagement = &botManagement

tencentcloud/services/teo/resource_tc_teo_web_security_template.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,48 @@ resource "tencentcloud_teo_web_security_template" "example" {
77
zone_id = "zone-3fkff38fyw8s"
88
template_name = "example"
99
security_policy {
10+
exception_rules {
11+
rules {
12+
name = "test"
13+
condition = "$${http.request.host} in ['1.1.1.1']"
14+
skip_scope = "WebSecurityModules"
15+
skip_option = "SkipOnAllRequestFields"
16+
web_security_modules_for_exception = ["websec-mod-managed-rules"]
17+
enabled = "on"
18+
}
19+
}
20+
21+
custom_rules {
22+
rules {
23+
name = "test"
24+
condition = "$${http.request.ip} in ['1.1.1.1']"
25+
enabled = "on"
26+
rule_type = "BasicAccessRule"
27+
action {
28+
name = "Deny"
29+
}
30+
}
31+
}
32+
33+
rate_limiting_rules {
34+
rules {
35+
name = "单 IP 请求速率限制"
36+
condition = "$${http.request.uri.path} contain ['/checkout/submit']"
37+
count_by = ["http.request.ip"]
38+
max_request_threshold = 300
39+
counting_period = "60s"
40+
action_duration = "30m"
41+
priority = 50
42+
enabled = "on"
43+
action {
44+
name = "Challenge"
45+
challenge_action_parameters {
46+
challenge_option = "JSChallenge"
47+
}
48+
}
49+
}
50+
}
51+
1052
bot_management {
1153
enabled = "off"
1254
basic_bot_settings {

0 commit comments

Comments
 (0)