Skip to content

Commit 177a06d

Browse files
authored
support nat zone (#1959)
* support nat zone * support nat zone
1 parent 6c78559 commit 177a06d

File tree

4 files changed

+73
-16
lines changed

4 files changed

+73
-16
lines changed

.changelog/1959.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_nat_gateway: support set `zone`
3+
```

tencentcloud/resource_tc_clb_instance.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,8 +795,12 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac
795795
request.SnatPro = &snatPro
796796
}
797797

798-
if d.HasChange("snat_ips") {
799-
return fmt.Errorf("`snat_ips`")
798+
immutableArgs := []string{"snat_ips", "dynamic_vip"}
799+
800+
for _, v := range immutableArgs {
801+
if d.HasChange(v) {
802+
return fmt.Errorf("argument `%s` cannot be changed", v)
803+
}
800804
}
801805

802806
if changed {

tencentcloud/resource_tc_nat_gateway.go

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,30 @@ Provides a resource to create a NAT gateway.
44
Example Usage
55
66
```hcl
7-
resource "tencentcloud_nat_gateway" "foo" {
8-
name = "test_nat_gateway"
9-
vpc_id = "vpc-4xxr2cy7"
10-
bandwidth = 100
11-
max_concurrent = 1000000
12-
assigned_eip_set = ["1.1.1.1"]
7+
data "tencentcloud_vpc_instances" "foo" {
8+
name = "Default-VPC"
9+
}
10+
# Create EIP
11+
resource "tencentcloud_eip" "eip_dev_dnat" {
12+
name = "terraform_nat_test"
13+
}
14+
resource "tencentcloud_eip" "new_eip" {
15+
name = "terraform_nat_test"
16+
}
1317
18+
resource "tencentcloud_nat_gateway" "my_nat" {
19+
vpc_id = data.tencentcloud_vpc_instances.foo.instance_list.0.vpc_id
20+
name = "new_name"
21+
max_concurrent = 10000000
22+
bandwidth = 1000
23+
zone = "ap-guangzhou-3"
24+
25+
assigned_eip_set = [
26+
tencentcloud_eip.eip_dev_dnat.public_ip,
27+
tencentcloud_eip.new_eip.public_ip,
28+
]
1429
tags = {
15-
test = "tf"
30+
tf = "test"
1631
}
1732
}
1833
```
@@ -86,6 +101,12 @@ func resourceTencentCloudNatGateway() *schema.Resource {
86101
MaxItems: 10,
87102
Description: "EIP IP address set bound to the gateway. The value of at least 1 and at most 10.",
88103
},
104+
"zone": {
105+
Type: schema.TypeString,
106+
Optional: true,
107+
Computed: true,
108+
Description: "The availability zone, such as `ap-guangzhou-3`.",
109+
},
89110
"tags": {
90111
Type: schema.TypeMap,
91112
Optional: true,
@@ -124,6 +145,10 @@ func resourceTencentCloudNatGatewayCreate(d *schema.ResourceData, meta interface
124145
}
125146
}
126147

148+
if v, ok := d.GetOk("zone"); ok {
149+
request.Zone = helper.String(v.(string))
150+
}
151+
127152
if v := helper.GetTags(d, "tags"); len(v) > 0 {
128153
for tagKey, tagValue := range v {
129154
tag := vpc.Tag{
@@ -235,6 +260,7 @@ func resourceTencentCloudNatGatewayRead(d *schema.ResourceData, meta interface{}
235260
_ = d.Set("bandwidth", *nat.InternetMaxBandwidthOut)
236261
_ = d.Set("created_time", *nat.CreatedTime)
237262
_ = d.Set("assigned_eip_set", flattenAddressList((*nat).PublicIpAddressSet))
263+
_ = d.Set("zone", *nat.Zone)
238264

239265
tcClient := meta.(*TencentCloudClient).apiV3Conn
240266
tagService := &TagService{client: tcClient}
@@ -254,6 +280,14 @@ func resourceTencentCloudNatGatewayUpdate(d *schema.ResourceData, meta interface
254280
ctx := context.WithValue(context.TODO(), logIdKey, logId)
255281
vpcService := VpcService{client: meta.(*TencentCloudClient).apiV3Conn}
256282

283+
immutableArgs := []string{"zone"}
284+
285+
for _, v := range immutableArgs {
286+
if d.HasChange(v) {
287+
return fmt.Errorf("argument `%s` cannot be changed", v)
288+
}
289+
}
290+
257291
d.Partial(true)
258292
natGatewayId := d.Id()
259293
request := vpc.NewModifyNatGatewayAttributeRequest()

website/docs/r/nat_gateway.html.markdown

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,30 @@ Provides a resource to create a NAT gateway.
1414
## Example Usage
1515

1616
```hcl
17-
resource "tencentcloud_nat_gateway" "foo" {
18-
name = "test_nat_gateway"
19-
vpc_id = "vpc-4xxr2cy7"
20-
bandwidth = 100
21-
max_concurrent = 1000000
22-
assigned_eip_set = ["1.1.1.1"]
17+
data "tencentcloud_vpc_instances" "foo" {
18+
name = "Default-VPC"
19+
}
20+
# Create EIP
21+
resource "tencentcloud_eip" "eip_dev_dnat" {
22+
name = "terraform_nat_test"
23+
}
24+
resource "tencentcloud_eip" "new_eip" {
25+
name = "terraform_nat_test"
26+
}
2327
28+
resource "tencentcloud_nat_gateway" "my_nat" {
29+
vpc_id = data.tencentcloud_vpc_instances.foo.instance_list.0.vpc_id
30+
name = "new_name"
31+
max_concurrent = 10000000
32+
bandwidth = 1000
33+
zone = "ap-guangzhou-3"
34+
35+
assigned_eip_set = [
36+
tencentcloud_eip.eip_dev_dnat.public_ip,
37+
tencentcloud_eip.new_eip.public_ip,
38+
]
2439
tags = {
25-
test = "tf"
40+
tf = "test"
2641
}
2742
}
2843
```
@@ -37,6 +52,7 @@ The following arguments are supported:
3752
* `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.
3853
* `max_concurrent` - (Optional, Int) The upper limit of concurrent connection of NAT gateway. Valid values: `1000000`, `3000000`, `10000000`. Default is `1000000`.
3954
* `tags` - (Optional, Map) The available tags within this NAT gateway.
55+
* `zone` - (Optional, String) The availability zone, such as `ap-guangzhou-3`.
4056

4157
## Attributes Reference
4258

0 commit comments

Comments
 (0)