Skip to content

fix(vpc): [138633841] tencentcloud_eni_ipv4_address Add deletion operation waiting #3303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3303.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_eni_ipv4_address: Add deletion operation waiting
```
64 changes: 57 additions & 7 deletions tencentcloud/services/vpc/resource_tc_eni_ipv4_address.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,72 @@
Provides a resource to create a vpc eni_ipv4_address
Provides a resource to create a vpc eni ipv4 address

Example Usage

```hcl
data "tencentcloud_enis" "eni" {
name = "Primary ENI"
resource "tencentcloud_vpc" "vpc" {
name = "vpc-example"
cidr_block = "10.0.0.0/16"
}

resource "tencentcloud_eni_ipv4_address" "eni_ipv4_address" {
network_interface_id = data.tencentcloud_enis.eni.enis.0.id
resource "tencentcloud_subnet" "subnet" {
availability_zone = "ap-guangzhou-6"
name = "subnet-example"
vpc_id = tencentcloud_vpc.vpc.id
cidr_block = "10.0.0.0/16"
is_multicast = false
}

resource "tencentcloud_security_group" "example" {
name = "tf-example"
description = "sg desc."
project_id = 0

tags = {
createBy = "Terraform"
}
}

resource "tencentcloud_eni" "example" {
name = "tf-example"
vpc_id = tencentcloud_vpc.vpc.id
subnet_id = tencentcloud_subnet.subnet.id
description = "eni desc."
ipv4_count = 1
security_groups = [
tencentcloud_security_group.example.id,
]
}

resource "tencentcloud_eni_ipv4_address" "example" {
network_interface_id = tencentcloud_eni.example.id
qos_level = "DEFAULT"
secondary_private_ip_address_count = 3
}
```

Or

```hcl
resource "tencentcloud_eni_ipv4_address" "example" {
network_interface_id = tencentcloud_eni.example.id
private_ip_addresses {
is_wan_ip_blocked = false
private_ip_address = "10.0.0.15"
qos_level = "DEFAULT"
}

private_ip_addresses {
is_wan_ip_blocked = false
private_ip_address = "10.0.0.4"
qos_level = "DEFAULT"
}
}
```

Import

vpc eni_ipv4_address can be imported using the id, e.g.
vpc eni ipv4 address can be imported using the id, e.g.

```
terraform import tencentcloud_eni_ipv4_address.eni_ipv4_address eni_id
terraform import tencentcloud_eni_ipv4_address.example eni-65369ozn
```
34 changes: 29 additions & 5 deletions tencentcloud/services/vpc/service_tencentcloud_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7082,6 +7082,7 @@ func (me *VpcService) DeleteEniIpv4AddressById(ctx context.Context, networkInter
logId := tccommon.GetLogId(ctx)

request := vpc.NewUnassignPrivateIpAddressesRequest()
response := vpc.NewUnassignPrivateIpAddressesResponse()
request.NetworkInterfaceId = &networkInterfaceId

for _, ipv4Address := range ipv4Addresses {
Expand All @@ -7096,14 +7097,37 @@ func (me *VpcService) DeleteEniIpv4AddressById(ctx context.Context, networkInter
}
}()

ratelimit.Check(request.GetAction())
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
ratelimit.Check(request.GetAction())
result, e := me.client.UseVpcClient().UnassignPrivateIpAddresses(request)
if e != nil {
return tccommon.RetryError(e)
} else {
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
}

if result == nil || result.Response == nil {
return resource.NonRetryableError(fmt.Errorf("Delete vpc eniIpv4Address failed, Response is nil."))
}

response = result
return nil
})

response, err := me.client.UseVpcClient().UnassignPrivateIpAddresses(request)
if err != nil {
errRet = err
return
log.Printf("[CRITAL]%s delete vpc eniIpv4Address failed, reason:%+v", logId, err)
return err
}

// wait
if response.Response.RequestId != nil {
err = me.DescribeVpcTaskResult(ctx, response.Response.RequestId)
if err != nil {
return err
}
} else {
time.Sleep(15 * time.Second)
}
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())

return
}
Expand Down
66 changes: 58 additions & 8 deletions website/docs/r/eni_ipv4_address.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,76 @@ layout: "tencentcloud"
page_title: "TencentCloud: tencentcloud_eni_ipv4_address"
sidebar_current: "docs-tencentcloud-resource-eni_ipv4_address"
description: |-
Provides a resource to create a vpc eni_ipv4_address
Provides a resource to create a vpc eni ipv4 address
---

# tencentcloud_eni_ipv4_address

Provides a resource to create a vpc eni_ipv4_address
Provides a resource to create a vpc eni ipv4 address

## Example Usage

```hcl
data "tencentcloud_enis" "eni" {
name = "Primary ENI"
resource "tencentcloud_vpc" "vpc" {
name = "vpc-example"
cidr_block = "10.0.0.0/16"
}

resource "tencentcloud_eni_ipv4_address" "eni_ipv4_address" {
network_interface_id = data.tencentcloud_enis.eni.enis.0.id
resource "tencentcloud_subnet" "subnet" {
availability_zone = "ap-guangzhou-6"
name = "subnet-example"
vpc_id = tencentcloud_vpc.vpc.id
cidr_block = "10.0.0.0/16"
is_multicast = false
}

resource "tencentcloud_security_group" "example" {
name = "tf-example"
description = "sg desc."
project_id = 0

tags = {
createBy = "Terraform"
}
}

resource "tencentcloud_eni" "example" {
name = "tf-example"
vpc_id = tencentcloud_vpc.vpc.id
subnet_id = tencentcloud_subnet.subnet.id
description = "eni desc."
ipv4_count = 1
security_groups = [
tencentcloud_security_group.example.id,
]
}

resource "tencentcloud_eni_ipv4_address" "example" {
network_interface_id = tencentcloud_eni.example.id
qos_level = "DEFAULT"
secondary_private_ip_address_count = 3
}
```

### Or

```hcl
resource "tencentcloud_eni_ipv4_address" "example" {
network_interface_id = tencentcloud_eni.example.id
private_ip_addresses {
is_wan_ip_blocked = false
private_ip_address = "10.0.0.15"
qos_level = "DEFAULT"
}

private_ip_addresses {
is_wan_ip_blocked = false
private_ip_address = "10.0.0.4"
qos_level = "DEFAULT"
}
}
```

## Argument Reference

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

## Import

vpc eni_ipv4_address can be imported using the id, e.g.
vpc eni ipv4 address can be imported using the id, e.g.

```
terraform import tencentcloud_eni_ipv4_address.eni_ipv4_address eni_id
terraform import tencentcloud_eni_ipv4_address.example eni-65369ozn
```

Loading