Skip to content

Commit 01b9ed9

Browse files
authored
feat/waf (#2301)
* feat/waf * feat/waf * feat/waf
1 parent 66f96f2 commit 01b9ed9

20 files changed

+1420
-140
lines changed

.changelog/2301.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
```release-note:new-data-source
2+
tencentcloud_waf_user_clb_regions
3+
```
4+
5+
```release-note:new-resource
6+
tencentcloud_waf_cc
7+
```
8+
9+
```release-note:enhancement
10+
tencentcloud_waf_clb_domain: Support set cls status
11+
```
12+
13+
```release-note:enhancement
14+
tencentcloud_waf_saas_domain: Support set cls status
15+
```

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ require (
4646
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.693
4747
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544
4848
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.711
49-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.788
49+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.794
5050
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624
5151
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762
5252
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.692
@@ -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.199
9999
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.779
100-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.788
100+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.794
101101
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wedata v1.0.782
102102
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wss v1.0.199
103103
github.com/tencentyun/cos-go-sdk-v5 v0.7.42-0.20230629101357-7edd77448a0f

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.787 h1:Bxi9
881881
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.787/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
882882
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.788 h1:H3OCwvAHQSgphJNjAM6JhlKT1x83WF4uu6qahWTR1dE=
883883
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.788/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
884+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.794 h1:UZNzwFi22p+MPZNPcYMFniQcG0H05fFCXHyqsmx904U=
885+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.794/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
884886
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624 h1:nEZqsoqt1pEoaP9JjkHQy3/H00suCfzlHW1qOm2nYD8=
885887
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624/go.mod h1:+TXSVyeKwt1IhZRqKPbTREteBcP+K07Q846/ilNzLWA=
886888
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762 h1:2egy69SP/wPsmnfozcQVZ6tUY6F6N/TpEe/7xtXrc/8=
@@ -995,6 +997,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.771 h1:y047JWT
995997
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.771/go.mod h1:ahzakUD9//SLiEPseHAS9hZhth6lqSYHfc2w2rmQ/sM=
996998
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.788 h1:xHqalD5i8WG9NoIrURhH/1elbeVzR0ODQGVuxJLuepY=
997999
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.788/go.mod h1:cQ1AQPJ+XpJi3v4LkAQ4axonhwpxWCpCIXaQl/XJFWU=
1000+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.794 h1:BeiyGZ0WVMxlxz5wH2dxxPAGpo1KhQ33XHTucu1GK5k=
1001+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.794/go.mod h1:26sr2/i6bz7sboU0ag5bUDDIKB2yxQ8LId/U1z9nysk=
9981002
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wedata v1.0.782 h1:pVTxKpthJC8bw+nKPnLVHrprBOXdY7T0KVQ892yg81o=
9991003
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wedata v1.0.782/go.mod h1:Oy6D8ARyX6BCeMEbayqubSqNqXAOkenLexnzdwlbcs8=
10001004
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wss v1.0.199 h1:hMBLtiJPnZ9GvA677cTB6ELBR6B68wCR2QY1sNoGQc4=
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
Use this data source to query detailed information of waf user_clb_regions
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_waf_user_clb_regions" "example" {}
8+
```
9+
*/
10+
package tencentcloud
11+
12+
import (
13+
"context"
14+
"strconv"
15+
"time"
16+
17+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
18+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
19+
waf "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf/v20180125"
20+
)
21+
22+
func dataSourceTencentCloudWafUserClbRegions() *schema.Resource {
23+
return &schema.Resource{
24+
Read: dataSourceTencentCloudWafUserClbRegionsRead,
25+
Schema: map[string]*schema.Schema{
26+
"data": {
27+
Computed: true,
28+
Type: schema.TypeSet,
29+
Elem: &schema.Schema{Type: schema.TypeString},
30+
Description: "Region list(ap-xxx format).",
31+
},
32+
"rich_datas": {
33+
Computed: true,
34+
Type: schema.TypeList,
35+
Description: "Detail info for region.",
36+
Elem: &schema.Resource{
37+
Schema: map[string]*schema.Schema{
38+
"id": {
39+
Type: schema.TypeString,
40+
Computed: true,
41+
Description: "Region ID.",
42+
},
43+
"text": {
44+
Type: schema.TypeString,
45+
Computed: true,
46+
Description: "Chinese description for region.",
47+
},
48+
"value": {
49+
Type: schema.TypeString,
50+
Computed: true,
51+
Description: "English description for region.",
52+
},
53+
"code": {
54+
Type: schema.TypeString,
55+
Computed: true,
56+
Description: "Region code.",
57+
},
58+
},
59+
},
60+
},
61+
"result_output_file": {
62+
Type: schema.TypeString,
63+
Optional: true,
64+
Description: "Used to save results.",
65+
},
66+
},
67+
}
68+
}
69+
70+
func dataSourceTencentCloudWafUserClbRegionsRead(d *schema.ResourceData, meta interface{}) error {
71+
defer logElapsed("data_source.tencentcloud_waf_user_clb_regions.read")()
72+
defer inconsistentCheck(d, meta)()
73+
74+
var (
75+
logId = getLogId(contextNil)
76+
ctx = context.WithValue(context.TODO(), logIdKey, logId)
77+
service = WafService{client: meta.(*TencentCloudClient).apiV3Conn}
78+
userClbRegions *waf.DescribeUserClbWafRegionsResponseParams
79+
)
80+
81+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
82+
result, e := service.DescribeWafUserClbRegionsByFilter(ctx)
83+
if e != nil {
84+
return retryError(e)
85+
}
86+
87+
userClbRegions = result
88+
return nil
89+
})
90+
91+
if err != nil {
92+
return err
93+
}
94+
95+
if userClbRegions.Data != nil {
96+
_ = d.Set("data", userClbRegions.Data)
97+
}
98+
99+
if userClbRegions.RichDatas != nil {
100+
tmpList := make([]map[string]interface{}, 0, len(userClbRegions.RichDatas))
101+
for _, clbWafRegionItem := range userClbRegions.RichDatas {
102+
clbWafRegionItemMap := map[string]interface{}{}
103+
104+
if clbWafRegionItem.Id != nil {
105+
clbWafRegionItemMap["id"] = clbWafRegionItem.Id
106+
}
107+
108+
if clbWafRegionItem.Text != nil {
109+
clbWafRegionItemMap["text"] = clbWafRegionItem.Text
110+
}
111+
112+
if clbWafRegionItem.Value != nil {
113+
clbWafRegionItemMap["value"] = clbWafRegionItem.Value
114+
}
115+
116+
if clbWafRegionItem.Code != nil {
117+
clbWafRegionItemMap["code"] = clbWafRegionItem.Code
118+
}
119+
120+
tmpList = append(tmpList, clbWafRegionItemMap)
121+
}
122+
123+
_ = d.Set("rich_datas", tmpList)
124+
}
125+
126+
d.SetId(strconv.FormatInt(time.Now().Unix(), 10))
127+
output, ok := d.GetOk("result_output_file")
128+
if ok && output.(string) != "" {
129+
if e := writeToFile(output.(string), d); e != nil {
130+
return e
131+
}
132+
}
133+
134+
return nil
135+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
// go test -i; go test -test.run TestAccTencentCloudWafUserClbRegionsDataSource_basic -v
10+
func TestAccTencentCloudWafUserClbRegionsDataSource_basic(t *testing.T) {
11+
t.Parallel()
12+
resource.Test(t, resource.TestCase{
13+
PreCheck: func() {
14+
testAccPreCheck(t)
15+
},
16+
Providers: testAccProviders,
17+
Steps: []resource.TestStep{
18+
{
19+
Config: testAccWafUserClbRegionsDataSource,
20+
Check: resource.ComposeTestCheckFunc(
21+
testAccCheckTencentCloudDataSourceID("data.tencentcloud_waf_user_clb_regions.example"),
22+
),
23+
},
24+
},
25+
})
26+
}
27+
28+
const testAccWafUserClbRegionsDataSource = `
29+
data "tencentcloud_waf_user_clb_regions" "example" {}
30+
`

tencentcloud/provider.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,6 +1955,7 @@ Web Application Firewall(WAF)
19551955
tencentcloud_waf_attack_total_count
19561956
tencentcloud_waf_peak_points
19571957
tencentcloud_waf_instance_qps_limit
1958+
tencentcloud_waf_user_clb_regions
19581959
19591960
Resource
19601961
tencentcloud_waf_custom_rule
@@ -1969,6 +1970,7 @@ Web Application Firewall(WAF)
19691970
tencentcloud_waf_module_status
19701971
tencentcloud_waf_protection_mode
19711972
tencentcloud_waf_web_shell
1973+
tencentcloud_waf_cc
19721974
19731975
Wedata
19741976
Data Source
@@ -2836,6 +2838,7 @@ func Provider() *schema.Provider {
28362838
"tencentcloud_waf_attack_total_count": dataSourceTencentCloudWafAttackTotalCount(),
28372839
"tencentcloud_waf_peak_points": dataSourceTencentCloudWafPeakPoints(),
28382840
"tencentcloud_waf_instance_qps_limit": dataSourceTencentCloudWafInstanceQpsLimit(),
2841+
"tencentcloud_waf_user_clb_regions": dataSourceTencentCloudWafUserClbRegions(),
28392842
"tencentcloud_cfw_nat_fw_switches": dataSourceTencentCloudCfwNatFwSwitches(),
28402843
"tencentcloud_cfw_vpc_fw_switches": dataSourceTencentCloudCfwVpcFwSwitches(),
28412844
"tencentcloud_cfw_edge_fw_switches": dataSourceTencentCloudCfwEdgeFwSwitches(),
@@ -3743,6 +3746,7 @@ func Provider() *schema.Provider {
37433746
"tencentcloud_waf_module_status": resourceTencentCloudWafModuleStatus(),
37443747
"tencentcloud_waf_protection_mode": resourceTencentCloudWafProtectionMode(),
37453748
"tencentcloud_waf_web_shell": resourceTencentCloudWafWebShell(),
3749+
"tencentcloud_waf_cc": resourceTencentCloudWafCc(),
37463750
"tencentcloud_wedata_function": resourceTencentCloudWedataFunction(),
37473751
"tencentcloud_wedata_resource": resourceTencentCloudWedataResource(),
37483752
"tencentcloud_wedata_script": resourceTencentCloudWedataScript(),

0 commit comments

Comments
 (0)