Skip to content

Commit f8379a3

Browse files
tongyimingmikatongandrew-tx
authored
add antiddos datasource (#2330)
* add antiddos datasource * add antiddos datasource * refact(ddos): conflict resolve --------- Co-authored-by: mikatong <mikatong@tencent.com> Co-authored-by: andrewjiang <andrewjiang@tencent.com>
1 parent a43ede9 commit f8379a3

24 files changed

+1955
-6
lines changed

.changelog/2330.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
```release-note:new-data-source
2+
tencentcloud_antiddos_pending_risk_info
3+
```
4+
5+
```release-note:new-data-source
6+
tencentcloud_antiddos_overview_index
7+
```
8+
9+
```release-note:new-data-source
10+
tencentcloud_antiddos_overview_ddos_trend
11+
```
12+
13+
```release-note:new-data-source
14+
tencentcloud_antiddos_overview_ddos_event_list
15+
```
16+
17+
```release-note:new-data-source
18+
tencentcloud_antiddos_overview_cc_trend
19+
```
20+
21+
```release-note:new-resource
22+
tencentcloud_antiddos_ddos_black_white_ip
23+
```
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/*
2+
Use this data source to query detailed information of antiddos overview_cc_trend
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_antiddos_overview_cc_trend" "overview_cc_trend" {
8+
period = 300
9+
start_time = "2023-11-20 00:00:00"
10+
end_time = "2023-11-21 00:00:00"
11+
metric_name = "inqps"
12+
business = "bgpip"
13+
}
14+
```
15+
*/
16+
package tencentcloud
17+
18+
import (
19+
"context"
20+
21+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
22+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
23+
antiddos "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/antiddos/v20200309"
24+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
25+
)
26+
27+
func dataSourceTencentCloudAntiddosOverviewCcTrend() *schema.Resource {
28+
return &schema.Resource{
29+
Read: dataSourceTencentCloudAntiddosOverviewCcTrendRead,
30+
Schema: map[string]*schema.Schema{
31+
"period": {
32+
Required: true,
33+
Type: schema.TypeInt,
34+
Description: "Statistical granularity, values [300 (5 minutes), 3600 (hours), 86400 (days)].",
35+
},
36+
37+
"start_time": {
38+
Required: true,
39+
Type: schema.TypeString,
40+
Description: "StartTime.",
41+
},
42+
43+
"end_time": {
44+
Required: true,
45+
Type: schema.TypeString,
46+
Description: "EndTime.",
47+
},
48+
49+
"metric_name": {
50+
Required: true,
51+
Type: schema.TypeString,
52+
Description: "Indicator, values [inqps (peak total requests, dropqps (peak attack requests)), incount (number of requests), dropcount (number of attacks)].",
53+
},
54+
55+
"business": {
56+
Optional: true,
57+
Type: schema.TypeString,
58+
Description: "Dayu sub product code (bgpip represents advanced defense IP; net represents professional version of advanced defense IP).",
59+
},
60+
61+
"ip_list": {
62+
Optional: true,
63+
Type: schema.TypeSet,
64+
Elem: &schema.Schema{
65+
Type: schema.TypeString,
66+
},
67+
Description: "resource id list.",
68+
},
69+
70+
"data": {
71+
Computed: true,
72+
Type: schema.TypeSet,
73+
Elem: &schema.Schema{
74+
Type: schema.TypeInt,
75+
},
76+
Description: "Data.",
77+
},
78+
79+
"result_output_file": {
80+
Type: schema.TypeString,
81+
Optional: true,
82+
Description: "Used to save results.",
83+
},
84+
},
85+
}
86+
}
87+
88+
func dataSourceTencentCloudAntiddosOverviewCcTrendRead(d *schema.ResourceData, meta interface{}) error {
89+
defer logElapsed("data_source.tencentcloud_antiddos_overview_cc_trend.read")()
90+
defer inconsistentCheck(d, meta)()
91+
92+
logId := getLogId(contextNil)
93+
94+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
95+
96+
paramMap := make(map[string]interface{})
97+
if v, _ := d.GetOk("period"); v != nil {
98+
paramMap["Period"] = helper.IntInt64(v.(int))
99+
}
100+
101+
if v, ok := d.GetOk("start_time"); ok {
102+
paramMap["StartTime"] = helper.String(v.(string))
103+
}
104+
105+
if v, ok := d.GetOk("end_time"); ok {
106+
paramMap["EndTime"] = helper.String(v.(string))
107+
}
108+
109+
if v, ok := d.GetOk("metric_name"); ok {
110+
paramMap["MetricName"] = helper.String(v.(string))
111+
}
112+
113+
if v, ok := d.GetOk("business"); ok {
114+
paramMap["Business"] = helper.String(v.(string))
115+
}
116+
117+
if v, ok := d.GetOk("ip_list"); ok {
118+
ipListSet := v.(*schema.Set).List()
119+
paramMap["IpList"] = helper.InterfacesStringsPoint(ipListSet)
120+
}
121+
122+
service := AntiddosService{client: meta.(*TencentCloudClient).apiV3Conn}
123+
var overviewCCTrendResponseParams *antiddos.DescribeOverviewCCTrendResponseParams
124+
125+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
126+
result, e := service.DescribeAntiddosOverviewCcTrendByFilter(ctx, paramMap)
127+
if e != nil {
128+
return retryError(e)
129+
}
130+
overviewCCTrendResponseParams = result
131+
return nil
132+
})
133+
if err != nil {
134+
return err
135+
}
136+
137+
d.SetId(helper.BuildToken())
138+
resultMap := make(map[string]interface{})
139+
140+
if overviewCCTrendResponseParams != nil {
141+
_ = d.Set("data", overviewCCTrendResponseParams.Data)
142+
resultMap["data"] = overviewCCTrendResponseParams.Data
143+
}
144+
output, ok := d.GetOk("result_output_file")
145+
if ok && output.(string) != "" {
146+
if e := writeToFile(output.(string), resultMap); e != nil {
147+
return e
148+
}
149+
}
150+
return nil
151+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudAntiddosOverviewCcTrendDataSource_basic(t *testing.T) {
10+
t.Parallel()
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
13+
Providers: testAccProviders,
14+
Steps: []resource.TestStep{
15+
{
16+
Config: testAccAntiddosOverviewCcTrendDataSource,
17+
Check: resource.ComposeTestCheckFunc(
18+
testAccCheckTencentCloudDataSourceID("data.tencentcloud_antiddos_overview_cc_trend.overview_cc_trend"),
19+
resource.TestCheckResourceAttrSet("data.tencentcloud_antiddos_overview_cc_trend.overview_cc_trend", "data.#"),
20+
),
21+
},
22+
},
23+
})
24+
}
25+
26+
const testAccAntiddosOverviewCcTrendDataSource = `
27+
28+
data "tencentcloud_antiddos_overview_cc_trend" "overview_cc_trend" {
29+
period = 300
30+
start_time = "2023-11-20 00:00:00"
31+
end_time = "2023-11-21 00:00:00"
32+
metric_name = "inqps"
33+
business = "bgpip"
34+
}
35+
`

0 commit comments

Comments
 (0)