Skip to content

Commit 24b5266

Browse files
committed
add
1 parent ae43289 commit 24b5266

13 files changed

+151
-53
lines changed

tencentcloud/services/ccn/data_source_tc_ccn_routes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ccn
22

33
import (
44
"context"
5+
56
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
67
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
78
vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"

tencentcloud/services/ccn/resource_tc_ccn_attachment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ func resourceTencentCloudCcnAttachmentRead(d *schema.ResourceData, meta interfac
291291
}
292292

293293
func resourceTencentCloudCcnAttachmentUpdate(d *schema.ResourceData, meta interface{}) error {
294-
defer tccommon.LogElapsed("resource.tencentcloud_ccn_attachment.create")()
294+
defer tccommon.LogElapsed("resource.tencentcloud_ccn_attachment.update")()
295295

296296
if d.HasChange("description") {
297297
var (

tencentcloud/services/ccn/resource_tc_ccn_route_table.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package ccn
33
import (
44
"context"
55
"fmt"
6+
"log"
7+
68
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
79
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
8-
"log"
910

1011
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1112
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -79,7 +80,7 @@ func resourceTencentCloudCcnRouteTableCreate(d *schema.ResourceData, meta interf
7980
}
8081

8182
request.RouteTable = []*vpc.CcnBatchRouteTable{
82-
&vpc.CcnBatchRouteTable{
83+
{
8384
CcnId: helper.String(ccnId),
8485
Name: helper.String(name),
8586
Description: helper.String(description),
@@ -183,7 +184,7 @@ func resourceTencentCloudCcnRouteTableUpdate(d *schema.ResourceData, meta interf
183184
}
184185

185186
request.RouteTableInfo = []*vpc.ModifyRouteTableInfo{
186-
&vpc.ModifyRouteTableInfo{
187+
{
187188
RouteTableId: helper.String(routeTableId),
188189
Name: helper.String(name),
189190
Description: helper.String(description),

tencentcloud/services/ccn/resource_tc_ccn_route_table_associate_instance_config.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package ccn
33
import (
44
"context"
55
"fmt"
6-
vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"
76
"log"
87
"strings"
98

9+
vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"
10+
1011
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
1112

1213
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
@@ -36,7 +37,7 @@ func ResourceTencentCloudCcnRouteTableAssociateInstanceConfig() *schema.Resource
3637
},
3738
"instances": {
3839
Required: true,
39-
Type: schema.TypeList,
40+
Type: schema.TypeSet,
4041
Description: "Instances list.",
4142
Elem: &schema.Resource{
4243
Schema: map[string]*schema.Schema{
@@ -86,7 +87,7 @@ func resourceTencentCloudCcnRouteTableAssociateInstanceConfigRead(d *schema.Reso
8687
ccnId := items[0]
8788
routeTableId := items[1]
8889

89-
instanceBindList, err := service.DescribeRouteTableAssociatedInstancesById(ctx, ccnId, routeTableId)
90+
instanceBindList, err := service.DescribeRouteTableAssociatedInstancesById(ctx, meta, ccnId, routeTableId)
9091
if err != nil {
9192
return err
9293
}
@@ -103,12 +104,12 @@ func resourceTencentCloudCcnRouteTableAssociateInstanceConfigRead(d *schema.Reso
103104
tmpList := make([]map[string]interface{}, 0, len(instanceBindList))
104105
for _, instanceBind := range instanceBindList {
105106
instanceMap := map[string]interface{}{}
106-
if instanceBind.InstanceId != nil {
107-
instanceMap["instance_id"] = *instanceBind.InstanceId
107+
if instanceBind.instanceId != "" {
108+
instanceMap["instance_id"] = instanceBind.instanceId
108109
}
109110

110-
if instanceBind.InstanceType != nil {
111-
instanceMap["instance_type"] = *instanceBind.InstanceType
111+
if instanceBind.instanceType != "" {
112+
instanceMap["instance_type"] = instanceBind.instanceType
112113
}
113114

114115
tmpList = append(tmpList, instanceMap)
@@ -139,7 +140,8 @@ func resourceTencentCloudCcnRouteTableAssociateInstanceConfigUpdate(d *schema.Re
139140
request.RouteTableId = helper.String(routeTableId)
140141

141142
if v, ok := d.GetOk("instances"); ok {
142-
for _, item := range v.([]interface{}) {
143+
tmpV := v.(*schema.Set).List()
144+
for _, item := range tmpV {
143145
instanceMap := item.(map[string]interface{})
144146
instanceInfo := vpc.CcnInstanceWithoutRegion{}
145147
if v, ok := instanceMap["instance_id"]; ok {

tencentcloud/services/ccn/resource_tc_ccn_route_table_broadcast_policies.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package ccn
33
import (
44
"context"
55
"fmt"
6+
"log"
7+
"strings"
8+
69
tchttp "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http"
710
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
811
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
9-
"log"
10-
"strings"
1112

1213
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1314
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

tencentcloud/services/ccn/resource_tc_ccn_route_table_broadcast_policies.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Provides a resource to create a CCN Route table broadcast policies.
22

3+
~> **NOTE:** Use this resource to manage all broadcast policies under the routing table of CCN instances.
4+
35
Example Usage
46

57
```hcl

tencentcloud/services/ccn/resource_tc_ccn_route_table_input_policies.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package ccn
33
import (
44
"context"
55
"fmt"
6+
"log"
7+
"strings"
8+
69
tchttp "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http"
710
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
811
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
9-
"log"
10-
"strings"
1112

1213
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1314
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

tencentcloud/services/ccn/resource_tc_ccn_route_table_input_policies.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Provides a resource to create a CCN Route table input policies.
22

3+
~> **NOTE:** Use this resource to manage all input policies under the routing table of CCN instances.
4+
35
Example Usage
46

57
```hcl

tencentcloud/services/ccn/resource_tc_ccn_route_table_selection_policies.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ package ccn
33
import (
44
"context"
55
"fmt"
6+
"log"
7+
68
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
79
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
810
vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"
911
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
1012
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
11-
"log"
1213
)
1314

1415
func ResourceTencentCloudCcnRouteTableSelectionPolicies() *schema.Resource {

tencentcloud/services/ccn/resource_tc_ccn_route_table_selection_policies.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Provides a resource to create a CCN Route table selection policies.
22

3+
~> **NOTE:** Use this resource to manage all selection policies under the routing table of CCN instances.
4+
35
Example Usage
46

57
```hcl
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
Provides a resource to create a vpc ccn_routes
1+
Provides a resource to create a vpc ccn_routes switch
22

33
Example Usage
44

55
```hcl
6-
resource "tencentcloud_ccn_routes" "ccn_routes" {
7-
ccn_id = "ccn-39lqkygf"
8-
route_id = "ccnr-3o0dfyuw"
9-
switch = "on"
6+
resource "tencentcloud_ccn_routes" "example" {
7+
ccn_id = "ccn-gr7nynbd"
8+
route_id = "ccnrtb-jpf7bzn3"
9+
switch = "off"
1010
}
1111
```
1212

@@ -15,5 +15,5 @@ Import
1515
vpc ccn_routes can be imported using the id, e.g.
1616

1717
```
18-
terraform import tencentcloud_ccn_routes.ccn_routes ccnId#routesId
19-
```
18+
terraform import tencentcloud_ccn_routes.ccn_routes ccn-gr7nynbd#ccnr-5uhewx1s
19+
```

tencentcloud/services/ccn/service_tencentcloud_ccn.go

Lines changed: 107 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ package ccn
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67
"log"
78
"strings"
89

10+
tchttp "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http"
11+
912
vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"
1013

1114
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
@@ -27,6 +30,33 @@ type CcnBasicInfo struct {
2730
createTime string
2831
}
2932

33+
type CcnInstanceBind struct {
34+
instanceId string
35+
instanceType string
36+
}
37+
38+
type CcnInstanceBindResponseData struct {
39+
InstanceBindSet []struct {
40+
AliasInstanceId string `json:"AliasInstanceId"`
41+
AliasType string `json:"AliasType"`
42+
CcnId string `json:"CcnId"`
43+
InstanceBindTime string `json:"InstanceBindTime"`
44+
InstanceId string `json:"InstanceId"`
45+
InstanceName string `json:"InstanceName"`
46+
InstanceRegion string `json:"InstanceRegion"`
47+
InstanceType string `json:"InstanceType"`
48+
InstanceUin string `json:"InstanceUin"`
49+
RouteTableId string `json:"RouteTableId"`
50+
State string `json:"State"`
51+
} `json:"InstanceBindSet"`
52+
RequestId string `json:"RequestId"`
53+
TotalCount int `json:"TotalCount"`
54+
}
55+
56+
type CcnInstanceBindApiResponse struct {
57+
Response CcnInstanceBindResponseData `json:"Response"`
58+
}
59+
3060
func (info CcnBasicInfo) CcnId() string {
3161
return info.ccnId
3262
}
@@ -1000,41 +1030,96 @@ func (me *VpcService) DescribeCcnCrossBorderComplianceByFilter(ctx context.Conte
10001030
return
10011031
}
10021032

1003-
func (me *VpcService) DescribeRouteTableAssociatedInstancesById(ctx context.Context, ccnId, routeTableId string) (instanceBindList []*vpc.InstanceBind, errRet error) {
1004-
logId := tccommon.GetLogId(ctx)
1005-
1006-
request := vpc.NewDescribeRouteTableAssociatedInstancesRequest()
1007-
request.Filters = []*vpc.Filter{
1008-
{
1009-
Name: helper.String("ccn-id"),
1010-
Values: helper.Strings([]string{ccnId}),
1011-
},
1012-
{
1013-
Name: helper.String("ccn-route-table-id"),
1014-
Values: helper.Strings([]string{routeTableId}),
1033+
func (me *VpcService) DescribeRouteTableAssociatedInstancesById(ctx context.Context, meta interface{}, ccnId, routeTableId string) (instanceBindList []CcnInstanceBind, errRet error) {
1034+
body := map[string]interface{}{
1035+
"Filters": []map[string]interface{}{
1036+
{
1037+
"Name": "ccn-id",
1038+
"Values": []string{ccnId},
1039+
},
1040+
{
1041+
"Name": "ccn-route-table-id",
1042+
"Values": []string{routeTableId},
1043+
},
10151044
},
1045+
"Offset": 0,
1046+
"Limit": 100,
10161047
}
10171048

1018-
defer func() {
1019-
if errRet != nil {
1020-
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error())
1021-
}
1022-
}()
1049+
client := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseVpcOmitNilClient()
1050+
request := tchttp.NewCommonRequest("vpc", "2017-03-12", "DescribeRouteTableAssociatedInstances")
1051+
err := request.SetActionParameters(body)
1052+
if err != nil {
1053+
errRet = err
1054+
return
1055+
}
10231056

1024-
ratelimit.Check(request.GetAction())
1025-
response, err := me.client.UseVpcClient().DescribeRouteTableAssociatedInstances(request)
1057+
response := tchttp.NewCommonResponse()
1058+
err = client.Send(request, response)
10261059
if err != nil {
1060+
fmt.Printf("describe vpc DescribeRouteTableAssociatedInstances failed: %v \n", err)
10271061
errRet = err
10281062
return
10291063
}
10301064

1031-
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
1032-
if response.Response == nil || len(response.Response.InstanceBindSet) < 1 {
1065+
resultStr := string(response.GetBody())
1066+
var ccnInstanceBindApiResponse CcnInstanceBindApiResponse
1067+
err = json.Unmarshal([]byte(resultStr), &ccnInstanceBindApiResponse)
1068+
if err != nil {
1069+
errRet = err
10331070
return
10341071
}
10351072

1036-
instanceBindList = response.Response.InstanceBindSet
1073+
InstanceBindSet := ccnInstanceBindApiResponse.Response.InstanceBindSet
1074+
for _, BindSet := range InstanceBindSet {
1075+
var tmpBind CcnInstanceBind
1076+
if BindSet.InstanceId != "" {
1077+
tmpBind.instanceId = BindSet.InstanceId
1078+
}
1079+
1080+
if BindSet.InstanceType != "" {
1081+
tmpBind.instanceType = BindSet.InstanceType
1082+
}
1083+
1084+
instanceBindList = append(instanceBindList, tmpBind)
1085+
}
1086+
10371087
return
1088+
1089+
//logId := tccommon.GetLogId(ctx)
1090+
//
1091+
//request := vpc.NewDescribeRouteTableAssociatedInstancesRequest()
1092+
//request.Filters = []*vpc.Filter{
1093+
// {
1094+
// Name: helper.String("ccn-id"),
1095+
// Values: helper.Strings([]string{ccnId}),
1096+
// },
1097+
// {
1098+
// Name: helper.String("ccn-route-table-id"),
1099+
// Values: helper.Strings([]string{routeTableId}),
1100+
// },
1101+
//}
1102+
//
1103+
//defer func() {
1104+
// if errRet != nil {
1105+
// log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error())
1106+
// }
1107+
//}()
1108+
//
1109+
//ratelimit.Check(request.GetAction())
1110+
//response, err := me.client.UseVpcClient().DescribeRouteTableAssociatedInstances(request)
1111+
//if err != nil {
1112+
// errRet = err
1113+
// return
1114+
//}
1115+
//
1116+
//log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
1117+
//if response.Response == nil || len(response.Response.InstanceBindSet) < 1 {
1118+
// return
1119+
//}
1120+
//
1121+
//instanceBindList = response.Response.InstanceBindSet
1122+
//return
10381123
}
10391124

10401125
func (me *VpcService) DescribeVpcReplaceCcnRouteTableInputPolicysById(ctx context.Context, ccnId, routeTableId string) (policySet *vpc.CcnRouteTableInputPolicys, errRet error) {

0 commit comments

Comments
 (0)