Skip to content

Commit 0f75167

Browse files
committed
add
1 parent 52ce1d6 commit 0f75167

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

tencentcloud/services/vpc/resource_tc_nat_gateway.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1414
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
15+
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
1516
vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"
1617

1718
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
@@ -86,6 +87,13 @@ func ResourceTencentCloudNatGateway() *schema.Resource {
8687
ValidateFunc: tccommon.ValidateAllowedIntValue([]int{1, 2}),
8788
Description: "1: traditional NAT, 2: standard NAT, default value is 1.",
8889
},
90+
"stock_public_ip_addresses_bandwidth_out": {
91+
Type: schema.TypeInt,
92+
Optional: true,
93+
Computed: true,
94+
ForceNew: true,
95+
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.",
96+
},
8997
"tags": {
9098
Type: schema.TypeMap,
9199
Optional: true,
@@ -163,6 +171,10 @@ func resourceTencentCloudNatGatewayCreate(d *schema.ResourceData, meta interface
163171
request.SubnetId = helper.String(v.(string))
164172
}
165173

174+
if v, ok := d.GetOkExists("stock_public_ip_addresses_bandwidth_out"); ok {
175+
request.StockPublicIpAddressesBandwidthOut = helper.IntUint64(v.(int))
176+
}
177+
166178
if v := helper.GetTags(d, "tags"); len(v) > 0 {
167179
for tagKey, tagValue := range v {
168180
tag := vpc.Tag{
@@ -292,6 +304,39 @@ func resourceTencentCloudNatGatewayRead(d *schema.ResourceData, meta interface{}
292304
_ = d.Set("nat_product_version", *nat.NatProductVersion)
293305
}
294306

307+
// set `stock_public_ip_addresses_bandwidth_out`
308+
bandwidthRequest := vpc.NewDescribeAddressesRequest()
309+
bandwidthResponse := vpc.NewDescribeAddressesResponse()
310+
bandwidthRequest.Filters = []*vpc.Filter{
311+
{
312+
Name: common.StringPtr("address-ip"),
313+
Values: flattenAddressList((*nat).PublicIpAddressSet),
314+
},
315+
}
316+
317+
err = resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
318+
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseVpcClient(iacExtInfo).DescribeAddresses(bandwidthRequest)
319+
if e != nil {
320+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
321+
logId, bandwidthRequest.GetAction(), bandwidthRequest.ToJsonString(), e.Error())
322+
return tccommon.RetryError(e)
323+
}
324+
bandwidthResponse = result
325+
return nil
326+
})
327+
328+
if err != nil {
329+
log.Printf("[CRITAL]%s read NAT gateway addresses failed, reason:%s\n", logId, err.Error())
330+
return err
331+
}
332+
333+
if bandwidthResponse != nil && len(bandwidthResponse.Response.AddressSet) > 0 {
334+
address := bandwidthResponse.Response.AddressSet[0]
335+
if address.Bandwidth != nil {
336+
_ = d.Set("stock_public_ip_addresses_bandwidth_out", address.Bandwidth)
337+
}
338+
}
339+
295340
tcClient := meta.(tccommon.ProviderMeta).GetAPIV3Conn()
296341
tagService := svctag.NewTagService(tcClient)
297342
tags, err := tagService.DescribeResourceTags(ctx, "vpc", "nat", tcClient.Region, d.Id())

tencentcloud/services/vpc/resource_tc_nat_gateway.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ Provides a resource to create a NAT gateway.
22

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

5+
~> **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.
6+
57
Example Usage
68

79
Create a traditional NAT gateway.
@@ -66,6 +68,37 @@ resource "tencentcloud_nat_gateway" "example" {
6668
}
6769
```
6870

71+
Or set stock public ip addresses bandwidth out
72+
73+
```hcl
74+
resource "tencentcloud_vpc" "vpc" {
75+
cidr_block = "10.0.0.0/16"
76+
name = "tf_nat_gateway_vpc"
77+
}
78+
79+
resource "tencentcloud_eip" "eip_example1" {
80+
name = "tf_nat_gateway_eip1"
81+
}
82+
83+
resource "tencentcloud_eip" "eip_example2" {
84+
name = "tf_nat_gateway_eip2"
85+
}
86+
87+
resource "tencentcloud_nat_gateway" "example" {
88+
name = "tf_example_nat_gateway"
89+
vpc_id = tencentcloud_vpc.vpc.id
90+
nat_product_version = 2
91+
stock_public_ip_addresses_bandwidth_out = 100
92+
assigned_eip_set = [
93+
tencentcloud_eip.eip_example1.public_ip,
94+
tencentcloud_eip.eip_example2.public_ip,
95+
]
96+
tags = {
97+
createBy = "terraform"
98+
}
99+
}
100+
```
101+
69102
Import
70103

71104
NAT gateway can be imported using the id, e.g.

website/docs/r/nat_gateway.html.markdown

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Provides a resource to create a NAT gateway.
1313

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

16+
~> **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.
17+
1618
## Example Usage
1719

1820
### Create a traditional NAT gateway.
@@ -77,6 +79,37 @@ resource "tencentcloud_nat_gateway" "example" {
7779
}
7880
```
7981

82+
### Or set stock public ip addresses bandwidth out
83+
84+
```hcl
85+
resource "tencentcloud_vpc" "vpc" {
86+
cidr_block = "10.0.0.0/16"
87+
name = "tf_nat_gateway_vpc"
88+
}
89+
90+
resource "tencentcloud_eip" "eip_example1" {
91+
name = "tf_nat_gateway_eip1"
92+
}
93+
94+
resource "tencentcloud_eip" "eip_example2" {
95+
name = "tf_nat_gateway_eip2"
96+
}
97+
98+
resource "tencentcloud_nat_gateway" "example" {
99+
name = "tf_example_nat_gateway"
100+
vpc_id = tencentcloud_vpc.vpc.id
101+
nat_product_version = 2
102+
stock_public_ip_addresses_bandwidth_out = 100
103+
assigned_eip_set = [
104+
tencentcloud_eip.eip_example1.public_ip,
105+
tencentcloud_eip.eip_example2.public_ip,
106+
]
107+
tags = {
108+
createBy = "terraform"
109+
}
110+
}
111+
```
112+
80113
## Argument Reference
81114

82115
The following arguments are supported:
@@ -87,6 +120,7 @@ The following arguments are supported:
87120
* `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`.
88121
* `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`.
89122
* `nat_product_version` - (Optional, Int, ForceNew) 1: traditional NAT, 2: standard NAT, default value is 1.
123+
* `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.
90124
* `subnet_id` - (Optional, String, ForceNew) Subnet of NAT.
91125
* `tags` - (Optional, Map) The available tags within this NAT gateway.
92126
* `zone` - (Optional, String) The availability zone, such as `ap-guangzhou-3`.

0 commit comments

Comments
 (0)