Skip to content

Commit 6ad5a3a

Browse files
authored
feat(waf): [128286560] add new resource (#3596)
* add * add
1 parent fa0b58d commit 6ad5a3a

31 files changed

+7494
-313
lines changed

.changelog/3596.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
```release-note:new-data-source
2+
tencentcloud_waf_owasp_rule_types
3+
```
4+
5+
```release-note:new-data-source
6+
tencentcloud_waf_owasp_rules
7+
```
8+
9+
```release-note:new-resource
10+
tencentcloud_waf_owasp_rule_type_config
11+
```
12+
13+
```release-note:new-resource
14+
tencentcloud_waf_owasp_rule_status_config
15+
```
16+
17+
```release-note:new-resource
18+
tencentcloud_waf_owasp_white_rule
19+
```

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ require (
9797
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tsf v1.0.674
9898
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod v1.0.860
9999
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.1.14
100-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.1170
100+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.1.36
101101
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wedata v1.1.45
102102
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wss v1.0.199
103103
github.com/tencentyun/cos-go-sdk-v5 v0.7.66

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -977,10 +977,10 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.46 h1:wWcfc
977977
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.46/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
978978
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.48 h1:aoRUrz2ag27jQWcOKHgeE+toSti6/xPqHKMLruOtJuM=
979979
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.48/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
980-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.50 h1:wZGiUXmzr4L0S1coFhnjddkyNrO5ZTtfxBDrbeR+1d8=
981-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.50/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
982980
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.49 h1:BQwUw2V21zIRJxstnaxtG/22lBL3+FbUgWhaC6Qd9ws=
983981
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.49/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
982+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.50 h1:wZGiUXmzr4L0S1coFhnjddkyNrO5ZTtfxBDrbeR+1d8=
983+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.50/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
984984
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993 h1:WlPgXldQCxt7qi5Xrc6j6zTrsXWzN5BcOGs7Irq7fwQ=
985985
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993/go.mod h1:Z9U8zNtyuyKhjS0698wqsrG/kLx1TQ5CEixXBwVe7xY=
986986
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/csip v1.0.860 h1:F3esKBIT3HW9+7Gt8cVgf8X06VdGIczpgLBUECzSEzU=
@@ -1118,6 +1118,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.1.14 h1:RsontLM/
11181118
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.1.14/go.mod h1:qvuXI7MmzMaUBhGaQhGdZU7QLp3hKS53a3otvIz4CYg=
11191119
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.1170 h1:kcQCWuI9zOkZgL5CK66HNAJmSWCSJxRrDxXT+j02CeE=
11201120
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.1170/go.mod h1:vTukVfThbBIc4lOf4eq/q51eEk78oZUJd2lAoJBOJwI=
1121+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.1.36 h1:d4Cjrt+VkS0OElToWZuojkj55z07ECvqfSyeyLOziF4=
1122+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.1.36/go.mod h1:4ukz7/m3FarLnjn9UTX/Oc0cTWLZb82MKVLov0Ac4/k=
11211123
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wedata v1.0.792 h1:NLgKNOIHWa38AmW7dyfI9Jlcp2Kr9VRD94f48pPNmxM=
11221124
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wedata v1.0.792/go.mod h1:Xz6vPV3gHlzPwtEcmWdWO1EUXJDgn2p7UMCXbJiVioQ=
11231125
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wedata v1.1.31 h1:5mDWm86NA0etP4ictillWtZgyCHiK9hpCmj+qEYeowc=

tencentcloud/provider.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,8 @@ func Provider() *schema.Provider {
12191219
"tencentcloud_waf_peak_points": waf.DataSourceTencentCloudWafPeakPoints(),
12201220
"tencentcloud_waf_instance_qps_limit": waf.DataSourceTencentCloudWafInstanceQpsLimit(),
12211221
"tencentcloud_waf_user_clb_regions": waf.DataSourceTencentCloudWafUserClbRegions(),
1222+
"tencentcloud_waf_owasp_rule_types": waf.DataSourceTencentCloudWafOwaspRuleTypes(),
1223+
"tencentcloud_waf_owasp_rules": waf.DataSourceTencentCloudWafOwaspRules(),
12221224
"tencentcloud_cfw_nat_fw_switches": cfw.DataSourceTencentCloudCfwNatFwSwitches(),
12231225
"tencentcloud_cfw_vpc_fw_switches": cfw.DataSourceTencentCloudCfwVpcFwSwitches(),
12241226
"tencentcloud_cfw_edge_fw_switches": cfw.DataSourceTencentCloudCfwEdgeFwSwitches(),
@@ -2331,6 +2333,9 @@ func Provider() *schema.Provider {
23312333
"tencentcloud_waf_bot_status_config": waf.ResourceTencentCloudWafBotStatusConfig(),
23322334
"tencentcloud_waf_bot_scene_ucb_rule": waf.ResourceTencentCloudWafBotSceneUCBRule(),
23332335
"tencentcloud_waf_attack_white_rule": waf.ResourceTencentCloudWafAttackWhiteRule(),
2336+
"tencentcloud_waf_owasp_rule_type_config": waf.ResourceTencentCloudWafOwaspRuleTypeConfig(),
2337+
"tencentcloud_waf_owasp_rule_status_config": waf.ResourceTencentCloudWafOwaspRuleStatusConfig(),
2338+
"tencentcloud_waf_owasp_white_rule": waf.ResourceTencentCloudWafOwaspWhiteRule(),
23342339
"tencentcloud_wedata_submit_task_operation": wedata.ResourceTencentCloudWedataSubmitTaskOperation(),
23352340
"tencentcloud_wedata_task": wedata.ResourceTencentCloudWedataTask(),
23362341
"tencentcloud_wedata_workflow_folder": wedata.ResourceTencentCloudWedataWorkflowFolder(),

tencentcloud/provider.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,6 +2197,8 @@ tencentcloud_waf_attack_total_count
21972197
tencentcloud_waf_peak_points
21982198
tencentcloud_waf_instance_qps_limit
21992199
tencentcloud_waf_user_clb_regions
2200+
tencentcloud_waf_owasp_rule_types
2201+
tencentcloud_waf_owasp_rules
22002202

22012203
Resource
22022204
tencentcloud_waf_custom_rule
@@ -2224,6 +2226,9 @@ tencentcloud_waf_bot_scene_status_config
22242226
tencentcloud_waf_bot_status_config
22252227
tencentcloud_waf_bot_scene_ucb_rule
22262228
tencentcloud_waf_attack_white_rule
2229+
tencentcloud_waf_owasp_rule_type_config
2230+
tencentcloud_waf_owasp_rule_status_config
2231+
tencentcloud_waf_owasp_white_rule
22272232

22282233
Wedata
22292234
Data Source
Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
package waf
2+
3+
import (
4+
"context"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8+
wafv20180125 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf/v20180125"
9+
10+
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
11+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
12+
)
13+
14+
func DataSourceTencentCloudWafOwaspRuleTypes() *schema.Resource {
15+
return &schema.Resource{
16+
Read: dataSourceTencentCloudWafOwaspRuleTypesRead,
17+
Schema: map[string]*schema.Schema{
18+
"domain": {
19+
Type: schema.TypeString,
20+
Required: true,
21+
Description: "Domain names to be queried.",
22+
},
23+
24+
"filters": {
25+
Type: schema.TypeList,
26+
Optional: true,
27+
Description: "Filter conditions. supports RuleId, CveID, and Desc.",
28+
Elem: &schema.Resource{
29+
Schema: map[string]*schema.Schema{
30+
"name": {
31+
Type: schema.TypeString,
32+
Required: true,
33+
Description: "Field name, used for filtering\nFilter the sub-order number (value) by DealName.",
34+
},
35+
"values": {
36+
Type: schema.TypeSet,
37+
Required: true,
38+
Description: "Values after filtering.",
39+
Elem: &schema.Schema{
40+
Type: schema.TypeString,
41+
},
42+
},
43+
"exact_match": {
44+
Type: schema.TypeBool,
45+
Required: true,
46+
Description: "Exact search or not.",
47+
},
48+
},
49+
},
50+
},
51+
52+
"list": {
53+
Type: schema.TypeList,
54+
Computed: true,
55+
Description: "Rule type list and information.",
56+
Elem: &schema.Resource{
57+
Schema: map[string]*schema.Schema{
58+
"type_id": {
59+
Type: schema.TypeInt,
60+
Computed: true,
61+
Description: "Type ID.",
62+
},
63+
"type_name": {
64+
Type: schema.TypeString,
65+
Computed: true,
66+
Description: "Type name.",
67+
},
68+
"description": {
69+
Type: schema.TypeString,
70+
Computed: true,
71+
Description: "Type description.",
72+
},
73+
"classification": {
74+
Type: schema.TypeString,
75+
Computed: true,
76+
Description: "Data type category.",
77+
},
78+
"action": {
79+
Type: schema.TypeInt,
80+
Computed: true,
81+
Description: "Protection mode of the rule type. valid values: 0 (observation), 1 (intercept).",
82+
},
83+
"level": {
84+
Type: schema.TypeInt,
85+
Computed: true,
86+
Description: "Protection level of the rule type. valid values: 100 (loose), 200 (normal), 300 (strict), 400 (ultra-strict).",
87+
},
88+
"status": {
89+
Type: schema.TypeInt,
90+
Computed: true,
91+
Description: "The switch status of the rule type. valid values: 0 (disabled), 1 (enabled).",
92+
},
93+
"total_rule": {
94+
Type: schema.TypeInt,
95+
Computed: true,
96+
Description: "Specifies all rules under the rule type. always.",
97+
},
98+
"active_rule": {
99+
Type: schema.TypeInt,
100+
Computed: true,
101+
Description: "Indicates the total number of rules enabled under the rule type.",
102+
},
103+
},
104+
},
105+
},
106+
107+
"result_output_file": {
108+
Type: schema.TypeString,
109+
Optional: true,
110+
Description: "Used to save results.",
111+
},
112+
},
113+
}
114+
}
115+
116+
func dataSourceTencentCloudWafOwaspRuleTypesRead(d *schema.ResourceData, meta interface{}) error {
117+
defer tccommon.LogElapsed("data_source.tencentcloud_waf_owasp_rule_types.read")()
118+
defer tccommon.InconsistentCheck(d, meta)()
119+
120+
var (
121+
logId = tccommon.GetLogId(nil)
122+
ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta)
123+
service = WafService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
124+
domain string
125+
)
126+
127+
paramMap := make(map[string]interface{})
128+
if v, ok := d.GetOk("domain"); ok {
129+
paramMap["Domain"] = helper.String(v.(string))
130+
domain = v.(string)
131+
}
132+
133+
if v, ok := d.GetOk("filters"); ok {
134+
filtersSet := v.([]interface{})
135+
tmpSet := make([]*wafv20180125.FiltersItemNew, 0, len(filtersSet))
136+
for _, item := range filtersSet {
137+
filtersMap := item.(map[string]interface{})
138+
filtersItemNew := wafv20180125.FiltersItemNew{}
139+
if v, ok := filtersMap["name"].(string); ok && v != "" {
140+
filtersItemNew.Name = helper.String(v)
141+
}
142+
143+
if v, ok := filtersMap["values"]; ok {
144+
valuesSet := v.(*schema.Set).List()
145+
for i := range valuesSet {
146+
values := valuesSet[i].(string)
147+
filtersItemNew.Values = append(filtersItemNew.Values, helper.String(values))
148+
}
149+
}
150+
151+
if v, ok := filtersMap["exact_match"].(bool); ok {
152+
filtersItemNew.ExactMatch = helper.Bool(v)
153+
}
154+
155+
tmpSet = append(tmpSet, &filtersItemNew)
156+
}
157+
158+
paramMap["Filters"] = tmpSet
159+
}
160+
161+
var respData []*wafv20180125.OwaspRuleType
162+
reqErr := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
163+
result, e := service.DescribeWafOwaspRuleTypesByFilter(ctx, paramMap)
164+
if e != nil {
165+
return tccommon.RetryError(e)
166+
}
167+
168+
respData = result
169+
return nil
170+
})
171+
172+
if reqErr != nil {
173+
return reqErr
174+
}
175+
176+
listList := make([]map[string]interface{}, 0, len(respData))
177+
for _, list := range respData {
178+
listMap := map[string]interface{}{}
179+
if list.TypeId != nil {
180+
listMap["type_id"] = list.TypeId
181+
}
182+
183+
if list.TypeName != nil {
184+
listMap["type_name"] = list.TypeName
185+
}
186+
187+
if list.Description != nil {
188+
listMap["description"] = list.Description
189+
}
190+
191+
if list.Classification != nil {
192+
listMap["classification"] = list.Classification
193+
}
194+
195+
if list.Action != nil {
196+
listMap["action"] = list.Action
197+
}
198+
199+
if list.Level != nil {
200+
listMap["level"] = list.Level
201+
}
202+
203+
if list.Status != nil {
204+
listMap["status"] = list.Status
205+
}
206+
207+
if list.TotalRule != nil {
208+
listMap["total_rule"] = list.TotalRule
209+
}
210+
211+
if list.ActiveRule != nil {
212+
listMap["active_rule"] = list.ActiveRule
213+
}
214+
215+
listList = append(listList, listMap)
216+
}
217+
218+
_ = d.Set("list", listList)
219+
d.SetId(domain)
220+
output, ok := d.GetOk("result_output_file")
221+
if ok && output.(string) != "" {
222+
if e := tccommon.WriteToFile(output.(string), d); e != nil {
223+
return e
224+
}
225+
}
226+
227+
return nil
228+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Use this data source to query detailed information of WAF owasp rule types
2+
3+
Example Usage
4+
5+
```hcl
6+
data "tencentcloud_waf_owasp_rule_types" "example" {
7+
domain = "demo.com"
8+
filters {
9+
name = "RuleId"
10+
values = ["10000001"]
11+
exact_match = true
12+
}
13+
}
14+
```
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package waf_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
8+
tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
9+
)
10+
11+
func TestAccTencentCloudWafOwaspRuleTypesDataSource_basic(t *testing.T) {
12+
t.Parallel()
13+
resource.Test(t, resource.TestCase{
14+
PreCheck: func() {
15+
tcacctest.AccPreCheck(t)
16+
},
17+
Providers: tcacctest.AccProviders,
18+
Steps: []resource.TestStep{{
19+
Config: testAccWafOwaspRuleTypesDataSource,
20+
Check: resource.ComposeTestCheckFunc(
21+
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_waf_owasp_rule_types.example"),
22+
),
23+
}},
24+
})
25+
}
26+
27+
const testAccWafOwaspRuleTypesDataSource = `
28+
data "tencentcloud_waf_owasp_rule_types" "example" {
29+
domain = "example.qcloud.com"
30+
filters {
31+
name = "RuleId"
32+
values = ["10000001"]
33+
exact_match = true
34+
}
35+
}
36+
`

0 commit comments

Comments
 (0)