Skip to content

Commit c6def4c

Browse files
tongyimingmikatong
andauthored
Feat/ddos accessl3l4 (#845)
* feat: access ddosv2 l4 * feat: support ddos_v2 l3l4l7 * fix: ddos v2 support internation account test * fix: ddos v2 support internation account test Co-authored-by: mikatong <mikatong@tencent.com>
1 parent 04d9e11 commit c6def4c

33 files changed

+11353
-3
lines changed

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ require (
1717
github.com/mitchellh/go-homedir v1.1.0
1818
github.com/mozillazg/go-httpheader v0.3.0 // indirect
1919
github.com/pkg/errors v0.9.1
20+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/antiddos v1.0.334
2021
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/api v1.0.285
2122
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway v1.0.199
2223
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.199
@@ -32,7 +33,7 @@ require (
3233
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.332
3334
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.199
3435
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.199
35-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.199
36+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.335
3637
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dc v1.0.199
3738
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.294
3839
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/emr v1.0.287

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,8 @@ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s
446446
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
447447
github.com/tdakkota/asciicheck v0.0.0-20200416190851-d7f85be797a2 h1:Xr9gkxfOP0KQWXKNqmwe8vEeSUiUj4Rlee9CMVX2ZUQ=
448448
github.com/tdakkota/asciicheck v0.0.0-20200416190851-d7f85be797a2/go.mod h1:yHp0ai0Z9gUljN3o0xMhYJnH/IcvkdTBOX2fmJ93JEM=
449+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/antiddos v1.0.334 h1:wQMm0QGdVvdkYALiav8MHWnigkpquU4XiUsMOzEtw38=
450+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/antiddos v1.0.334/go.mod h1:6ficOD4j2/gwkkXUrSlInWqKIAuWrIid1u4UvMiC41A=
449451
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/api v1.0.285 h1:gFmukRGLtYiXVBVvg/5DP/0fM1+dKpwDjT+khtDVLmc=
450452
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/api v1.0.285/go.mod h1:aGlXSWjtSnE6kuqcaRy/NKj1CLiB8NlMSHGsDn+k7Ag=
451453
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway v1.0.199 h1:e9M5HSIq2xw61Oz9whoaq+QT95rZtowkY/2zhdzx9v4=
@@ -487,6 +489,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.199 h1:L0t
487489
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.199/go.mod h1:AvfGfE5JXkyMV6uGd6B++SIDp+VV/SSphg1q2RiANFw=
488490
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.199 h1:CzZEt6l0qDjZUW8D8rUNQ/sKw6z6oYYdWuby3hlsn8g=
489491
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.199/go.mod h1:pz4s3nOhoB9cY0+uWzifuwr7lfh/Gvi1rv0ADxpPzD4=
492+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.335 h1:D8qrelkK5udv8RzJJIABMzItGIyaZoYnxEVeIsYqiNw=
493+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.335/go.mod h1:pz4s3nOhoB9cY0+uWzifuwr7lfh/Gvi1rv0ADxpPzD4=
490494
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dc v1.0.199 h1:7ShREKvI8ik2YNtLF42JR9x2YEeZS/gZvhIRfpsI8T0=
491495
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dc v1.0.199/go.mod h1:5WGSrlIZJOhwIqPjjafb6vzrPEZieSHPhPMjjGPXOSU=
492496
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.294 h1:VKP8TRlMSDUIJ32GuFKr4a0Fv/oi4LksRVOfJoK9CVc=

tencentcloud/basic_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ const (
3939
defaultSecurityGroup = "sg-ijato2x1"
4040
defaultSecurityGroup2 = "sg-51rgzop1"
4141

42-
defaultProjectId = "1250480"
42+
defaultProjectId = "1250480"
43+
defaultDayuBgpIdV2 = "bgpip-000004x0"
44+
defaultDayuBgpIpV2 = "119.28.217.253"
4345
)
4446

4547
/*

tencentcloud/connectivity/client.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/aws/aws-sdk-go/aws/endpoints"
1414
"github.com/aws/aws-sdk-go/aws/session"
1515
"github.com/aws/aws-sdk-go/service/s3"
16+
antiddos "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/antiddos/v20200309"
1617
api "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/api/v20201106"
1718
apigateway "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway/v20180808"
1819
as "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as/v20180419"
@@ -104,6 +105,7 @@ type TencentCloudClient struct {
104105
clsConn *cls.Client
105106
dnsPodConn *dnspod.Client
106107
privateDnsConn *privatedns.Client
108+
antiddosConn *antiddos.Client
107109
}
108110

109111
// NewClientProfile returns a new ClientProfile
@@ -678,3 +680,16 @@ func (me *TencentCloudClient) UsePrivateDnsClient() *privatedns.Client {
678680

679681
return me.privateDnsConn
680682
}
683+
684+
// UseAntiddosClient returns antiddos client for service
685+
func (me *TencentCloudClient) UseAntiddosClient() *antiddos.Client {
686+
if me.antiddosConn != nil {
687+
return me.antiddosConn
688+
}
689+
690+
cpf := me.NewClientProfile(300)
691+
me.antiddosConn, _ = antiddos.NewClient(me.Credential, me.Region, cpf)
692+
me.antiddosConn.WithHttpTransport(&LogRoundTripper{})
693+
694+
return me.antiddosConn
695+
}
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
/*
2+
Use this data source to query dayu eip rules
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_dayu_eip" "test" {
8+
resource_id="bgpip-000004xg"
9+
}
10+
```
11+
*/
12+
package tencentcloud
13+
14+
import (
15+
"context"
16+
17+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
18+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
19+
)
20+
21+
func dataSourceTencentCloudDayuEip() *schema.Resource {
22+
return &schema.Resource{
23+
Read: dataSourceTencentCloudDayuEipRead,
24+
Schema: map[string]*schema.Schema{
25+
"resource_id": {
26+
Type: schema.TypeString,
27+
Required: true,
28+
Description: "Id of the resource.",
29+
},
30+
"bind_status": {
31+
Type: schema.TypeList,
32+
Elem: &schema.Schema{
33+
Type: schema.TypeString,
34+
ValidateFunc: validateAllowedStringValue(DDOS_EIP_BIND_STATUS),
35+
},
36+
Optional: true,
37+
Description: "The binding state of the instance, value range [BINDING, BIND, UNBINDING, UNBIND], default is [BINDING, BIND, UNBINDING, UNBIND].",
38+
},
39+
"offset": {
40+
Type: schema.TypeInt,
41+
Optional: true,
42+
Default: 0,
43+
Description: "The page start offset, default is `0`.",
44+
},
45+
"limit": {
46+
Type: schema.TypeInt,
47+
Optional: true,
48+
Default: 10,
49+
Description: "The number of pages, default is `10`.",
50+
},
51+
"result_output_file": {
52+
Type: schema.TypeString,
53+
Optional: true,
54+
Description: "Used to save results.",
55+
},
56+
"list": {
57+
Type: schema.TypeList,
58+
Computed: true,
59+
Description: "A list of layer 4 rules. Each element contains the following attributes:",
60+
Elem: &schema.Resource{
61+
Schema: map[string]*schema.Schema{
62+
"eip_list": {
63+
Type: schema.TypeList,
64+
Required: true,
65+
Elem: &schema.Schema{
66+
Type: schema.TypeString,
67+
Description: "",
68+
},
69+
},
70+
"instance_id": {
71+
Type: schema.TypeString,
72+
Optional: true,
73+
Description: "ID of the resource instance.",
74+
},
75+
"eip_bound_rsc_ins": {
76+
Type: schema.TypeString,
77+
Optional: true,
78+
Description: "The ID of the resource instance for the binding.",
79+
},
80+
"eip_bound_rsc_eni": {
81+
Type: schema.TypeString,
82+
Required: true,
83+
Description: "The ID of the bound ENI.",
84+
},
85+
"eip_bound_rsc_vip": {
86+
Type: schema.TypeString,
87+
Required: true,
88+
Description: "Bind the resource intranet IP.",
89+
},
90+
"created_time": {
91+
Type: schema.TypeString,
92+
Required: true,
93+
Description: "The created time of resource.",
94+
},
95+
"expired_time": {
96+
Type: schema.TypeString,
97+
Required: true,
98+
Description: "The expired time of resource.",
99+
},
100+
"modify_time": {
101+
Type: schema.TypeString,
102+
Required: true,
103+
Description: "The modify time of resource.",
104+
},
105+
"protection_status": {
106+
Type: schema.TypeString,
107+
Required: true,
108+
Description: "The protection status of the asset instance.",
109+
},
110+
"eip_address_status": {
111+
Type: schema.TypeString,
112+
Required: true,
113+
Description: "Eip PUBLIC IP status.",
114+
},
115+
"region": {
116+
Type: schema.TypeString,
117+
Required: true,
118+
Description: "The region where the asset instance is located.",
119+
},
120+
},
121+
},
122+
},
123+
},
124+
}
125+
}
126+
127+
func dataSourceTencentCloudDayuEipRead(d *schema.ResourceData, meta interface{}) error {
128+
defer logElapsed("data_source.tencentcloud_dayu_l4_rules.read")()
129+
130+
logId := getLogId(contextNil)
131+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
132+
133+
resourceId := d.Get("resource_id").(string)
134+
var bindStatus []string
135+
if v, ok := d.GetOk("bind_status"); ok {
136+
tmpBindStatusList := v.([]interface{})
137+
for _, tmpBindStatus := range tmpBindStatusList {
138+
bindStatus = append(bindStatus, tmpBindStatus.(string))
139+
}
140+
} else {
141+
bindStatus = DDOS_EIP_BIND_STATUS
142+
}
143+
offset := d.Get("offset").(int)
144+
limit := d.Get("limit").(int)
145+
146+
antiddosService := AntiddosService{client: meta.(*TencentCloudClient).apiV3Conn}
147+
result, err := antiddosService.DescribeListBGPIPInstances(ctx, resourceId, bindStatus, offset, limit)
148+
if err != nil {
149+
return err
150+
}
151+
resultList := make([]map[string]interface{}, 0)
152+
for _, eipItem := range result {
153+
tmpEipInfo := make(map[string]interface{})
154+
eipList := make([]string, 0)
155+
for _, eip := range eipItem.InstanceDetail.EipList {
156+
eipList = append(eipList, *eip)
157+
}
158+
tmpEipInfo["eip_list"] = eipList
159+
tmpEipInfo["instance_id"] = *eipItem.InstanceDetail.InstanceId
160+
tmpEipInfo["region"] = *eipItem.Region.Region
161+
tmpEipInfo["eip_bound_rsc_ins"] = *eipItem.EipAddressInfo.EipBoundRscIns
162+
tmpEipInfo["eip_bound_rsc_eni"] = *eipItem.EipAddressInfo.EipBoundRscEni
163+
tmpEipInfo["eip_bound_rsc_vip"] = *eipItem.EipAddressInfo.EipBoundRscVip
164+
tmpEipInfo["eip_address_status"] = *eipItem.EipAddressStatus
165+
tmpEipInfo["protection_status"] = *eipItem.Status
166+
tmpEipInfo["created_time"] = *eipItem.CreatedTime
167+
tmpEipInfo["expired_time"] = *eipItem.ExpiredTime
168+
tmpEipInfo["modify_time"] = *eipItem.EipAddressInfo.ModifyTime
169+
170+
resultList = append(resultList, tmpEipInfo)
171+
}
172+
ids := make([]string, 0, len(resultList))
173+
for _, listItem := range resultList {
174+
ids = append(ids, listItem["instance_id"].(string))
175+
}
176+
d.SetId(helper.DataResourceIdsHash(ids))
177+
_ = d.Set("list", resultList)
178+
output, ok := d.GetOk("result_output_file")
179+
if ok && output.(string) != "" {
180+
return writeToFile(output.(string), resultList)
181+
}
182+
return nil
183+
184+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
7+
)
8+
9+
var testDataDayuEip = "data.tencentcloud_dayu_eip.test"
10+
11+
func TestAccTencentCloudDataDayuEip(t *testing.T) {
12+
t.Parallel()
13+
resource.Test(t, resource.TestCase{
14+
PreCheck: func() { testAccPreCheckCommon(t, ACCTUNT_TYPE_INTERNATION) },
15+
Providers: testAccProviders,
16+
CheckDestroy: testAccCheckDayuEipDestroy,
17+
Steps: []resource.TestStep{
18+
{
19+
Config: testAccTencentCloudDataDayuEip,
20+
Check: resource.ComposeAggregateTestCheckFunc(
21+
testAccCheckDayuEipExists("tencentcloud_dayu_eip.test_eip"),
22+
resource.TestCheckResourceAttr(testDataDayuEip, "list.#", "1"),
23+
),
24+
},
25+
},
26+
})
27+
}
28+
29+
const testAccTencentCloudDataDayuEip = `
30+
resource "tencentcloud_dayu_eip" "test_eip" {
31+
resource_id = "bgpip-000004xg"
32+
eip = "162.62.163.50"
33+
bind_resource_id = "ins-4m0jvxic"
34+
bind_resource_region = "hk"
35+
bind_resource_type = "cvm"
36+
}
37+
38+
data "tencentcloud_dayu_eip" "test" {
39+
resource_id = tencentcloud_dayu_eip.test_eip.resource_id
40+
}
41+
`

0 commit comments

Comments
 (0)