11/*
2- Provides a resource to create a vpc bandwidth_package_resources
2+ Provides a resource to create a vpc bandwidth_package_attachment
33
44Example Usage
55
66```hcl
7- resource "tencentcloud_vpc_bandwidth_package_resources " "bandwidth_package_resources " {
7+ resource "tencentcloud_vpc_bandwidth_package_attachment " "bandwidth_package_attachment " {
88 resource_ids = "lb-dv1ai6ma"
99 bandwidth_package_id = "bwp-atmf0p9g"
1010 network_type = "BGP"
1111 resource_type = "LoadBalance"
1212 protocol = ""
1313}
1414
15+ ```
16+ Import
17+
18+ vpc bandwidth_package_attachment can be imported using the id, e.g.
19+ ```
20+ $ terraform import tencentcloud_vpc_bandwidth_package_attachment.bandwidth_package_attachment bandwidthPackageAttachment_id
1521```
1622*/
1723package tencentcloud
@@ -28,67 +34,62 @@ import (
2834 "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
2935)
3036
31- func resourceTencentCloudVpcBandwidthPackageResources () * schema.Resource {
37+ func resourceTencentCloudVpcBandwidthPackageAttachment () * schema.Resource {
3238 return & schema.Resource {
33- Read : resourceTencentCloudVpcBandwidthPackageResourcesRead ,
34- Create : resourceTencentCloudVpcBandwidthPackageResourcesCreate ,
35- Delete : resourceTencentCloudVpcBandwidthPackageResourcesDelete ,
39+ Read : resourceTencentCloudVpcBandwidthPackageAttachmentRead ,
40+ Create : resourceTencentCloudVpcBandwidthPackageAttachmentCreate ,
41+ Delete : resourceTencentCloudVpcBandwidthPackageAttachmentDelete ,
3642 Importer : & schema.ResourceImporter {
3743 State : schema .ImportStatePassthrough ,
3844 },
3945 Schema : map [string ]* schema.Schema {
40- "resource_ids " : {
46+ "resource_id " : {
4147 Type : schema .TypeString ,
4248 Required : true ,
43- ForceNew : true ,
4449 Description : "The unique ID of the resource, currently supports EIP resources and LB resources, such as `eip-xxxx`, `lb-xxxx`." ,
4550 },
4651
4752 "bandwidth_package_id" : {
4853 Type : schema .TypeString ,
4954 Optional : true ,
50- ForceNew : true ,
5155 Description : "Bandwidth package unique ID, in the form of `bwp-xxxx`." ,
5256 },
5357
5458 "network_type" : {
5559 Type : schema .TypeString ,
5660 Optional : true ,
57- ForceNew : true ,
5861 Description : "Bandwidth packet type, currently supports `BGP` type, indicating that the internal resource is BGP IP." ,
5962 },
6063
6164 "resource_type" : {
6265 Type : schema .TypeString ,
6366 Optional : true ,
64- ForceNew : true ,
6567 Description : "Resource types, including `Address`, `LoadBalance`." ,
6668 },
6769
6870 "protocol" : {
6971 Type : schema .TypeString ,
7072 Optional : true ,
71- ForceNew : true ,
7273 Description : "Bandwidth packet protocol type. Currently `ipv4` and `ipv6` protocol types are supported." ,
7374 },
7475 },
7576 }
7677}
7778
78- func resourceTencentCloudVpcBandwidthPackageResourcesCreate (d * schema.ResourceData , meta interface {}) error {
79- defer logElapsed ("resource.tencentcloud_vpc_bandwidth_package_resources .create" )()
79+ func resourceTencentCloudVpcBandwidthPackageAttachmentCreate (d * schema.ResourceData , meta interface {}) error {
80+ defer logElapsed ("resource.tencentcloud_vpc_bandwidth_package_attachment .create" )()
8081 defer inconsistentCheck (d , meta )()
8182
8283 logId := getLogId (contextNil )
8384
8485 var (
8586 request = vpc .NewAddBandwidthPackageResourcesRequest ()
86- resourceId string
87+ response * vpc. AddBandwidthPackageResourcesResponse
8788 bandwidthPackageId string
88- resourceType string
89+ resourceId string
8990 )
9091
91- if v , ok := d .GetOk ("resource_ids " ); ok {
92+ if v , ok := d .GetOk ("resource_id " ); ok {
9293 resourceId = v .(string )
9394 request .ResourceIds = append (request .ResourceIds , helper .String (v .(string )))
9495 }
@@ -99,11 +100,12 @@ func resourceTencentCloudVpcBandwidthPackageResourcesCreate(d *schema.ResourceDa
99100 }
100101
101102 if v , ok := d .GetOk ("network_type" ); ok {
103+
102104 request .NetworkType = helper .String (v .(string ))
103105 }
104106
105107 if v , ok := d .GetOk ("resource_type" ); ok {
106- resourceType = v .( string )
108+
107109 request .ResourceType = helper .String (v .(string ))
108110 }
109111
@@ -120,87 +122,84 @@ func resourceTencentCloudVpcBandwidthPackageResourcesCreate(d *schema.ResourceDa
120122 log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " ,
121123 logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
122124 }
125+ response = result
123126 return nil
124127 })
125128
126129 if err != nil {
127- log .Printf ("[CRITAL]%s create vpc bandwidthPackageResources failed, reason:%+v" , logId , err )
130+ log .Printf ("[CRITAL]%s create vpc bandwidthPackageAttachment failed, reason:%+v" , logId , err )
128131 return err
129132 }
130133
131- d .SetId (strings . Join ([] string { bandwidthPackageId , resourceId , resourceType }, FILED_SP ) )
132- return resourceTencentCloudVpcBandwidthPackageResourcesRead (d , meta )
134+ d .SetId (bandwidthPackageId + FILED_SP + resourceId )
135+ return resourceTencentCloudVpcBandwidthPackageAttachmentRead (d , meta )
133136}
134137
135- func resourceTencentCloudVpcBandwidthPackageResourcesRead (d * schema.ResourceData , meta interface {}) error {
136- defer logElapsed ("resource.tencentcloud_vpc_bandwidth_package_resources .read" )()
138+ func resourceTencentCloudVpcBandwidthPackageAttachmentRead (d * schema.ResourceData , meta interface {}) error {
139+ defer logElapsed ("resource.tencentcloud_vpc_bandwidth_package_attachment .read" )()
137140 defer inconsistentCheck (d , meta )()
138141
139142 logId := getLogId (contextNil )
140143 ctx := context .WithValue (context .TODO (), logIdKey , logId )
141144
142145 service := VpcService {client : meta .(* TencentCloudClient ).apiV3Conn }
143146
144- ids := strings .Split (d .Id (), FILED_SP )
145- if len (ids ) != 3 {
146- return fmt .Errorf ("id is broken, id is %s" , d .Id ())
147+ idSplit := strings .Split (d .Id (), FILED_SP )
148+ if len (idSplit ) != 2 {
149+ return fmt .Errorf ("id is broken,%s" , d .Id ())
147150 }
151+ bandwidthPackageId := idSplit [0 ]
152+ resourceId := idSplit [1 ]
148153
149- bandwidthPackageId := ids [0 ]
150- resourceId := ids [1 ]
151- resourceType := ids [2 ]
152-
153- bandwidthPackageResources , err := service .DescribeVpcBandwidthPackageResources (ctx , bandwidthPackageId , resourceId , resourceType )
154+ bandwidthPackageAttachment , err := service .DescribeVpcBandwidthPackageAttachment (ctx , bandwidthPackageId , resourceId )
154155
155156 if err != nil {
156157 return err
157158 }
158159
159- if bandwidthPackageResources == nil {
160+ if bandwidthPackageAttachment == nil {
160161 d .SetId ("" )
161- return fmt .Errorf ("resource `bandwidthPackageResources ` %s does not exist" , resourceId )
162+ return fmt .Errorf ("resource `bandwidthPackageAttachment ` %s does not exist" , bandwidthPackageId )
162163 }
163164
164165 _ = d .Set ("bandwidth_package_id" , bandwidthPackageId )
165166
166- if bandwidthPackageResources .ResourceId != nil {
167- _ = d .Set ("resource_ids " , bandwidthPackageResources .ResourceId )
167+ if bandwidthPackageAttachment .ResourceId != nil {
168+ _ = d .Set ("resource_id " , bandwidthPackageAttachment .ResourceId )
168169 }
169170
170- //if bandwidthPackageResources .NetworkType != nil {
171- // _ = d.Set("network_type", bandwidthPackageResources .NetworkType)
171+ //if bandwidthPackageAttachment .NetworkType != nil {
172+ // _ = d.Set("network_type", bandwidthPackageAttachment .NetworkType)
172173 //}
173174
174- if bandwidthPackageResources .ResourceType != nil {
175- _ = d .Set ("resource_type" , bandwidthPackageResources .ResourceType )
175+ if bandwidthPackageAttachment .ResourceType != nil {
176+ _ = d .Set ("resource_type" , bandwidthPackageAttachment .ResourceType )
176177 }
177178
178- //if bandwidthPackageResources .Protocol != nil {
179- // _ = d.Set("protocol", bandwidthPackageResources .Protocol)
179+ //if bandwidthPackageAttachment .Protocol != nil {
180+ // _ = d.Set("protocol", bandwidthPackageAttachment .Protocol)
180181 //}
181182
182183 return nil
183184}
184185
185- func resourceTencentCloudVpcBandwidthPackageResourcesDelete (d * schema.ResourceData , meta interface {}) error {
186- defer logElapsed ("resource.tencentcloud_vpc_bandwidth_package_resources .delete" )()
186+ func resourceTencentCloudVpcBandwidthPackageAttachmentDelete (d * schema.ResourceData , meta interface {}) error {
187+ defer logElapsed ("resource.tencentcloud_vpc_bandwidth_package_attachment .delete" )()
187188 defer inconsistentCheck (d , meta )()
188189
189190 logId := getLogId (contextNil )
190191 ctx := context .WithValue (context .TODO (), logIdKey , logId )
191192
192193 service := VpcService {client : meta .(* TencentCloudClient ).apiV3Conn }
193194
194- ids := strings .Split (d .Id (), FILED_SP )
195- if len (ids ) != 3 {
196- return fmt .Errorf ("id is broken, id is %s" , d .Id ())
195+ idSplit := strings .Split (d .Id (), FILED_SP )
196+ if len (idSplit ) != 2 {
197+ return fmt .Errorf ("id is broken,%s" , d .Id ())
197198 }
199+ bandwidthPackageId := idSplit [0 ]
200+ resourceId := idSplit [1 ]
198201
199- bandwidthPackageId := ids [0 ]
200- resourceId := ids [1 ]
201- resourceType := ids [2 ]
202-
203- if err := service .DeleteVpcBandwidthPackageResourcesById (ctx , bandwidthPackageId , resourceId , resourceType ); err != nil {
202+ if err := service .DeleteVpcBandwidthPackageAttachmentById (ctx , bandwidthPackageId , resourceId ); err != nil {
204203 return err
205204 }
206205
0 commit comments