diff --git a/.changelog/2955.txt b/.changelog/2955.txt new file mode 100644 index 0000000000..11d24a8bbf --- /dev/null +++ b/.changelog/2955.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_nat_gateway: add `stock_public_ip_addresses_bandwidth_out` fields +``` \ No newline at end of file diff --git a/tencentcloud/services/vpc/resource_tc_nat_gateway.go b/tencentcloud/services/vpc/resource_tc_nat_gateway.go index 571e560bd5..9ece440665 100644 --- a/tencentcloud/services/vpc/resource_tc_nat_gateway.go +++ b/tencentcloud/services/vpc/resource_tc_nat_gateway.go @@ -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" @@ -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, @@ -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{ @@ -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()) diff --git a/tencentcloud/services/vpc/resource_tc_nat_gateway.md b/tencentcloud/services/vpc/resource_tc_nat_gateway.md index a3b81233f2..1659a570a7 100644 --- a/tencentcloud/services/vpc/resource_tc_nat_gateway.md +++ b/tencentcloud/services/vpc/resource_tc_nat_gateway.md @@ -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. @@ -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. diff --git a/website/docs/r/nat_gateway.html.markdown b/website/docs/r/nat_gateway.html.markdown index 70af26c5c2..5f8c59da10 100644 --- a/website/docs/r/nat_gateway.html.markdown +++ b/website/docs/r/nat_gateway.html.markdown @@ -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. @@ -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: @@ -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`.