Skip to content

Commit 11c586e

Browse files
committed
attachment support import
1 parent fe809a6 commit 11c586e

14 files changed

+115
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
ENHANCEMENTS:
44

55
* Resource: `tencentcloud_vpc_acl_attachment` perfect example field `subnet_ids` to `subnet_id`([#505](https://github.com/tencentcloudstack/terraform-provider-tencentcloud/issues/505)).
6+
* Resource: `tencentcloud_cbs_storage_attachment` support import.
7+
* Resource: `tencentcloud_eip_association` support import.
8+
* Resource: `tencentcloud_route_table_entry` support import.
9+
* Resource: `tencentcloud_acl_attachment` support import.
610

711
## 1.41.2 (August 28, 2020)
812

tencentcloud/resource_tc_cbs_storage_attachment.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ resource "tencentcloud_cbs_storage_attachment" "attachment" {
99
instance_id = "ins-jqlegd42"
1010
}
1111
```
12+
13+
Import
14+
15+
CBS storage attachment can be imported using the id, e.g.
16+
17+
```
18+
$ terraform import tencentcloud_cbs_storage_attachment.attachment disk-41s6jwy4
19+
```
1220
*/
1321
package tencentcloud
1422

@@ -27,6 +35,9 @@ func resourceTencentCloudCbsStorageAttachment() *schema.Resource {
2735
Create: resourceTencentCloudCbsStorageAttachmentCreate,
2836
Read: resourceTencentCloudCbsStorageAttachmentRead,
2937
Delete: resourceTencentCloudCbsStorageAttachmentDelete,
38+
Importer: &schema.ResourceImporter{
39+
State: schema.ImportStatePassthrough,
40+
},
3041

3142
Schema: map[string]*schema.Schema{
3243
"storage_id": {

tencentcloud/resource_tc_cbs_storage_attachment_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ func TestAccTencentCloudCbsStorageAttachment(t *testing.T) {
2525
resource.TestCheckResourceAttrSet("tencentcloud_cbs_storage_attachment.foo", "instance_id"),
2626
),
2727
},
28+
{
29+
ResourceName: "tencentcloud_cbs_storage_attachment.foo",
30+
ImportState: true,
31+
ImportStateVerify: true,
32+
},
2833
},
2934
})
3035
}

tencentcloud/resource_tc_eip_association.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ resource "tencentcloud_eip_association" "bar" {
2121
private_ip = "10.0.1.22"
2222
}
2323
```
24+
25+
Import
26+
27+
Eip association can be imported using the id, e.g.
28+
29+
```
30+
$ terraform import tencentcloud_eip_association.bar eip-41s6jwy4::ins-34jwj3
31+
```
2432
*/
2533
package tencentcloud
2634

@@ -41,6 +49,9 @@ func resourceTencentCloudEipAssociation() *schema.Resource {
4149
Create: resourceTencentCloudEipAssociationCreate,
4250
Read: resourceTencentCloudEipAssociationRead,
4351
Delete: resourceTencentCloudEipAssociationDelete,
52+
Importer: &schema.ResourceImporter{
53+
State: schema.ImportStatePassthrough,
54+
},
4455

4556
Schema: map[string]*schema.Schema{
4657
"eip_id": {

tencentcloud/resource_tc_eip_association_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ func TestAccTencentCloudEipAssociationWithInstance(t *testing.T) {
2929
resource.TestCheckResourceAttr("tencentcloud_eip.foo", "status", "UNBIND"),
3030
),
3131
},
32+
{
33+
ResourceName: id,
34+
ImportState: true,
35+
ImportStateVerify: true,
36+
},
3237
},
3338
})
3439
}

tencentcloud/resource_tc_route_table_entry.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ resource "tencentcloud_route_table_entry" "instance" {
3434
description = "ci-test-route-table-entry"
3535
}
3636
```
37+
38+
Import
39+
40+
Route table entry can be imported using the id, e.g.
41+
42+
```
43+
$ terraform import tencentcloud_route_table_entry.foo 83517.rtb-mlhpg09u
44+
```
3745
*/
3846
package tencentcloud
3947

@@ -53,6 +61,9 @@ func resourceTencentCloudVpcRouteEntry() *schema.Resource {
5361
Create: resourceTencentCloudVpcRouteEntryCreate,
5462
Read: resourceTencentCloudVpcRouteEntryRead,
5563
Delete: resourceTencentCloudVpcRouteEntryDelete,
64+
Importer: &schema.ResourceImporter{
65+
State: schema.ImportStatePassthrough,
66+
},
5667

5768
Schema: map[string]*schema.Schema{
5869
"route_table_id": {

tencentcloud/resource_tc_route_table_entry_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ func TestAccTencentCloudVpcV3RouteEntryBasic(t *testing.T) {
3131
resource.TestCheckResourceAttr("tencentcloud_route_table_entry.foo", "next_hub", "0"),
3232
),
3333
},
34+
{
35+
ResourceName: "tencentcloud_route_table_entry.foo",
36+
ImportState: true,
37+
ImportStateVerify: true,
38+
},
3439
},
3540
})
3641
}

tencentcloud/resource_tc_vpc_acl_attachment.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,19 @@ resource "tencentcloud_vpc_acl_attachment" "attachment"{
2424
subnet_id = data.tencentcloud_vpc_instances.id_instances.instance_list[0].subnet_ids[0]
2525
}
2626
```
27+
28+
Import
29+
30+
Acl attachment can be imported using the id, e.g.
31+
32+
```
33+
$ terraform import tencentcloud_vpc_acl_attachment.attachment acl-eotx5qsg#subnet-91x0geu6
34+
```
2735
*/
2836
package tencentcloud
2937

3038
import (
3139
"context"
32-
"fmt"
3340
"log"
3441
"strings"
3542

@@ -96,18 +103,27 @@ func resourceTencentCloudVpcAclAttachmentRead(d *schema.ResourceData, meta inter
96103
ctx = context.WithValue(context.TODO(), logIdKey, logId)
97104
service = VpcService{client: meta.(*TencentCloudClient).apiV3Conn}
98105
attachmentId = d.Id()
99-
aclId string
100106
)
101107

102-
aclId = strings.Split(attachmentId, FILED_SP)[0]
108+
idSplit := strings.Split(attachmentId, FILED_SP)
109+
if len(idSplit) < 2 {
110+
d.SetId("")
111+
return nil
112+
}
113+
aclId := idSplit[0]
114+
subnetId := idSplit[1]
103115
results, err := service.DescribeNetWorkAcls(ctx, aclId, "", "")
104116
if err != nil {
105117
return err
106118
}
107-
if len(results) > 0 && len(results[0].SubnetSet) < 1 {
119+
if len(results) < 1 || len(results[0].SubnetSet) < 1 {
108120
d.SetId("")
109-
return fmt.Errorf("[TECENT_TERRAFORM_CHECK][ACL attachment][Read] check: ACL attachment is not exist")
121+
return nil
110122
}
123+
124+
_ = d.Set("acl_id", aclId)
125+
_ = d.Set("subnet_id", subnetId)
126+
111127
return nil
112128

113129
}

tencentcloud/resource_tc_vpc_acl_attachment_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ func TestAccTencentCloudVpcAclAttachment_basic(t *testing.T) {
2222
resource.TestCheckResourceAttrSet("tencentcloud_vpc_acl_attachment.attachment", "acl_id"),
2323
),
2424
},
25+
{
26+
ResourceName: "tencentcloud_vpc_acl_attachment.attachment",
27+
ImportState: true,
28+
ImportStateVerify: true,
29+
},
2530
},
2631
})
2732
}

tencentcloud/resource_tc_vpc_acl_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ func TestAccTencentCloudVpcAcl_basic(t *testing.T) {
2424
resource.TestCheckResourceAttr("tencentcloud_vpc_acl.foo", "egress.#", "2"),
2525
),
2626
},
27+
{
28+
ResourceName: "tencentcloud_vpc_acl.foo",
29+
ImportState: true,
30+
ImportStateVerify: true,
31+
},
2732
},
2833
})
2934
}

0 commit comments

Comments
 (0)