Skip to content

Commit 980b431

Browse files
authored
Feat/waf (#2160)
* feat/waf * feat/waf * feat/waf * feat/waf * add * feat/waf * feat/waf * feat/waf * feat/waf * feat/waf * feat/waf * feat/waf * feat/waf * feat/waf * feat/waf * add * add * feat/waf * feat/waf
1 parent 04b6fe6 commit 980b431

26 files changed

+1956
-192
lines changed

.changelog/2160.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
```release-note:new-resource
2+
tencentcloud_waf_anti_fake
3+
```
4+
5+
```release-note:new-resource
6+
tencentcloud_waf_anti_info_leak
7+
```
8+
9+
```release-note:new-data-source
10+
tencentcloud_waf_instance_qps_limit
11+
```
12+
13+
```release-note:enhancement
14+
resource/tencentcloud_waf_clb_domain: alb_type support apisix, tsegw
15+
```

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ require (
100100
gopkg.in/yaml.v2 v2.4.0
101101
)
102102

103-
require github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.754
103+
require github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.759
104104

105105
require (
106106
4d63.com/gocheckcompilerdirectives v1.2.1 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,10 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.755 h1:3u79chv
974974
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.755/go.mod h1:sOWUQj3GQHdkTqZc1b+mAFqWmhUv2Pg4EZoOjqDprzY=
975975
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.754 h1:QjRYFbhUfH4xlwJZf1dRiz8hhQxxbfGTm8F5zC0XYXk=
976976
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.754/go.mod h1:Xz3W12eATXJq8EULnYz8/7EY/w2GLCgCWb9Dw36SWKM=
977+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.757 h1:0068GFkgwRJHzFRsS3pUhzqD96v0DkFusmBG8U5XvWc=
978+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.757/go.mod h1:i906Da8ZhGtegDaZyFHTGbjnlzSI1f7hxGxC/eIBWtY=
979+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.759 h1:elaQECRbdePWEJXh3EMRWUkd5GIu5C+u9HrQZRML/3A=
980+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.759/go.mod h1:MDjcWvTd6A+6JFVbyw1jsLfq2tNDTkbiVKvgb7wb5uE=
977981
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wedata v1.0.725 h1:ETqP+erlPnDK1zafCmyDYNkZLcY+dAG3143Ihk5vFHk=
978982
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wedata v1.0.725/go.mod h1:YPB08jHrJ3GJJ09ZTEBLnMvI+lqQEtu17jJjyfq8+sU=
979983
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wss v1.0.199 h1:hMBLtiJPnZ9GvA677cTB6ELBR6B68wCR2QY1sNoGQc4=
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/*
2+
Use this data source to query detailed information of waf instance_qps_limit
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_waf_instance_qps_limit" "example" {
8+
instance_id = "waf_2kxtlbky00b3b4qz"
9+
}
10+
```
11+
*/
12+
package tencentcloud
13+
14+
import (
15+
"context"
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+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
21+
)
22+
23+
func dataSourceTencentCloudWafInstanceQpsLimit() *schema.Resource {
24+
return &schema.Resource{
25+
Read: dataSourceTencentCloudWafInstanceQpsLimitRead,
26+
Schema: map[string]*schema.Schema{
27+
"instance_id": {
28+
Required: true,
29+
Type: schema.TypeString,
30+
Description: "Unique ID of Instance.",
31+
},
32+
"type": {
33+
Optional: true,
34+
Type: schema.TypeString,
35+
Description: "Instance type.",
36+
},
37+
"qps_data": {
38+
Computed: true,
39+
Type: schema.TypeList,
40+
Description: "Qps info.",
41+
Elem: &schema.Resource{
42+
Schema: map[string]*schema.Schema{
43+
"elastic_billing_default": {
44+
Type: schema.TypeInt,
45+
Computed: true,
46+
Description: "Elastic qps default value.",
47+
},
48+
"elastic_billing_min": {
49+
Type: schema.TypeInt,
50+
Computed: true,
51+
Description: "Minimum elastic qps.",
52+
},
53+
"elastic_billing_max": {
54+
Type: schema.TypeInt,
55+
Computed: true,
56+
Description: "Maximum elastic qps.",
57+
},
58+
"qps_extend_max": {
59+
Type: schema.TypeInt,
60+
Computed: true,
61+
Description: "Maximum qps of extend package.",
62+
},
63+
"qps_extend_intl_max": {
64+
Type: schema.TypeInt,
65+
Computed: true,
66+
Description: "Maximum qps of extend package for overseas.",
67+
},
68+
},
69+
},
70+
},
71+
"result_output_file": {
72+
Type: schema.TypeString,
73+
Optional: true,
74+
Description: "Used to save results.",
75+
},
76+
},
77+
}
78+
}
79+
80+
func dataSourceTencentCloudWafInstanceQpsLimitRead(d *schema.ResourceData, meta interface{}) error {
81+
defer logElapsed("data_source.tencentcloud_waf_instance_qps_limit.read")()
82+
defer inconsistentCheck(d, meta)()
83+
84+
var (
85+
logId = getLogId(contextNil)
86+
ctx = context.WithValue(context.TODO(), logIdKey, logId)
87+
service = WafService{client: meta.(*TencentCloudClient).apiV3Conn}
88+
qpsData *waf.QpsData
89+
instanceId string
90+
)
91+
92+
paramMap := make(map[string]interface{})
93+
if v, ok := d.GetOk("instance_id"); ok {
94+
paramMap["InstanceId"] = helper.String(v.(string))
95+
instanceId = v.(string)
96+
}
97+
98+
if v, ok := d.GetOk("type"); ok {
99+
paramMap["Type"] = helper.String(v.(string))
100+
}
101+
102+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
103+
result, e := service.DescribeWafInstanceQpsLimitByFilter(ctx, paramMap)
104+
if e != nil {
105+
return retryError(e)
106+
}
107+
108+
qpsData = result
109+
return nil
110+
})
111+
112+
if err != nil {
113+
return err
114+
}
115+
116+
if qpsData != nil {
117+
tmqList := []interface{}{}
118+
qpsDataMap := map[string]interface{}{}
119+
120+
if qpsData.ElasticBillingDefault != nil {
121+
qpsDataMap["elastic_billing_default"] = qpsData.ElasticBillingDefault
122+
}
123+
124+
if qpsData.ElasticBillingMin != nil {
125+
qpsDataMap["elastic_billing_min"] = qpsData.ElasticBillingMin
126+
}
127+
128+
if qpsData.ElasticBillingMax != nil {
129+
qpsDataMap["elastic_billing_max"] = qpsData.ElasticBillingMax
130+
}
131+
132+
if qpsData.QPSExtendMax != nil {
133+
qpsDataMap["qps_extend_max"] = qpsData.QPSExtendMax
134+
}
135+
136+
if qpsData.QPSExtendIntlMax != nil {
137+
qpsDataMap["qps_extend_intl_max"] = qpsData.QPSExtendIntlMax
138+
}
139+
140+
tmqList = append(tmqList, qpsDataMap)
141+
_ = d.Set("qps_data", tmqList)
142+
}
143+
144+
d.SetId(instanceId)
145+
output, ok := d.GetOk("result_output_file")
146+
if ok && output.(string) != "" {
147+
if e := writeToFile(output.(string), d); e != nil {
148+
return e
149+
}
150+
}
151+
152+
return nil
153+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 TestAccTencentCloudWafInstanceQpsLimitDataSource_basic -v
10+
func TestAccTencentCloudWafInstanceQpsLimitDataSource_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: testAccWafInstanceQpsLimitDataSource,
20+
Check: resource.ComposeTestCheckFunc(
21+
testAccCheckTencentCloudDataSourceID("data.tencentcloud_waf_instance_qps_limit.example"),
22+
),
23+
},
24+
},
25+
})
26+
}
27+
28+
const testAccWafInstanceQpsLimitDataSource = `
29+
data "tencentcloud_waf_instance_qps_limit" "example" {
30+
instance_id = "waf_2kxtlbky00b3b4qz"
31+
}
32+
`

tencentcloud/extension_waf.go

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,15 @@ const (
126126
)
127127

128128
const (
129-
ALB_TYPE_CLB = "clb"
129+
ALB_TYPE_CLB = "clb"
130+
ALB_TYPE_APISIX = "apisix"
131+
ALB_TYPE_TSEGW = "tsegw"
130132
)
131133

132134
var ALB_TYPES = []string{
133135
ALB_TYPE_CLB,
136+
ALB_TYPE_APISIX,
137+
ALB_TYPE_TSEGW,
134138
}
135139

136140
const (
@@ -592,3 +596,55 @@ var MetricNameList = []string{
592596
var (
593597
STATE_0 = 0
594598
)
599+
600+
const (
601+
ANTI_FAKE_URL_STATUS_0 = 0
602+
ANTI_FAKE_URL_STATUS_1 = 1
603+
ANTI_FAKE_URL_STATUS_2 = 2
604+
ANTI_FAKE_URL_STATUS_3 = 3
605+
)
606+
607+
var ANTI_FAKE_URL_STATUS = []int{
608+
ANTI_FAKE_URL_STATUS_0,
609+
ANTI_FAKE_URL_STATUS_1,
610+
ANTI_FAKE_URL_STATUS_2,
611+
ANTI_FAKE_URL_STATUS_3,
612+
}
613+
614+
const (
615+
ANTI_INFO_LEAK_ACTION_TYPE_0 = 0
616+
ANTI_INFO_LEAK_ACTION_TYPE_1 = 1
617+
ANTI_INFO_LEAK_ACTION_TYPE_2 = 2
618+
ANTI_INFO_LEAK_ACTION_TYPE_3 = 3
619+
ANTI_INFO_LEAK_ACTION_TYPE_4 = 4
620+
)
621+
622+
var ANTI_INFO_LEAK_ACTION_TYPE = []int{
623+
ANTI_INFO_LEAK_ACTION_TYPE_0,
624+
ANTI_INFO_LEAK_ACTION_TYPE_1,
625+
ANTI_INFO_LEAK_ACTION_TYPE_2,
626+
ANTI_INFO_LEAK_ACTION_TYPE_3,
627+
ANTI_INFO_LEAK_ACTION_TYPE_4,
628+
}
629+
630+
const (
631+
STRATEGIES_FIELD_RETURNCODE = "returncode"
632+
STRATEGIES_FIELD_KEYWORDS = "keywords"
633+
STRATEGIES_FIELD_INFORMATION = "information"
634+
)
635+
636+
var STRATEGIES_FIELD = []string{
637+
STRATEGIES_FIELD_RETURNCODE,
638+
STRATEGIES_FIELD_KEYWORDS,
639+
STRATEGIES_FIELD_INFORMATION,
640+
}
641+
642+
const (
643+
ANTI_INFO_LEAK_RULE_STATUS_0 = 0
644+
ANTI_INFO_LEAK_RULE_STATUS_1 = 1
645+
)
646+
647+
var ANTI_INFO_LEAK_RULE_STATUS = []int{
648+
ANTI_INFO_LEAK_RULE_STATUS_0,
649+
ANTI_INFO_LEAK_RULE_STATUS_1,
650+
}

tencentcloud/provider.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,7 @@ Waf
16761676
tencentcloud_waf_attack_overview
16771677
tencentcloud_waf_attack_total_count
16781678
tencentcloud_waf_peak_points
1679+
tencentcloud_waf_instance_qps_limit
16791680
16801681
Resource
16811682
tencentcloud_waf_custom_rule
@@ -1684,6 +1685,8 @@ Waf
16841685
tencentcloud_waf_saas_domain
16851686
tencentcloud_waf_clb_instance
16861687
tencentcloud_waf_saas_instance
1688+
tencentcloud_waf_anti_fake
1689+
tencentcloud_waf_anti_info_leak
16871690
*/
16881691
package tencentcloud
16891692

@@ -2344,6 +2347,7 @@ func Provider() *schema.Provider {
23442347
"tencentcloud_waf_attack_overview": dataSourceTencentCloudWafAttackOverview(),
23452348
"tencentcloud_waf_attack_total_count": dataSourceTencentCloudWafAttackTotalCount(),
23462349
"tencentcloud_waf_peak_points": dataSourceTencentCloudWafPeakPoints(),
2350+
"tencentcloud_waf_instance_qps_limit": dataSourceTencentCloudWafInstanceQpsLimit(),
23472351
"tencentcloud_ses_receivers": dataSourceTencentCloudSesReceivers(),
23482352
"tencentcloud_ses_send_tasks": dataSourceTencentCloudSesSendTasks(),
23492353
"tencentcloud_ses_email_identities": dataSourceTencentCloudSesEmailIdentities(),
@@ -3107,6 +3111,8 @@ func Provider() *schema.Provider {
31073111
"tencentcloud_waf_saas_domain": resourceTencentCloudWafSaasDomain(),
31083112
"tencentcloud_waf_clb_instance": resourceTencentCloudWafClbInstance(),
31093113
"tencentcloud_waf_saas_instance": resourceTencentCloudWafSaasInstance(),
3114+
"tencentcloud_waf_anti_fake": resourceTencentCloudWafAntiFake(),
3115+
"tencentcloud_waf_anti_info_leak": resourceTencentCloudWafAntiInfoLeak(),
31103116
},
31113117

31123118
ConfigureFunc: providerConfigure,

0 commit comments

Comments
 (0)