Skip to content

Commit d99ded8

Browse files
authored
Feat/ccn routes set (#1653)
* set ccn routes * add ccn routes * add changelog * update * fix import * add accept and reset * add accept and reset * add accept and reset * add changelog
1 parent 1f1ee59 commit d99ded8

13 files changed

+775
-7
lines changed

.changelog/1653.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
```release-note:new-resource
2+
tencentcloud_ccn_routes
3+
```
4+
5+
```release-note:new-resource
6+
tencentcloud_ccn_instances_accept_attach
7+
```
8+
9+
```release-note:new-resource
10+
tencentcloud_ccn_instances_reset_attach
11+
```

tencentcloud/provider.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ Cloud Connect Network(CCN)
213213
tencentcloud_ccn
214214
tencentcloud_ccn_attachment
215215
tencentcloud_ccn_bandwidth_limit
216+
tencentcloud_ccn_routes
217+
tencentcloud_ccn_instances_accept_attach
218+
tencentcloud_ccn_instances_reset_attach
216219
217220
CVM Dedicated Host(CDH)
218221
Data Source
@@ -1414,6 +1417,9 @@ func Provider() terraform.ResourceProvider {
14141417
"tencentcloud_ccn": resourceTencentCloudCcn(),
14151418
"tencentcloud_ccn_attachment": resourceTencentCloudCcnAttachment(),
14161419
"tencentcloud_ccn_bandwidth_limit": resourceTencentCloudCcnBandwidthLimit(),
1420+
"tencentcloud_ccn_routes": resourceTencentCloudCcnRoutes(),
1421+
"tencentcloud_ccn_instances_accept_attach": resourceTencentCloudCcnInstancesAcceptAttach(),
1422+
"tencentcloud_ccn_instances_reset_attach": resourceTencentCloudCcnInstancesResetAttach(),
14171423
"tencentcloud_dcx": resourceTencentCloudDcxInstance(),
14181424
"tencentcloud_dc_gateway": resourceTencentCloudDcGatewayInstance(),
14191425
"tencentcloud_dc_gateway_ccn_route": resourceTencentCloudDcGatewayCcnRouteInstance(),
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*
2+
Provides a resource to create a vpc ccn_instances_accept_attach, you can use this resource to approve cross-region attachment.
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "tencentcloud_ccn_instances_accept_attach" "ccn_instances_accept_attach" {
8+
ccn_id = "ccn-39lqkygf"
9+
instances {
10+
instance_id = "vpc-j9yhbzpn"
11+
instance_region = "ap-guangzhou"
12+
instance_type = "VPC"
13+
}
14+
}
15+
```
16+
*/
17+
package tencentcloud
18+
19+
import (
20+
"fmt"
21+
"log"
22+
23+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
24+
"github.com/hashicorp/terraform-plugin-sdk/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 resourceTencentCloudCcnInstancesAcceptAttach() *schema.Resource {
30+
return &schema.Resource{
31+
Create: resourceTencentCloudCcnInstancesAcceptAttachCreate,
32+
Read: resourceTencentCloudCcnInstancesAcceptAttachRead,
33+
Delete: resourceTencentCloudCcnInstancesAcceptAttachDelete,
34+
Importer: &schema.ResourceImporter{
35+
State: schema.ImportStatePassthrough,
36+
},
37+
Schema: map[string]*schema.Schema{
38+
"ccn_id": {
39+
Required: true,
40+
ForceNew: true,
41+
Type: schema.TypeString,
42+
Description: "CCN Instance ID.",
43+
},
44+
45+
"instances": {
46+
Required: true,
47+
ForceNew: true,
48+
Type: schema.TypeList,
49+
Description: "Accept List Of Attachment Instances.",
50+
Elem: &schema.Resource{
51+
Schema: map[string]*schema.Schema{
52+
"instance_id": {
53+
Type: schema.TypeString,
54+
Required: true,
55+
Description: "Attachment Instance ID.",
56+
},
57+
"instance_region": {
58+
Type: schema.TypeString,
59+
Required: true,
60+
Description: "Instance Region.",
61+
},
62+
"instance_type": {
63+
Type: schema.TypeString,
64+
Optional: true,
65+
Description: "InstanceType: `VPC`, `DIRECTCONNECT`, `BMVPC`, `VPNGW`.",
66+
},
67+
"description": {
68+
Type: schema.TypeString,
69+
Optional: true,
70+
Description: "Description.",
71+
},
72+
"route_table_id": {
73+
Type: schema.TypeString,
74+
Optional: true,
75+
Description: "ID of the routing table associated with the instance. Note: This field may return null, indicating that no valid value can be obtained.",
76+
},
77+
},
78+
},
79+
},
80+
},
81+
}
82+
}
83+
84+
func resourceTencentCloudCcnInstancesAcceptAttachCreate(d *schema.ResourceData, meta interface{}) error {
85+
defer logElapsed("resource.tencentcloud_ccn_instances_accept_attach.read")()
86+
defer inconsistentCheck(d, meta)()
87+
88+
logId := getLogId(contextNil)
89+
90+
var (
91+
request = vpc.NewAcceptAttachCcnInstancesRequest()
92+
ccnId string
93+
)
94+
if v, ok := d.GetOk("ccn_id"); ok {
95+
ccnId = v.(string)
96+
request.CcnId = helper.String(v.(string))
97+
}
98+
99+
if v, ok := d.GetOk("instances"); ok {
100+
for _, item := range v.([]interface{}) {
101+
dMap := item.(map[string]interface{})
102+
ccnInstance := vpc.CcnInstance{}
103+
if v, ok := dMap["instance_id"]; ok {
104+
ccnInstance.InstanceId = helper.String(v.(string))
105+
}
106+
if v, ok := dMap["instance_region"]; ok {
107+
ccnInstance.InstanceRegion = helper.String(v.(string))
108+
}
109+
if v, ok := dMap["instance_type"]; ok {
110+
ccnInstance.InstanceType = helper.String(v.(string))
111+
}
112+
if v, ok := dMap["description"]; ok {
113+
ccnInstance.Description = helper.String(v.(string))
114+
}
115+
if v, ok := dMap["route_table_id"]; ok {
116+
routeTableId := v.(string)
117+
if routeTableId != "" {
118+
ccnInstance.RouteTableId = helper.String(v.(string))
119+
}
120+
}
121+
request.Instances = append(request.Instances, &ccnInstance)
122+
}
123+
}
124+
125+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
126+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseVpcClient().AcceptAttachCcnInstances(request)
127+
if e != nil {
128+
return retryError(e)
129+
} else {
130+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
131+
}
132+
return nil
133+
})
134+
if err != nil {
135+
return fmt.Errorf("[CRITAL]%s operate vpc ccnInstancesAcceptAttach failed, reason:%+v", logId, err)
136+
}
137+
138+
d.SetId(ccnId)
139+
140+
return resourceTencentCloudCcnInstancesAcceptAttachRead(d, meta)
141+
}
142+
143+
func resourceTencentCloudCcnInstancesAcceptAttachRead(d *schema.ResourceData, meta interface{}) error {
144+
defer logElapsed("resource.tencentcloud_ccn_instances_accept_attach.read")()
145+
defer inconsistentCheck(d, meta)()
146+
147+
return nil
148+
}
149+
150+
func resourceTencentCloudCcnInstancesAcceptAttachDelete(d *schema.ResourceData, meta interface{}) error {
151+
defer logElapsed("resource.tencentcloud_ccn_instances_accept_attach.delete")()
152+
defer inconsistentCheck(d, meta)()
153+
154+
return nil
155+
}
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/*
2+
Provides a resource to create a vpc ccn_instances_reset_attach, you can use this resource to reset cross-region attachment.
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "tencentcloud_ccn_instances_reset_attach" "ccn_instances_reset_attach" {
8+
ccn_id = "ccn-39lqkygf"
9+
ccn_uin = "100022975249"
10+
instances {
11+
instance_id = "vpc-j9yhbzpn"
12+
instance_region = "ap-guangzhou"
13+
instance_type = "VPC"
14+
}
15+
}
16+
```
17+
*/
18+
package tencentcloud
19+
20+
import (
21+
"fmt"
22+
"log"
23+
24+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
25+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
26+
vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"
27+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
28+
)
29+
30+
func resourceTencentCloudCcnInstancesResetAttach() *schema.Resource {
31+
return &schema.Resource{
32+
Create: resourceTencentCloudCcnInstancesResetAttachCreate,
33+
Read: resourceTencentCloudCcnInstancesResetAttachRead,
34+
Delete: resourceTencentCloudCcnInstancesResetAttachDelete,
35+
Schema: map[string]*schema.Schema{
36+
"ccn_id": {
37+
Required: true,
38+
ForceNew: true,
39+
Type: schema.TypeString,
40+
Description: "CCN Instance ID.",
41+
},
42+
43+
"ccn_uin": {
44+
Required: true,
45+
ForceNew: true,
46+
Type: schema.TypeString,
47+
Description: "CCN Uin (root account).",
48+
},
49+
50+
"instances": {
51+
Required: true,
52+
ForceNew: true,
53+
Type: schema.TypeList,
54+
Description: "List Of Attachment Instances.",
55+
Elem: &schema.Resource{
56+
Schema: map[string]*schema.Schema{
57+
"instance_id": {
58+
Type: schema.TypeString,
59+
Required: true,
60+
Description: "Attachment Instance ID.",
61+
},
62+
"instance_region": {
63+
Type: schema.TypeString,
64+
Required: true,
65+
Description: "Instance Region.",
66+
},
67+
"instance_type": {
68+
Type: schema.TypeString,
69+
Optional: true,
70+
Description: "InstanceType: `VPC`, `DIRECTCONNECT`, `BMVPC`, `VPNGW`.",
71+
},
72+
"description": {
73+
Type: schema.TypeString,
74+
Optional: true,
75+
Description: "Description.",
76+
},
77+
"route_table_id": {
78+
Type: schema.TypeString,
79+
Optional: true,
80+
Description: "ID of the routing table associated with the instance. Note: This field may return null, indicating that no valid value can be obtained.",
81+
},
82+
},
83+
},
84+
},
85+
},
86+
}
87+
}
88+
89+
func resourceTencentCloudCcnInstancesResetAttachCreate(d *schema.ResourceData, meta interface{}) error {
90+
defer logElapsed("data_source.tencentcloud_vpc_ccn_instances_reset_attach.read")()
91+
defer inconsistentCheck(d, meta)()
92+
93+
logId := getLogId(contextNil)
94+
95+
var (
96+
request = vpc.NewResetAttachCcnInstancesRequest()
97+
ccnId string
98+
)
99+
if v, ok := d.GetOk("ccn_id"); ok {
100+
ccnId = v.(string)
101+
request.CcnId = helper.String(v.(string))
102+
}
103+
104+
if v, ok := d.GetOk("ccn_uin"); ok {
105+
request.CcnUin = helper.String(v.(string))
106+
}
107+
108+
if v, ok := d.GetOk("instances"); ok {
109+
for _, item := range v.([]interface{}) {
110+
dMap := item.(map[string]interface{})
111+
ccnInstance := vpc.CcnInstance{}
112+
if v, ok := dMap["instance_id"]; ok {
113+
ccnInstance.InstanceId = helper.String(v.(string))
114+
}
115+
if v, ok := dMap["instance_region"]; ok {
116+
ccnInstance.InstanceRegion = helper.String(v.(string))
117+
}
118+
if v, ok := dMap["instance_type"]; ok {
119+
ccnInstance.InstanceType = helper.String(v.(string))
120+
}
121+
if v, ok := dMap["description"]; ok {
122+
ccnInstance.Description = helper.String(v.(string))
123+
}
124+
if v, ok := dMap["route_table_id"]; ok {
125+
routeTableId := v.(string)
126+
if routeTableId != "" {
127+
ccnInstance.RouteTableId = helper.String(v.(string))
128+
}
129+
}
130+
request.Instances = append(request.Instances, &ccnInstance)
131+
}
132+
}
133+
134+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
135+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseVpcClient().ResetAttachCcnInstances(request)
136+
if e != nil {
137+
return retryError(e)
138+
} else {
139+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
140+
}
141+
return nil
142+
})
143+
if err != nil {
144+
return fmt.Errorf("[CRITAL]%s operate vpc ccnInstancesResetAttach failed, reason:%+v", logId, err)
145+
}
146+
147+
d.SetId(ccnId)
148+
149+
return resourceTencentCloudCcnInstancesResetAttachRead(d, meta)
150+
}
151+
152+
func resourceTencentCloudCcnInstancesResetAttachRead(d *schema.ResourceData, meta interface{}) error {
153+
defer logElapsed("resource.tencentcloud_ccn_instances_reset_attach.read")()
154+
defer inconsistentCheck(d, meta)()
155+
156+
return nil
157+
}
158+
159+
func resourceTencentCloudCcnInstancesResetAttachDelete(d *schema.ResourceData, meta interface{}) error {
160+
defer logElapsed("resource.tencentcloudccn_instances_reset_attach.delete")()
161+
defer inconsistentCheck(d, meta)()
162+
163+
return nil
164+
}

0 commit comments

Comments
 (0)