Skip to content

Commit 012dea5

Browse files
authored
feat/waf (#2340)
* feat/waf * feat/waf
1 parent 8f27932 commit 012dea5

File tree

16 files changed

+470
-47
lines changed

16 files changed

+470
-47
lines changed

.changelog/2340.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
```release-note:new-resource
2+
tencentcloud_waf_modify_access_period
3+
```
4+
5+
```release-note:enhancement
6+
tencentcloud_waf_clb_instance: Support set `bot_management` and `api_security`.
7+
```
8+
9+
```release-note:enhancement
10+
tencentcloud_waf_saas_instance: Support set `bot_management` and `api_security`.
11+
```

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.800
49+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.802
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.799
100+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.802
101101
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wedata v1.0.792
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.798/go.mod
881881
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.799/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
882882
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.800 h1:sQFdr2aQz+Z3wxI0BC0+yKQXwlo7q26u+yyPJcAuga4=
883883
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.800/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
884+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.802 h1:Oxtoc+JC1CjCcLJbmw9AWspiG8184A9CWFe1mujWoW8=
885+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.802/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=
@@ -987,6 +989,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.779 h1:4NpjQiF
987989
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.779/go.mod h1:kYBG2jgpjL7CuhYM+K1fkEtbWvNXrtt7NSLwXVCqmKA=
988990
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.799 h1:4RBEIK1t30g8VUTkU8KiE756Bq4O+ABUWYA1YoYpkZc=
989991
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.799/go.mod h1:y0QoatwZugI17brN5IRUBtwpPtWajnkZPbulNUxtcwg=
992+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.802 h1:ezxDJsbS0shcpDmyyxbPS3hxp92r9lujsj1/vr5tZXk=
993+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.802/go.mod h1:yX7LqAVM/vOt7bGz4AaFEQEJVfp0uJ5W6eEUCzsMXOI=
990994
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wedata v1.0.792 h1:NLgKNOIHWa38AmW7dyfI9Jlcp2Kr9VRD94f48pPNmxM=
991995
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wedata v1.0.792/go.mod h1:Xz6vPV3gHlzPwtEcmWdWO1EUXJDgn2p7UMCXbJiVioQ=
992996
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wss v1.0.199 h1:hMBLtiJPnZ9GvA677cTB6ELBR6B68wCR2QY1sNoGQc4=

tencentcloud/extension_waf.go

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,40 @@ var LABEL_TYPES_CLB = map[string]string{
415415
WAF_ULTIMATE_CLB: "sv_wsm_waf_package_ultimate_clb",
416416
}
417417

418+
var BOT_MANAGEMENT_LABEL_TYPES_CLB = map[int]string{
419+
REGION_ID_MAINLAND: "sv_wsm_waf_scene_bot_protection_clb",
420+
REGION_ID_NON_MAINLAND: "sv_wsm_waf_scene_bot_protection_clb_intl",
421+
}
422+
423+
var BOT_MANAGEMENT_LABEL_TYPES_SAAS = map[int]string{
424+
REGION_ID_MAINLAND: "sv_wsm_waf_scene_bot_protection",
425+
REGION_ID_NON_MAINLAND: "sv_wsm_waf_scene_bot_protection_intl",
426+
}
427+
428+
var API_SECURITY_LABEL_TYPES_CLB_REGION1 = map[string]string{
429+
WAF_PREMIUM_CLB: "sv_wsm_waf_scene_cpre",
430+
WAF_ENTERPRISE_CLB: "sv_wsm_waf_scene_cent",
431+
WAF_ULTIMATE_CLB: "sv_wsm_waf_scene_cult",
432+
}
433+
434+
var API_SECURITY_LABEL_TYPES_CLB_REGION9 = map[string]string{
435+
WAF_PREMIUM_CLB: "sv_wsm_waf_scene_cipre",
436+
WAF_ENTERPRISE_CLB: "sv_wsm_waf_scene_cient",
437+
WAF_ULTIMATE_CLB: "sv_wsm_waf_scene_ciult",
438+
}
439+
440+
var API_SECURITY_LABEL_TYPES_SAAS_REGION1 = map[string]string{
441+
WAF_PREMIUM_SAAS: "sv_wsm_waf_scene_pre",
442+
WAF_ENTERPRISE_SAAS: "sv_wsm_waf_scene_ent",
443+
WAF_ULTIMATE_SAAS: "sv_wsm_waf_scene_ult",
444+
}
445+
446+
var API_SECURITY_LABEL_TYPES_SAAS_REGION9 = map[string]string{
447+
WAF_PREMIUM_SAAS: "sv_wsm_waf_scene_ipre",
448+
WAF_ENTERPRISE_SAAS: "sv_wsm_waf_scene_ient",
449+
WAF_ULTIMATE_SAAS: "sv_wsm_waf_scene_iult",
450+
}
451+
418452
var WAF_CATEGORY_ID_CLB = map[string]int{
419453
WAF_PREMIUM_CLB: 101198,
420454
WAF_ENTERPRISE_CLB: 101204,
@@ -478,10 +512,22 @@ const (
478512
)
479513

480514
const (
481-
DOMIAN_CATEGORY_ID_CLB = 101207
482-
DOMAIN_SUB_PRODUCT_CODE_CLB = "sp_wsm_waf_domain_clb"
483-
DOMAIN_PID_CLB = 1001156
484-
DOMAIN_LABEL_TYPE_CLB = "sv_wsm_waf_domain_clb"
515+
DOMIAN_CATEGORY_ID_CLB = 101207
516+
DOMAIN_SUB_PRODUCT_CODE_CLB = "sp_wsm_waf_domain_clb"
517+
DOMAIN_PID_CLB = 1001156
518+
DOMAIN_LABEL_TYPE_CLB = "sv_wsm_waf_domain_clb"
519+
BOT_MANAGEMENT_CATEGORY_ID_CLB = 1025567
520+
BOT_MANAGEMENT_SUB_PRODUCT_CODE_CLB = "sp_wsm_waf_bot_protection_clb"
521+
BOT_MANAGEMENT_PID_CLB = 1017001
522+
API_SECURITY_CATEGORY_ID_CLB = 1027183
523+
API_SECURITY_SUB_PRODUCT_CODE_CLB = "sp_wsm_waf_apiclb"
524+
API_SECURITY_PID_CLB = 1028166
525+
BOT_MANAGEMENT_CATEGORY_ID_SAAS = 1025564
526+
BOT_MANAGEMENT_SUB_PRODUCT_CODE_SAAS = "sp_wsm_waf_bot_protection"
527+
BOT_MANAGEMENT_PID_SAAS = 1016997
528+
API_SECURITY_CATEGORY_ID_SAAS = 1027180
529+
API_SECURITY_SUB_PRODUCT_CODE_SAAS = "sp_wsm_waf_api"
530+
API_SECURITY_PID_SAAS = 1028161
485531
)
486532

487533
const (
@@ -658,3 +704,23 @@ var ANTI_INFO_LEAK_RULE_STATUS = []int{
658704
ANTI_INFO_LEAK_RULE_STATUS_0,
659705
ANTI_INFO_LEAK_RULE_STATUS_1,
660706
}
707+
708+
const (
709+
BOT_MANAGEMENT_STATUS_0 = 0
710+
BOT_MANAGEMENT_STATUS_1 = 1
711+
)
712+
713+
var BOT_MANAGEMENT_STATUS = []int{
714+
BOT_MANAGEMENT_STATUS_0,
715+
BOT_MANAGEMENT_STATUS_1,
716+
}
717+
718+
const (
719+
API_SECURITY_STATUS_0 = 0
720+
API_SECURITY_STATUS_1 = 1
721+
)
722+
723+
var API_SECURITY_STATUS = []int{
724+
API_SECURITY_STATUS_0,
725+
API_SECURITY_STATUS_1,
726+
}

tencentcloud/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,6 +1993,7 @@ Web Application Firewall(WAF)
19931993
tencentcloud_waf_cc_auto_status
19941994
tencentcloud_waf_cc_session
19951995
tencentcloud_waf_ip_access_control
1996+
tencentcloud_waf_modify_access_period
19961997
19971998
Wedata
19981999
Data Source
@@ -3824,6 +3825,7 @@ func Provider() *schema.Provider {
38243825
"tencentcloud_waf_cc_auto_status": resourceTencentCloudWafCcAutoStatus(),
38253826
"tencentcloud_waf_cc_session": resourceTencentCloudWafCcSession(),
38263827
"tencentcloud_waf_ip_access_control": resourceTencentCloudWafIpAccessControl(),
3828+
"tencentcloud_waf_modify_access_period": resourceTencentCloudWafModifyAccessPeriod(),
38273829
"tencentcloud_wedata_rule_template": resourceTencentCloudWedataRuleTemplate(),
38283830
"tencentcloud_wedata_datasource": resourceTencentCloudWedataDatasource(),
38293831
"tencentcloud_wedata_function": resourceTencentCloudWedataFunction(),

tencentcloud/resource_tc_waf_clb_instance.go

Lines changed: 98 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ resource "tencentcloud_waf_clb_instance" "example" {
2424
time_unit = "m"
2525
auto_renew_flag = 1
2626
elastic_mode = 1
27+
bot_management = 1
28+
api_security = 1
2729
}
2830
```
2931
@@ -38,6 +40,8 @@ resource "tencentcloud_waf_clb_instance" "example" {
3840
auto_renew_flag = 1
3941
elastic_mode = 1
4042
qps_limit = 200000
43+
bot_management = 1
44+
api_security = 1
4145
}
4246
```
4347
*/
@@ -109,6 +113,20 @@ func resourceTencentCloudWafClbInstance() *schema.Resource {
109113
ValidateFunc: validateIntegerMin(10000),
110114
Description: "QPS Limit, Minimum setting 10000. Only `elastic_mode` is 1, can be set.",
111115
},
116+
"bot_management": {
117+
Optional: true,
118+
Type: schema.TypeInt,
119+
Default: BOT_MANAGEMENT_STATUS_0,
120+
ValidateFunc: validateAllowedIntValue(BOT_MANAGEMENT_STATUS),
121+
Description: "Whether to purchase Bot management, 1: yes, 0: no. Default is 0.",
122+
},
123+
"api_security": {
124+
Optional: true,
125+
Type: schema.TypeInt,
126+
Default: API_SECURITY_STATUS_0,
127+
ValidateFunc: validateAllowedIntValue(API_SECURITY_STATUS),
128+
Description: "Whether to purchase API Security, 1: yes, 0: no. Default is 0.",
129+
},
112130
//"domain_pkg_count": {
113131
// Optional: true,
114132
// Type: schema.TypeInt,
@@ -142,11 +160,6 @@ func resourceTencentCloudWafClbInstance() *schema.Resource {
142160
Type: schema.TypeString,
143161
Description: "waf instance valid time.",
144162
},
145-
"api_security": {
146-
Computed: true,
147-
Type: schema.TypeInt,
148-
Description: "waf instance api security status.",
149-
},
150163
"status": {
151164
Computed: true,
152165
Type: schema.TypeInt,
@@ -161,12 +174,13 @@ func resourceTencentCloudWafClbInstanceCreate(d *schema.ResourceData, meta inter
161174
defer inconsistentCheck(d, meta)()
162175

163176
var (
164-
logId = getLogId(contextNil)
165-
request = waf.NewGenerateDealsAndPayNewRequest()
166-
response = waf.NewGenerateDealsAndPayNewResponse()
167-
client = meta.(*TencentCloudClient).apiV3Conn
168-
instanceId string
169-
mainlandMode int
177+
logId = getLogId(contextNil)
178+
request = waf.NewGenerateDealsAndPayNewRequest()
179+
response = waf.NewGenerateDealsAndPayNewResponse()
180+
client = meta.(*TencentCloudClient).apiV3Conn
181+
instanceId string
182+
mainlandMode int
183+
goodsCategory string
170184
)
171185

172186
region := client.Region
@@ -187,7 +201,7 @@ func resourceTencentCloudWafClbInstanceCreate(d *schema.ResourceData, meta inter
187201
instanceGoodDetail := new(waf.GoodsDetailNew)
188202
instanceGood.GoodsNum = helper.IntInt64(1)
189203
if v, ok := d.GetOk("goods_category"); ok {
190-
goodsCategory := v.(string)
204+
goodsCategory = v.(string)
191205
goodsCategoryId := int64(WAF_CATEGORY_ID_CLB[goodsCategory])
192206
subProductCode := SUB_PRODUCT_CODE_CLB[goodsCategory]
193207
labelTypes := LABEL_TYPES_CLB[goodsCategory]
@@ -221,7 +235,63 @@ func resourceTencentCloudWafClbInstanceCreate(d *schema.ResourceData, meta inter
221235
instanceGood.GoodsDetail = instanceGoodDetail
222236
goods = append(goods, instanceGood)
223237

224-
//// make domain pkg
238+
// bot management
239+
if v, ok := d.GetOkExists("bot_management"); ok {
240+
if v.(int) == 1 {
241+
botManagementGood := new(waf.GoodNews)
242+
botManagementDetail := new(waf.GoodsDetailNew)
243+
botManagementGood.GoodsCategoryId = helper.IntInt64(BOT_MANAGEMENT_CATEGORY_ID_CLB)
244+
botManagementGood.GoodsNum = helper.IntInt64(1)
245+
botManagementDetail.SubProductCode = helper.String(BOT_MANAGEMENT_SUB_PRODUCT_CODE_CLB)
246+
botManagementDetail.Pid = helper.IntInt64(BOT_MANAGEMENT_PID_CLB)
247+
botManagementDetail.LabelTypes = helper.Strings([]string{BOT_MANAGEMENT_LABEL_TYPES_CLB[mainlandMode]})
248+
botManagementDetail.LabelCounts = []*int64{helper.IntInt64(1)}
249+
250+
if v, ok := d.GetOkExists("time_span"); ok {
251+
botManagementDetail.TimeSpan = helper.IntInt64(v.(int))
252+
}
253+
254+
if v, ok := d.GetOk("time_unit"); ok {
255+
botManagementDetail.TimeUnit = helper.String(v.(string))
256+
}
257+
258+
botManagementGood.RegionId = helper.IntInt64(mainlandMode)
259+
botManagementGood.GoodsDetail = botManagementDetail
260+
goods = append(goods, botManagementGood)
261+
}
262+
}
263+
264+
// api security
265+
if v, ok := d.GetOkExists("api_security"); ok {
266+
if v.(int) == 1 {
267+
apiSecurityGood := new(waf.GoodNews)
268+
apiSecurityDetail := new(waf.GoodsDetailNew)
269+
apiSecurityGood.GoodsCategoryId = helper.IntInt64(API_SECURITY_CATEGORY_ID_CLB)
270+
apiSecurityGood.GoodsNum = helper.IntInt64(1)
271+
apiSecurityDetail.SubProductCode = helper.String(API_SECURITY_SUB_PRODUCT_CODE_CLB)
272+
apiSecurityDetail.Pid = helper.IntInt64(API_SECURITY_PID_CLB)
273+
if mainlandMode == REGION_ID_1 {
274+
apiSecurityDetail.LabelTypes = helper.Strings([]string{API_SECURITY_LABEL_TYPES_CLB_REGION1[goodsCategory]})
275+
} else {
276+
apiSecurityDetail.LabelTypes = helper.Strings([]string{API_SECURITY_LABEL_TYPES_CLB_REGION9[goodsCategory]})
277+
}
278+
apiSecurityDetail.LabelCounts = []*int64{helper.IntInt64(1)}
279+
280+
if v, ok := d.GetOkExists("time_span"); ok {
281+
apiSecurityDetail.TimeSpan = helper.IntInt64(v.(int))
282+
}
283+
284+
if v, ok := d.GetOk("time_unit"); ok {
285+
apiSecurityDetail.TimeUnit = helper.String(v.(string))
286+
}
287+
288+
apiSecurityGood.RegionId = helper.IntInt64(mainlandMode)
289+
apiSecurityGood.GoodsDetail = apiSecurityDetail
290+
goods = append(goods, apiSecurityGood)
291+
}
292+
}
293+
294+
// make domain pkg
225295
//if v, ok := d.GetOkExists("domain_pkg_count"); ok {
226296
// domainPkgGood := new(waf.GoodNews)
227297
// domainPkgGoodDetail := new(waf.GoodsDetailNew)
@@ -248,8 +318,8 @@ func resourceTencentCloudWafClbInstanceCreate(d *schema.ResourceData, meta inter
248318
// domainPkgGood.GoodsDetail = domainPkgGoodDetail
249319
// goods = append(goods, domainPkgGood)
250320
//}
251-
//
252-
//// make qps pkg
321+
322+
// make qps pkg
253323
//if v, ok := d.GetOkExists("qps_pkg_count"); ok {
254324
// qpsPkgGood := new(waf.GoodNews)
255325
// qpsPkgGoodDetail := new(waf.GoodsDetailNew)
@@ -400,6 +470,18 @@ func resourceTencentCloudWafClbInstanceRead(d *schema.ResourceData, meta interfa
400470
_ = d.Set("qps_limit", instanceInfo.ElasticBilling)
401471
}
402472

473+
if instanceInfo.BotPkg != nil {
474+
_ = d.Set("bot_management", instanceInfo.BotPkg.Status)
475+
} else {
476+
_ = d.Set("bot_management", 0)
477+
}
478+
479+
if instanceInfo.ApiPkg != nil {
480+
_ = d.Set("api_security", instanceInfo.ApiPkg.Status)
481+
} else {
482+
_ = d.Set("api_security", 0)
483+
}
484+
403485
//if instanceInfo.DomainPkg != nil {
404486
// _ = d.Set("domain_pkg_count", instanceInfo.DomainPkg.Count)
405487
//}
@@ -421,10 +503,6 @@ func resourceTencentCloudWafClbInstanceRead(d *schema.ResourceData, meta interfa
421503
_ = d.Set("valid_time", instanceInfo.ValidTime)
422504
}
423505

424-
if instanceInfo.APISecurity != nil {
425-
_ = d.Set("api_security", instanceInfo.APISecurity)
426-
}
427-
428506
if instanceInfo.Status != nil {
429507
_ = d.Set("status", instanceInfo.Status)
430508
}
@@ -445,7 +523,7 @@ func resourceTencentCloudWafClbInstanceUpdate(d *schema.ResourceData, meta inter
445523
elasticMode int
446524
)
447525

448-
immutableArgs := []string{"goods_category", "time_span", "time_unit", "domain_pkg_count", "qps_pkg_count"}
526+
immutableArgs := []string{"goods_category", "time_span", "time_unit", "domain_pkg_count", "qps_pkg_count", "bot_management", "api_security"}
449527

450528
for _, v := range immutableArgs {
451529
if d.HasChange(v) {

0 commit comments

Comments
 (0)