Skip to content

Commit 20bc9f7

Browse files
committed
add antiddos datasource
1 parent b2c4a51 commit 20bc9f7

19 files changed

+8591
-3146
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
data "tencentcloud_antiddos_basic_device_status" "basic_device_status" {
2+
ip_list = [
3+
"127.0.0.1"
4+
]
5+
filter_region = 1
6+
}
7+
8+
data "tencentcloud_antiddos_bgp_biz_trend" "bgp_biz_trend" {
9+
business = "bgp-multip"
10+
start_time = "2023-11-22 09:25:00"
11+
end_time = "2023-11-22 10:25:00"
12+
metric_name = "intraffic"
13+
instance_id = "bgp-00000ry7"
14+
flag = 0
15+
}
16+
17+
data "tencentcloud_antiddos_list_listener" "list_listener" {
18+
}
19+
20+
data "tencentcloud_antiddos_overview_attack_trend" "overview_attack_trend" {
21+
type = "ddos"
22+
dimension = "attackcount"
23+
period = 86400
24+
start_time = "2023-11-21 10:28:31"
25+
end_time = "2023-11-22 10:28:31"
26+
}

examples/tencentcloud-antiddos/variables.tf

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
terraform {
2+
required_version = ">= 0.12"
3+
}

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ require (
2626
github.com/pkg/errors v0.9.1
2727
github.com/stretchr/testify v1.8.2
2828
github.com/tencentcloud/tencentcloud-sdk-go-intl-en v3.0.646+incompatible
29-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/antiddos v1.0.358
29+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/antiddos v1.0.799
3030
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/api v1.0.285
3131
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway v1.0.763
3232
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apm v1.0.624
@@ -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.797
49+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.799
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,8 +97,8 @@ 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/wedata v1.0.792
101100
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.794
101+
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
104104
github.com/yangwenmai/ratelimit v0.0.0-20180104140304-44221c2292e1

go.sum

Lines changed: 454 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
/*
2+
Use this data source to query detailed information of antiddos basic_device_status
3+
4+
# Example Usage
5+
6+
```hcl
7+
8+
data "tencentcloud_antiddos_basic_device_status" "basic_device_status" {
9+
ip_list = [
10+
"127.0.0.1"
11+
]
12+
filter_region = 1
13+
}
14+
15+
```
16+
*/
17+
package tencentcloud
18+
19+
import (
20+
"context"
21+
22+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
23+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
24+
antiddos "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/antiddos/v20200309"
25+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
26+
)
27+
28+
func dataSourceTencentCloudAntiddosBasicDeviceStatus() *schema.Resource {
29+
return &schema.Resource{
30+
Read: dataSourceTencentCloudAntiddosBasicDeviceStatusRead,
31+
Schema: map[string]*schema.Schema{
32+
"ip_list": {
33+
Optional: true,
34+
Type: schema.TypeSet,
35+
Elem: &schema.Schema{
36+
Type: schema.TypeString,
37+
},
38+
Description: "Ip resource list.",
39+
},
40+
41+
"id_list": {
42+
Optional: true,
43+
Type: schema.TypeSet,
44+
Elem: &schema.Schema{
45+
Type: schema.TypeString,
46+
},
47+
Description: "Named resource transfer ID.",
48+
},
49+
50+
"filter_region": {
51+
Optional: true,
52+
Type: schema.TypeInt,
53+
Description: "Region Id.",
54+
},
55+
56+
"data": {
57+
Computed: true,
58+
Type: schema.TypeList,
59+
Description: "Return resources and status, status code: 1- Blocking status 2- Normal status 3- Attack status.",
60+
Elem: &schema.Resource{
61+
Schema: map[string]*schema.Schema{
62+
"key": {
63+
Type: schema.TypeString,
64+
Computed: true,
65+
Description: "Properties name.",
66+
},
67+
"value": {
68+
Type: schema.TypeString,
69+
Computed: true,
70+
Description: "Properties value.",
71+
},
72+
},
73+
},
74+
},
75+
76+
"c_l_b_data": {
77+
Computed: true,
78+
Type: schema.TypeList,
79+
Description: "Note: This field may return null, indicating that a valid value cannot be obtained.",
80+
Elem: &schema.Resource{
81+
Schema: map[string]*schema.Schema{
82+
"key": {
83+
Type: schema.TypeString,
84+
Computed: true,
85+
Description: "Properties name.",
86+
},
87+
"value": {
88+
Type: schema.TypeString,
89+
Computed: true,
90+
Description: "Properties value.",
91+
},
92+
},
93+
},
94+
},
95+
96+
"result_output_file": {
97+
Type: schema.TypeString,
98+
Optional: true,
99+
Description: "Used to save results.",
100+
},
101+
},
102+
}
103+
}
104+
105+
func dataSourceTencentCloudAntiddosBasicDeviceStatusRead(d *schema.ResourceData, meta interface{}) error {
106+
defer logElapsed("data_source.tencentcloud_antiddos_basic_device_status.read")()
107+
defer inconsistentCheck(d, meta)()
108+
109+
logId := getLogId(contextNil)
110+
111+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
112+
113+
paramMap := make(map[string]interface{})
114+
if v, ok := d.GetOk("ip_list"); ok {
115+
ipListSet := v.(*schema.Set).List()
116+
paramMap["IpList"] = helper.InterfacesStringsPoint(ipListSet)
117+
}
118+
119+
if v, ok := d.GetOk("id_list"); ok {
120+
idListSet := v.(*schema.Set).List()
121+
paramMap["IdList"] = helper.InterfacesStringsPoint(idListSet)
122+
}
123+
124+
if v, ok := d.GetOkExists("filter_region"); ok {
125+
paramMap["FilterRegion"] = helper.IntUint64(v.(int))
126+
}
127+
128+
service := AntiddosService{client: meta.(*TencentCloudClient).apiV3Conn}
129+
130+
var basicDeviceStatus *antiddos.DescribeBasicDeviceStatusResponseParams
131+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
132+
result, e := service.DescribeAntiddosBasicDeviceStatusByFilter(ctx, paramMap)
133+
if e != nil {
134+
return retryError(e)
135+
}
136+
basicDeviceStatus = result
137+
return nil
138+
})
139+
if err != nil {
140+
return err
141+
}
142+
143+
tmpList := make([]map[string]interface{}, 0)
144+
145+
if basicDeviceStatus.Data != nil {
146+
for _, keyValue := range basicDeviceStatus.Data {
147+
keyValueMap := map[string]interface{}{}
148+
if keyValue.Key != nil {
149+
keyValueMap["key"] = keyValue.Key
150+
}
151+
if keyValue.Value != nil {
152+
keyValueMap["value"] = keyValue.Value
153+
}
154+
tmpList = append(tmpList, keyValueMap)
155+
}
156+
_ = d.Set("data", tmpList)
157+
}
158+
159+
if basicDeviceStatus.CLBData != nil {
160+
for _, keyValue := range basicDeviceStatus.CLBData {
161+
keyValueMap := map[string]interface{}{}
162+
if keyValue.Key != nil {
163+
keyValueMap["key"] = keyValue.Key
164+
}
165+
if keyValue.Value != nil {
166+
keyValueMap["value"] = keyValue.Value
167+
}
168+
tmpList = append(tmpList, keyValueMap)
169+
}
170+
_ = d.Set("c_l_b_data", tmpList)
171+
}
172+
173+
d.SetId(helper.BuildToken())
174+
output, ok := d.GetOk("result_output_file")
175+
if ok && output.(string) != "" {
176+
if e := writeToFile(output.(string), tmpList); e != nil {
177+
return e
178+
}
179+
}
180+
return nil
181+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudAntiddosBasicDeviceStatusDataSource_basic(t *testing.T) {
10+
t.Parallel()
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() {
13+
testAccPreCheck(t)
14+
},
15+
Providers: testAccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccAntiddosBasicDeviceStatusDataSource,
19+
Check: resource.ComposeTestCheckFunc(
20+
testAccCheckTencentCloudDataSourceID("data.tencentcloud_antiddos_basic_device_status.basic_device_status"),
21+
resource.TestCheckResourceAttr("data.tencentcloud_antiddos_basic_device_status.basic_device_status", "data.#", "1"),
22+
resource.TestCheckResourceAttr("data.tencentcloud_antiddos_basic_device_status.basic_device_status", "data.0.key", "127.0.0.1"),
23+
),
24+
},
25+
},
26+
})
27+
}
28+
29+
const testAccAntiddosBasicDeviceStatusDataSource = `
30+
31+
data "tencentcloud_antiddos_basic_device_status" "basic_device_status" {
32+
ip_list = [
33+
"127.0.0.1"
34+
]
35+
filter_region = 1
36+
}
37+
38+
`

0 commit comments

Comments
 (0)