Skip to content

Commit

Permalink
fix(vpc): [119015747] tencentcloud_nat_gateway add `stock_public_ip…
Browse files Browse the repository at this point in the history
…_addresses_bandwidth_out` params (#2955)

* add

* add
  • Loading branch information
SevenEarth authored Nov 15, 2024
1 parent 217e75d commit 5bb2375
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/2955.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_nat_gateway: add `stock_public_ip_addresses_bandwidth_out` fields
```
45 changes: 45 additions & 0 deletions tencentcloud/services/vpc/resource_tc_nat_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"

"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
Expand Down Expand Up @@ -86,6 +87,13 @@ func ResourceTencentCloudNatGateway() *schema.Resource {
ValidateFunc: tccommon.ValidateAllowedIntValue([]int{1, 2}),
Description: "1: traditional NAT, 2: standard NAT, default value is 1.",
},
"stock_public_ip_addresses_bandwidth_out": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
Description: "The elastic public IP bandwidth value (unit: Mbps) for binding NAT gateway. When this parameter is not filled in, it defaults to the bandwidth value of the elastic public IP, and for some users, it defaults to the bandwidth limit of the elastic public IP of that user type.",
},
"tags": {
Type: schema.TypeMap,
Optional: true,
Expand Down Expand Up @@ -163,6 +171,10 @@ func resourceTencentCloudNatGatewayCreate(d *schema.ResourceData, meta interface
request.SubnetId = helper.String(v.(string))
}

if v, ok := d.GetOkExists("stock_public_ip_addresses_bandwidth_out"); ok {
request.StockPublicIpAddressesBandwidthOut = helper.IntUint64(v.(int))
}

if v := helper.GetTags(d, "tags"); len(v) > 0 {
for tagKey, tagValue := range v {
tag := vpc.Tag{
Expand Down Expand Up @@ -292,6 +304,39 @@ func resourceTencentCloudNatGatewayRead(d *schema.ResourceData, meta interface{}
_ = d.Set("nat_product_version", *nat.NatProductVersion)
}

// set `stock_public_ip_addresses_bandwidth_out`
bandwidthRequest := vpc.NewDescribeAddressesRequest()
bandwidthResponse := vpc.NewDescribeAddressesResponse()
bandwidthRequest.Filters = []*vpc.Filter{
{
Name: common.StringPtr("address-ip"),
Values: flattenAddressList((*nat).PublicIpAddressSet),
},
}

err = resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseVpcClient(iacExtInfo).DescribeAddresses(bandwidthRequest)
if e != nil {
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
logId, bandwidthRequest.GetAction(), bandwidthRequest.ToJsonString(), e.Error())
return tccommon.RetryError(e)
}
bandwidthResponse = result
return nil
})

if err != nil {
log.Printf("[CRITAL]%s read NAT gateway addresses failed, reason:%s\n", logId, err.Error())
return err
}

if bandwidthResponse != nil && len(bandwidthResponse.Response.AddressSet) > 0 {
address := bandwidthResponse.Response.AddressSet[0]
if address.Bandwidth != nil {
_ = d.Set("stock_public_ip_addresses_bandwidth_out", address.Bandwidth)
}
}

tcClient := meta.(tccommon.ProviderMeta).GetAPIV3Conn()
tagService := svctag.NewTagService(tcClient)
tags, err := tagService.DescribeResourceTags(ctx, "vpc", "nat", tcClient.Region, d.Id())
Expand Down
33 changes: 33 additions & 0 deletions tencentcloud/services/vpc/resource_tc_nat_gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ Provides a resource to create a NAT gateway.

~> **NOTE:** If `nat_product_version` is `1`, `max_concurrent` valid values is `1000000`, `3000000`, `10000000`.

~> **NOTE:** If set `stock_public_ip_addresses_bandwidth_out`, do not set the `internet_max_bandwidth_out` parameter of resource `tencentcloud_eip` at the same time, otherwise conflicts may occur.

Example Usage

Create a traditional NAT gateway.
Expand Down Expand Up @@ -66,6 +68,37 @@ resource "tencentcloud_nat_gateway" "example" {
}
```

Or set stock public ip addresses bandwidth out

```hcl
resource "tencentcloud_vpc" "vpc" {
cidr_block = "10.0.0.0/16"
name = "tf_nat_gateway_vpc"
}
resource "tencentcloud_eip" "eip_example1" {
name = "tf_nat_gateway_eip1"
}
resource "tencentcloud_eip" "eip_example2" {
name = "tf_nat_gateway_eip2"
}
resource "tencentcloud_nat_gateway" "example" {
name = "tf_example_nat_gateway"
vpc_id = tencentcloud_vpc.vpc.id
nat_product_version = 2
stock_public_ip_addresses_bandwidth_out = 100
assigned_eip_set = [
tencentcloud_eip.eip_example1.public_ip,
tencentcloud_eip.eip_example2.public_ip,
]
tags = {
createBy = "terraform"
}
}
```

Import

NAT gateway can be imported using the id, e.g.
Expand Down
34 changes: 34 additions & 0 deletions website/docs/r/nat_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Provides a resource to create a NAT gateway.

~> **NOTE:** If `nat_product_version` is `1`, `max_concurrent` valid values is `1000000`, `3000000`, `10000000`.

~> **NOTE:** If set `stock_public_ip_addresses_bandwidth_out`, do not set the `internet_max_bandwidth_out` parameter of resource `tencentcloud_eip` at the same time, otherwise conflicts may occur.

## Example Usage

### Create a traditional NAT gateway.
Expand Down Expand Up @@ -77,6 +79,37 @@ resource "tencentcloud_nat_gateway" "example" {
}
```

### Or set stock public ip addresses bandwidth out

```hcl
resource "tencentcloud_vpc" "vpc" {
cidr_block = "10.0.0.0/16"
name = "tf_nat_gateway_vpc"
}
resource "tencentcloud_eip" "eip_example1" {
name = "tf_nat_gateway_eip1"
}
resource "tencentcloud_eip" "eip_example2" {
name = "tf_nat_gateway_eip2"
}
resource "tencentcloud_nat_gateway" "example" {
name = "tf_example_nat_gateway"
vpc_id = tencentcloud_vpc.vpc.id
nat_product_version = 2
stock_public_ip_addresses_bandwidth_out = 100
assigned_eip_set = [
tencentcloud_eip.eip_example1.public_ip,
tencentcloud_eip.eip_example2.public_ip,
]
tags = {
createBy = "terraform"
}
}
```

## Argument Reference

The following arguments are supported:
Expand All @@ -87,6 +120,7 @@ The following arguments are supported:
* `bandwidth` - (Optional, Int) The maximum public network output bandwidth of NAT gateway (unit: Mbps). Valid values: `20`, `50`, `100`, `200`, `500`, `1000`, `2000`, `5000`. Default is `100`. When the value of parameter `nat_product_version` is 2, which is the standard NAT type, this parameter does not need to be filled in and defaults to `5000`.
* `max_concurrent` - (Optional, Int) The upper limit of concurrent connection of NAT gateway. Valid values: `1000000`, `3000000`, `10000000`. Default is `1000000`. When the value of parameter `nat_product_version` is 2, which is the standard NAT type, this parameter does not need to be filled in and defaults to `2000000`.
* `nat_product_version` - (Optional, Int, ForceNew) 1: traditional NAT, 2: standard NAT, default value is 1.
* `stock_public_ip_addresses_bandwidth_out` - (Optional, Int, ForceNew) The elastic public IP bandwidth value (unit: Mbps) for binding NAT gateway. When this parameter is not filled in, it defaults to the bandwidth value of the elastic public IP, and for some users, it defaults to the bandwidth limit of the elastic public IP of that user type.
* `subnet_id` - (Optional, String, ForceNew) Subnet of NAT.
* `tags` - (Optional, Map) The available tags within this NAT gateway.
* `zone` - (Optional, String) The availability zone, such as `ap-guangzhou-3`.
Expand Down

0 comments on commit 5bb2375

Please sign in to comment.