Skip to content

Commit 808704c

Browse files
authored
add vpc route (#1866)
* add vpc route * add change log
1 parent 0950cd6 commit 808704c

14 files changed

+1640
-0
lines changed

.changelog/1866.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:new-data-source
2+
tencentcloud_vpc_net_detect_state_check
3+
```
4+
5+
```release-note:new-resource
6+
tencentcloud_eni_sg_attachment
7+
```
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
/*
2+
Use this data source to query detailed information of vpc net_detect_state_check
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_vpc_net_detect_state_check" "net_detect_state_check" {
8+
net_detect_id = "netd-12345678"
9+
detect_destination_ip = [
10+
"10.0.0.3",
11+
"10.0.0.2"
12+
]
13+
next_hop_type = "NORMAL_CVM"
14+
next_hop_destination = "10.0.0.4"
15+
}
16+
```
17+
*/
18+
package tencentcloud
19+
20+
import (
21+
"context"
22+
23+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
24+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
25+
vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"
26+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
27+
)
28+
29+
func dataSourceTencentCloudVpcNetDetectStateCheck() *schema.Resource {
30+
return &schema.Resource{
31+
Read: dataSourceTencentCloudVpcNetDetectStateCheckRead,
32+
Schema: map[string]*schema.Schema{
33+
"detect_destination_ip": {
34+
Required: true,
35+
Type: schema.TypeSet,
36+
Elem: &schema.Schema{
37+
Type: schema.TypeString,
38+
},
39+
Description: "The array of detection destination IPv4 addresses, which contains at most two IP addresses.",
40+
},
41+
42+
"next_hop_type": {
43+
Required: true,
44+
Type: schema.TypeString,
45+
Description: "The type of the next hop. Currently supported types are:VPN: VPN gateway;DIRECTCONNECT: direct connect gateway;PEERCONNECTION: peering connection;NAT: NAT gateway;NORMAL_CVM: normal CVM.",
46+
},
47+
48+
"next_hop_destination": {
49+
Required: true,
50+
Type: schema.TypeString,
51+
Description: "The next-hop destination gateway. The value is related to NextHopType.If NextHopType is set to VPN, the value of this parameter is the VPN gateway ID, such as vpngw-12345678.If NextHopType is set to DIRECTCONNECT, the value of this parameter is the direct connect gateway ID, such as dcg-12345678.If NextHopType is set to PEERCONNECTION, the value of this parameter is the peering connection ID, such as pcx-12345678.If NextHopType is set to NAT, the value of this parameter is the NAT gateway ID, such as nat-12345678.If NextHopType is set to NORMAL_CVM, the value of this parameter is the IPv4 address of the CVM, such as 10.0.0.12.",
52+
},
53+
54+
"net_detect_id": {
55+
Optional: true,
56+
Type: schema.TypeString,
57+
Description: "ID of a network inspector instance, e.g. netd-12345678. Enter at least one of this parameter, VpcId, SubnetId, and NetDetectName. Use NetDetectId if it is present.",
58+
},
59+
60+
"vpc_id": {
61+
Optional: true,
62+
Type: schema.TypeString,
63+
Description: "ID of a `VPC` instance, e.g. `vpc-12345678`, which is used together with SubnetId and NetDetectName. You should enter either this parameter or NetDetectId, or both. Use NetDetectId if it is present.",
64+
},
65+
66+
"subnet_id": {
67+
Optional: true,
68+
Type: schema.TypeString,
69+
Description: "ID of a subnet instance, e.g. `subnet-12345678`, which is used together with VpcId and NetDetectName. You should enter either this parameter or NetDetectId, or both. Use NetDetectId if it is present.",
70+
},
71+
72+
"net_detect_name": {
73+
Optional: true,
74+
Type: schema.TypeString,
75+
Description: "The name of a network inspector, up to 60 bytes in length. It is used together with VpcId and NetDetectName. You should enter either this parameter or NetDetectId, or both. Use NetDetectId if it is present.",
76+
},
77+
78+
"net_detect_ip_state_set": {
79+
Computed: true,
80+
Type: schema.TypeList,
81+
Description: "The array of network detection verification results.",
82+
Elem: &schema.Resource{
83+
Schema: map[string]*schema.Schema{
84+
"detect_destination_ip": {
85+
Type: schema.TypeString,
86+
Computed: true,
87+
Description: "The destination IPv4 address of network detection.",
88+
},
89+
"state": {
90+
Type: schema.TypeInt,
91+
Computed: true,
92+
Description: "The detection result.0: successful;-1: no packet loss occurred during routing;-2: packet loss occurred when outbound traffic is blocked by the ACL;-3: packet loss occurred when inbound traffic is blocked by the ACL;-4: other errors.",
93+
},
94+
"delay": {
95+
Type: schema.TypeInt,
96+
Computed: true,
97+
Description: "The latency. Unit: ms.",
98+
},
99+
"packet_loss_rate": {
100+
Type: schema.TypeInt,
101+
Computed: true,
102+
Description: "The packet loss rate.",
103+
},
104+
},
105+
},
106+
},
107+
108+
"result_output_file": {
109+
Type: schema.TypeString,
110+
Optional: true,
111+
Description: "Used to save results.",
112+
},
113+
},
114+
}
115+
}
116+
117+
func dataSourceTencentCloudVpcNetDetectStateCheckRead(d *schema.ResourceData, meta interface{}) error {
118+
defer logElapsed("data_source.tencentcloud_vpc_net_detect_state_check.read")()
119+
defer inconsistentCheck(d, meta)()
120+
121+
logId := getLogId(contextNil)
122+
123+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
124+
125+
paramMap := make(map[string]interface{})
126+
if v, ok := d.GetOk("detect_destination_ip"); ok {
127+
detectDestinationIpSet := v.(*schema.Set).List()
128+
paramMap["DetectDestinationIp"] = helper.InterfacesStringsPoint(detectDestinationIpSet)
129+
}
130+
131+
if v, ok := d.GetOk("next_hop_type"); ok {
132+
paramMap["NextHopType"] = helper.String(v.(string))
133+
}
134+
135+
if v, ok := d.GetOk("next_hop_destination"); ok {
136+
paramMap["NextHopDestination"] = helper.String(v.(string))
137+
}
138+
139+
if v, ok := d.GetOk("net_detect_id"); ok {
140+
paramMap["NetDetectId"] = helper.String(v.(string))
141+
}
142+
143+
if v, ok := d.GetOk("vpc_id"); ok {
144+
paramMap["VpcId"] = helper.String(v.(string))
145+
}
146+
147+
if v, ok := d.GetOk("subnet_id"); ok {
148+
paramMap["SubnetId"] = helper.String(v.(string))
149+
}
150+
151+
if v, ok := d.GetOk("net_detect_name"); ok {
152+
paramMap["NetDetectName"] = helper.String(v.(string))
153+
}
154+
155+
service := VpcService{client: meta.(*TencentCloudClient).apiV3Conn}
156+
157+
var netDetectIpStateSet []*vpc.NetDetectIpState
158+
159+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
160+
result, e := service.DescribeVpcNetDetectStateCheck(ctx, paramMap)
161+
if e != nil {
162+
return retryError(e)
163+
}
164+
netDetectIpStateSet = result
165+
return nil
166+
})
167+
if err != nil {
168+
return err
169+
}
170+
171+
ids := make([]string, 0, len(netDetectIpStateSet))
172+
tmpList := make([]map[string]interface{}, 0, len(netDetectIpStateSet))
173+
174+
if netDetectIpStateSet != nil {
175+
for _, netDetectIpState := range netDetectIpStateSet {
176+
netDetectIpStateMap := map[string]interface{}{}
177+
178+
if netDetectIpState.DetectDestinationIp != nil {
179+
netDetectIpStateMap["detect_destination_ip"] = netDetectIpState.DetectDestinationIp
180+
}
181+
182+
if netDetectIpState.State != nil {
183+
netDetectIpStateMap["state"] = netDetectIpState.State
184+
}
185+
186+
if netDetectIpState.Delay != nil {
187+
netDetectIpStateMap["delay"] = netDetectIpState.Delay
188+
}
189+
190+
if netDetectIpState.PacketLossRate != nil {
191+
netDetectIpStateMap["packet_loss_rate"] = netDetectIpState.PacketLossRate
192+
}
193+
194+
ids = append(ids, *netDetectIpState.DetectDestinationIp)
195+
tmpList = append(tmpList, netDetectIpStateMap)
196+
}
197+
198+
_ = d.Set("net_detect_ip_state_set", tmpList)
199+
}
200+
201+
d.SetId(helper.DataResourceIdsHash(ids))
202+
output, ok := d.GetOk("result_output_file")
203+
if ok && output.(string) != "" {
204+
if e := writeToFile(output.(string), tmpList); e != nil {
205+
return e
206+
}
207+
}
208+
return nil
209+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudNeedFixVpcNetDetectStateCheckDataSource_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: testAccVpcNetDetectStateCheckDataSource,
19+
Check: resource.ComposeTestCheckFunc(testAccCheckTencentCloudDataSourceID("data.tencentcloud_vpc_net_detect_state_check.net_detect_state_check")),
20+
},
21+
},
22+
})
23+
}
24+
25+
const testAccVpcNetDetectStateCheckDataSource = `
26+
27+
data "tencentcloud_vpc_net_detect_state_check" "net_detect_state_check" {
28+
net_detect_id = "netd-12345678"
29+
detect_destination_ip = [
30+
"10.0.0.3",
31+
"10.0.0.2"
32+
]
33+
next_hop_type = "NORMAL_CVM"
34+
next_hop_destination = "10.0.0.4"
35+
}
36+
37+
`

tencentcloud/provider.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,7 @@ Virtual Private Cloud(VPC)
858858
tencentcloud_vpc_gateway_flow_qos
859859
tencentcloud_vpc_cvm_instances
860860
tencentcloud_vpc_net_detect_states
861+
tencentcloud_vpc_net_detect_state_check
861862
tencentcloud_vpc_network_interface_limit
862863
tencentcloud_vpc_private_ip_addresses
863864
tencentcloud_vpc_product_quota
@@ -888,6 +889,7 @@ Virtual Private Cloud(VPC)
888889
Resource
889890
tencentcloud_eni
890891
tencentcloud_eni_attachment
892+
tencentcloud_eni_sg_attachment
891893
tencentcloud_vpc
892894
tencentcloud_vpc_acl
893895
tencentcloud_vpc_acl_attachment
@@ -1557,6 +1559,7 @@ func Provider() *schema.Provider {
15571559
"tencentcloud_vpc_template_limits": dataSourceTencentCloudVpcTemplateLimits(),
15581560
"tencentcloud_vpc_limits": dataSourceTencentCloudVpcLimits(),
15591561
"tencentcloud_vpc_used_ip_address": dataSourceTencentCloudVpcUsedIpAddress(),
1562+
"tencentcloud_vpc_net_detect_state_check": dataSourceTencentCloudVpcNetDetectStateCheck(),
15601563
"tencentcloud_subnet": dataSourceTencentCloudSubnet(),
15611564
"tencentcloud_route_table": dataSourceTencentCloudRouteTable(),
15621565
"tencentcloud_domains": dataSourceTencentCloudDomains(),
@@ -1977,6 +1980,8 @@ func Provider() *schema.Provider {
19771980
"tencentcloud_vpc": resourceTencentCloudVpcInstance(),
19781981
"tencentcloud_vpc_acl": resourceTencentCloudVpcACL(),
19791982
"tencentcloud_vpc_acl_attachment": resourceTencentCloudVpcAclAttachment(),
1983+
"tencentcloud_vpc_network_acl_quintuple": resourceTencentCloudVpcNetworkAclQuintuple(),
1984+
"tencentcloud_vpc_notify_routes": resourceTencentCloudVpcNotifyRoutes(),
19801985
"tencentcloud_vpc_bandwidth_package": resourceTencentCloudVpcBandwidthPackage(),
19811986
"tencentcloud_vpc_bandwidth_package_attachment": resourceTencentCloudVpcBandwidthPackageAttachment(),
19821987
"tencentcloud_vpc_traffic_package": resourceTencentCloudVpcTrafficPackage(),
@@ -2009,6 +2014,7 @@ func Provider() *schema.Provider {
20092014
"tencentcloud_eip_normal_address_return": resourceTencentCloudEipNormalAddressReturn(),
20102015
"tencentcloud_eni": resourceTencentCloudEni(),
20112016
"tencentcloud_eni_attachment": resourceTencentCloudEniAttachment(),
2017+
"tencentcloud_eni_sg_attachment": resourceTencentCloudEniSgAttachment(),
20122018
"tencentcloud_ccn": resourceTencentCloudCcn(),
20132019
"tencentcloud_ccn_attachment": resourceTencentCloudCcnAttachment(),
20142020
"tencentcloud_ccn_bandwidth_limit": resourceTencentCloudCcnBandwidthLimit(),

0 commit comments

Comments
 (0)