Skip to content

Commit 0b4765b

Browse files
authored
fix(vpc): [138633841] tencentcloud_eni_ipv4_address Add deletion operation waiting (#3303)
* add * add * add
1 parent 6d4c935 commit 0b4765b

File tree

4 files changed

+147
-20
lines changed

4 files changed

+147
-20
lines changed

.changelog/3303.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_eni_ipv4_address: Add deletion operation waiting
3+
```
Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,72 @@
1-
Provides a resource to create a vpc eni_ipv4_address
1+
Provides a resource to create a vpc eni ipv4 address
22

33
Example Usage
44

55
```hcl
6-
data "tencentcloud_enis" "eni" {
7-
name = "Primary ENI"
6+
resource "tencentcloud_vpc" "vpc" {
7+
name = "vpc-example"
8+
cidr_block = "10.0.0.0/16"
89
}
910
10-
resource "tencentcloud_eni_ipv4_address" "eni_ipv4_address" {
11-
network_interface_id = data.tencentcloud_enis.eni.enis.0.id
11+
resource "tencentcloud_subnet" "subnet" {
12+
availability_zone = "ap-guangzhou-6"
13+
name = "subnet-example"
14+
vpc_id = tencentcloud_vpc.vpc.id
15+
cidr_block = "10.0.0.0/16"
16+
is_multicast = false
17+
}
18+
19+
resource "tencentcloud_security_group" "example" {
20+
name = "tf-example"
21+
description = "sg desc."
22+
project_id = 0
23+
24+
tags = {
25+
createBy = "Terraform"
26+
}
27+
}
28+
29+
resource "tencentcloud_eni" "example" {
30+
name = "tf-example"
31+
vpc_id = tencentcloud_vpc.vpc.id
32+
subnet_id = tencentcloud_subnet.subnet.id
33+
description = "eni desc."
34+
ipv4_count = 1
35+
security_groups = [
36+
tencentcloud_security_group.example.id,
37+
]
38+
}
39+
40+
resource "tencentcloud_eni_ipv4_address" "example" {
41+
network_interface_id = tencentcloud_eni.example.id
42+
qos_level = "DEFAULT"
1243
secondary_private_ip_address_count = 3
1344
}
1445
```
1546

47+
Or
48+
49+
```hcl
50+
resource "tencentcloud_eni_ipv4_address" "example" {
51+
network_interface_id = tencentcloud_eni.example.id
52+
private_ip_addresses {
53+
is_wan_ip_blocked = false
54+
private_ip_address = "10.0.0.15"
55+
qos_level = "DEFAULT"
56+
}
57+
58+
private_ip_addresses {
59+
is_wan_ip_blocked = false
60+
private_ip_address = "10.0.0.4"
61+
qos_level = "DEFAULT"
62+
}
63+
}
64+
```
65+
1666
Import
1767

18-
vpc eni_ipv4_address can be imported using the id, e.g.
68+
vpc eni ipv4 address can be imported using the id, e.g.
1969

2070
```
21-
terraform import tencentcloud_eni_ipv4_address.eni_ipv4_address eni_id
71+
terraform import tencentcloud_eni_ipv4_address.example eni-65369ozn
2272
```

tencentcloud/services/vpc/service_tencentcloud_vpc.go

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7099,6 +7099,7 @@ func (me *VpcService) DeleteEniIpv4AddressById(ctx context.Context, networkInter
70997099
logId := tccommon.GetLogId(ctx)
71007100

71017101
request := vpc.NewUnassignPrivateIpAddressesRequest()
7102+
response := vpc.NewUnassignPrivateIpAddressesResponse()
71027103
request.NetworkInterfaceId = &networkInterfaceId
71037104

71047105
for _, ipv4Address := range ipv4Addresses {
@@ -7113,14 +7114,37 @@ func (me *VpcService) DeleteEniIpv4AddressById(ctx context.Context, networkInter
71137114
}
71147115
}()
71157116

7116-
ratelimit.Check(request.GetAction())
7117+
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
7118+
ratelimit.Check(request.GetAction())
7119+
result, e := me.client.UseVpcClient().UnassignPrivateIpAddresses(request)
7120+
if e != nil {
7121+
return tccommon.RetryError(e)
7122+
} else {
7123+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
7124+
}
7125+
7126+
if result == nil || result.Response == nil {
7127+
return resource.NonRetryableError(fmt.Errorf("Delete vpc eniIpv4Address failed, Response is nil."))
7128+
}
7129+
7130+
response = result
7131+
return nil
7132+
})
71177133

7118-
response, err := me.client.UseVpcClient().UnassignPrivateIpAddresses(request)
71197134
if err != nil {
7120-
errRet = err
7121-
return
7135+
log.Printf("[CRITAL]%s delete vpc eniIpv4Address failed, reason:%+v", logId, err)
7136+
return err
7137+
}
7138+
7139+
// wait
7140+
if response.Response.RequestId != nil {
7141+
err = me.DescribeVpcTaskResult(ctx, response.Response.RequestId)
7142+
if err != nil {
7143+
return err
7144+
}
7145+
} else {
7146+
time.Sleep(15 * time.Second)
71227147
}
7123-
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
71247148

71257149
return
71267150
}

website/docs/r/eni_ipv4_address.html.markdown

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,76 @@ layout: "tencentcloud"
44
page_title: "TencentCloud: tencentcloud_eni_ipv4_address"
55
sidebar_current: "docs-tencentcloud-resource-eni_ipv4_address"
66
description: |-
7-
Provides a resource to create a vpc eni_ipv4_address
7+
Provides a resource to create a vpc eni ipv4 address
88
---
99

1010
# tencentcloud_eni_ipv4_address
1111

12-
Provides a resource to create a vpc eni_ipv4_address
12+
Provides a resource to create a vpc eni ipv4 address
1313

1414
## Example Usage
1515

1616
```hcl
17-
data "tencentcloud_enis" "eni" {
18-
name = "Primary ENI"
17+
resource "tencentcloud_vpc" "vpc" {
18+
name = "vpc-example"
19+
cidr_block = "10.0.0.0/16"
1920
}
2021
21-
resource "tencentcloud_eni_ipv4_address" "eni_ipv4_address" {
22-
network_interface_id = data.tencentcloud_enis.eni.enis.0.id
22+
resource "tencentcloud_subnet" "subnet" {
23+
availability_zone = "ap-guangzhou-6"
24+
name = "subnet-example"
25+
vpc_id = tencentcloud_vpc.vpc.id
26+
cidr_block = "10.0.0.0/16"
27+
is_multicast = false
28+
}
29+
30+
resource "tencentcloud_security_group" "example" {
31+
name = "tf-example"
32+
description = "sg desc."
33+
project_id = 0
34+
35+
tags = {
36+
createBy = "Terraform"
37+
}
38+
}
39+
40+
resource "tencentcloud_eni" "example" {
41+
name = "tf-example"
42+
vpc_id = tencentcloud_vpc.vpc.id
43+
subnet_id = tencentcloud_subnet.subnet.id
44+
description = "eni desc."
45+
ipv4_count = 1
46+
security_groups = [
47+
tencentcloud_security_group.example.id,
48+
]
49+
}
50+
51+
resource "tencentcloud_eni_ipv4_address" "example" {
52+
network_interface_id = tencentcloud_eni.example.id
53+
qos_level = "DEFAULT"
2354
secondary_private_ip_address_count = 3
2455
}
2556
```
2657

58+
### Or
59+
60+
```hcl
61+
resource "tencentcloud_eni_ipv4_address" "example" {
62+
network_interface_id = tencentcloud_eni.example.id
63+
private_ip_addresses {
64+
is_wan_ip_blocked = false
65+
private_ip_address = "10.0.0.15"
66+
qos_level = "DEFAULT"
67+
}
68+
69+
private_ip_addresses {
70+
is_wan_ip_blocked = false
71+
private_ip_address = "10.0.0.4"
72+
qos_level = "DEFAULT"
73+
}
74+
}
75+
```
76+
2777
## Argument Reference
2878

2979
The following arguments are supported:
@@ -54,9 +104,9 @@ In addition to all arguments above, the following attributes are exported:
54104

55105
## Import
56106

57-
vpc eni_ipv4_address can be imported using the id, e.g.
107+
vpc eni ipv4 address can be imported using the id, e.g.
58108

59109
```
60-
terraform import tencentcloud_eni_ipv4_address.eni_ipv4_address eni_id
110+
terraform import tencentcloud_eni_ipv4_address.example eni-65369ozn
61111
```
62112

0 commit comments

Comments
 (0)