Skip to content

Commit 4ed9af5

Browse files
authored
add standard nat (#2275)
* add standard nat * add standard nat
1 parent f571ee6 commit 4ed9af5

File tree

3 files changed

+110
-3
lines changed

3 files changed

+110
-3
lines changed

.changelog/2275.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
tencentcloud_nat_gateway: Support create standard nat
3+
```

tencentcloud/resource_tc_nat_gateway.go

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Provides a resource to create a NAT gateway.
33
44
Example Usage
55
6-
Create a NAT gateway.
6+
Create a traditional NAT gateway.
77
88
```hcl
99
resource "tencentcloud_vpc" "vpc" {
@@ -34,6 +34,43 @@ resource "tencentcloud_nat_gateway" "example" {
3434
}
3535
```
3636
37+
Create a standard NAT gateway.
38+
39+
```hcl
40+
resource "tencentcloud_vpc" "vpc" {
41+
cidr_block = "10.0.0.0/16"
42+
name = "tf_nat_gateway_vpc"
43+
}
44+
45+
resource "tencentcloud_eip" "eip_example1" {
46+
name = "tf_nat_gateway_eip1"
47+
}
48+
49+
resource "tencentcloud_eip" "eip_example2" {
50+
name = "tf_nat_gateway_eip2"
51+
}
52+
53+
resource "tencentcloud_nat_gateway" "example" {
54+
name = "tf_example_nat_gateway"
55+
vpc_id = tencentcloud_vpc.vpc.id
56+
assigned_eip_set = [
57+
tencentcloud_eip.eip_example1.public_ip,
58+
tencentcloud_eip.eip_example2.public_ip,
59+
]
60+
nat_product_version = 2
61+
tags = {
62+
tf_tag_key = "tf_tag_value"
63+
}
64+
lifecycle {
65+
ignore_changes = [
66+
// standard nat will set default values for bandwidth and max_concurrent
67+
bandwidth,
68+
max_concurrent,
69+
]
70+
}
71+
}
72+
```
73+
3774
Import
3875
3976
NAT gateway can be imported using the id, e.g.
@@ -109,6 +146,20 @@ func resourceTencentCloudNatGateway() *schema.Resource {
109146
Computed: true,
110147
Description: "The availability zone, such as `ap-guangzhou-3`.",
111148
},
149+
"subnet_id": {
150+
Type: schema.TypeString,
151+
Optional: true,
152+
Computed: true,
153+
ForceNew: true,
154+
Description: "Subnet of NAT.",
155+
},
156+
"nat_product_version": {
157+
Type: schema.TypeInt,
158+
Optional: true,
159+
Computed: true,
160+
ForceNew: true,
161+
Description: "1: traditional NAT, 2: standard NAT, default value is 1.",
162+
},
112163
"tags": {
113164
Type: schema.TypeMap,
114165
Optional: true,
@@ -151,6 +202,14 @@ func resourceTencentCloudNatGatewayCreate(d *schema.ResourceData, meta interface
151202
request.Zone = helper.String(v.(string))
152203
}
153204

205+
if v, ok := d.GetOk("subnet_id"); ok {
206+
request.SubnetId = helper.String(v.(string))
207+
}
208+
209+
if v, ok := d.GetOkExists("nat_product_version"); ok {
210+
request.NatProductVersion = helper.IntUint64(v.(int))
211+
}
212+
154213
if v := helper.GetTags(d, "tags"); len(v) > 0 {
155214
for tagKey, tagValue := range v {
156215
tag := vpc.Tag{
@@ -200,7 +259,7 @@ func resourceTencentCloudNatGatewayCreate(d *schema.ResourceData, meta interface
200259
result, e := meta.(*TencentCloudClient).apiV3Conn.UseVpcClient().DescribeNatGateways(statRequest)
201260
if e != nil {
202261
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
203-
logId, request.GetAction(), request.ToJsonString(), e.Error())
262+
logId, statRequest.GetAction(), statRequest.ToJsonString(), e.Error())
204263
return retryError(e)
205264
} else {
206265
//if not, quit
@@ -263,6 +322,12 @@ func resourceTencentCloudNatGatewayRead(d *schema.ResourceData, meta interface{}
263322
_ = d.Set("created_time", *nat.CreatedTime)
264323
_ = d.Set("assigned_eip_set", flattenAddressList((*nat).PublicIpAddressSet))
265324
_ = d.Set("zone", *nat.Zone)
325+
if nat.SubnetId != nil {
326+
_ = d.Set("subnet_id", *nat.SubnetId)
327+
}
328+
if nat.NatProductVersion != nil {
329+
_ = d.Set("nat_product_version", *nat.NatProductVersion)
330+
}
266331

267332
tcClient := meta.(*TencentCloudClient).apiV3Conn
268333
tagService := &TagService{client: tcClient}

website/docs/r/nat_gateway.html.markdown

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Provides a resource to create a NAT gateway.
1313

1414
## Example Usage
1515

16-
### Create a NAT gateway.
16+
### Create a traditional NAT gateway.
1717

1818
```hcl
1919
resource "tencentcloud_vpc" "vpc" {
@@ -44,6 +44,43 @@ resource "tencentcloud_nat_gateway" "example" {
4444
}
4545
```
4646

47+
### Create a standard NAT gateway.
48+
49+
```hcl
50+
resource "tencentcloud_vpc" "vpc" {
51+
cidr_block = "10.0.0.0/16"
52+
name = "tf_nat_gateway_vpc"
53+
}
54+
55+
resource "tencentcloud_eip" "eip_example1" {
56+
name = "tf_nat_gateway_eip1"
57+
}
58+
59+
resource "tencentcloud_eip" "eip_example2" {
60+
name = "tf_nat_gateway_eip2"
61+
}
62+
63+
resource "tencentcloud_nat_gateway" "example" {
64+
name = "tf_example_nat_gateway"
65+
vpc_id = tencentcloud_vpc.vpc.id
66+
assigned_eip_set = [
67+
tencentcloud_eip.eip_example1.public_ip,
68+
tencentcloud_eip.eip_example2.public_ip,
69+
]
70+
nat_product_version = 2
71+
tags = {
72+
tf_tag_key = "tf_tag_value"
73+
}
74+
lifecycle {
75+
ignore_changes = [
76+
// standard nat will set default values for bandwidth and max_concurrent
77+
bandwidth,
78+
max_concurrent,
79+
]
80+
}
81+
}
82+
```
83+
4784
## Argument Reference
4885

4986
The following arguments are supported:
@@ -53,6 +90,8 @@ The following arguments are supported:
5390
* `vpc_id` - (Required, String, ForceNew) ID of the vpc.
5491
* `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.
5592
* `max_concurrent` - (Optional, Int) The upper limit of concurrent connection of NAT gateway. Valid values: `1000000`, `3000000`, `10000000`. Default is `1000000`.
93+
* `nat_product_version` - (Optional, Int, ForceNew) 1: traditional NAT, 2: standard NAT, default value is 1.
94+
* `subnet_id` - (Optional, String, ForceNew) Subnet of NAT.
5695
* `tags` - (Optional, Map) The available tags within this NAT gateway.
5796
* `zone` - (Optional, String) The availability zone, such as `ap-guangzhou-3`.
5897

0 commit comments

Comments
 (0)