@@ -10,6 +10,10 @@ resource "tencentcloud_nat_gateway" "foo" {
10
10
bandwidth = 100
11
11
max_concurrent = 1000000
12
12
assigned_eip_set = ["1.1.1.1"]
13
+
14
+ tags = {
15
+ test = "tf"
16
+ }
13
17
}
14
18
```
15
19
@@ -24,6 +28,7 @@ $ terraform import tencentcloud_nat_gateway.foo nat-1asg3t63
24
28
package tencentcloud
25
29
26
30
import (
31
+ "context"
27
32
"fmt"
28
33
"log"
29
34
"time"
@@ -81,6 +86,12 @@ func resourceTencentCloudNatGateway() *schema.Resource {
81
86
MaxItems : 10 ,
82
87
Description : "EIP IP address set bound to the gateway. The value of at least 1 and at most 10." ,
83
88
},
89
+ "tags" : {
90
+ Type : schema .TypeMap ,
91
+ Optional : true ,
92
+ Description : "The available tags within this NAT gateway." ,
93
+ },
94
+ //computed
84
95
"created_time" : {
85
96
Type : schema .TypeString ,
86
97
Computed : true ,
@@ -161,6 +172,17 @@ func resourceTencentCloudNatGatewayCreate(d *schema.ResourceData, meta interface
161
172
log .Printf ("[CRITAL]%s create NAT gateway failed, reason:%s\n " , logId , err .Error ())
162
173
return err
163
174
}
175
+
176
+ //cs::vpc:ap-guangzhou:uin/12345:nat/nat-nxxx
177
+ ctx := context .WithValue (context .TODO (), logIdKey , logId )
178
+ if tags := helper .GetTags (d , "tags" ); len (tags ) > 0 {
179
+ tcClient := meta .(* TencentCloudClient ).apiV3Conn
180
+ tagService := & TagService {client : tcClient }
181
+ resourceName := BuildTagResourceName ("vpc" , "nat" , tcClient .Region , d .Id ())
182
+ if err := tagService .ModifyTags (ctx , resourceName , tags , nil ); err != nil {
183
+ return err
184
+ }
185
+ }
164
186
return resourceTencentCloudNatGatewayRead (d , meta )
165
187
}
166
188
@@ -169,6 +191,7 @@ func resourceTencentCloudNatGatewayRead(d *schema.ResourceData, meta interface{}
169
191
defer inconsistentCheck (d , meta )()
170
192
171
193
logId := getLogId (contextNil )
194
+ ctx := context .WithValue (context .TODO (), logIdKey , logId )
172
195
173
196
natGatewayId := d .Id ()
174
197
request := vpc .NewDescribeNatGatewaysRequest ()
@@ -201,6 +224,15 @@ func resourceTencentCloudNatGatewayRead(d *schema.ResourceData, meta interface{}
201
224
_ = d .Set ("bandwidth" , * nat .InternetMaxBandwidthOut )
202
225
_ = d .Set ("create_time" , * nat .CreatedTime )
203
226
_ = d .Set ("assigned_eip_set" , flattenAddressList ((* nat ).PublicIpAddressSet ))
227
+
228
+ tcClient := meta .(* TencentCloudClient ).apiV3Conn
229
+ tagService := & TagService {client : tcClient }
230
+ tags , err := tagService .DescribeResourceTags (ctx , "vpc" , "nat" , tcClient .Region , d .Id ())
231
+ if err != nil {
232
+ return err
233
+ }
234
+ _ = d .Set ("tags" , tags )
235
+
204
236
return nil
205
237
}
206
238
@@ -407,6 +439,23 @@ func resourceTencentCloudNatGatewayUpdate(d *schema.ResourceData, meta interface
407
439
}
408
440
409
441
}
442
+
443
+ ctx := context .WithValue (context .TODO (), logIdKey , logId )
444
+ if d .HasChange ("tags" ) {
445
+
446
+ oldValue , newValue := d .GetChange ("tags" )
447
+ replaceTags , deleteTags := diffTags (oldValue .(map [string ]interface {}), newValue .(map [string ]interface {}))
448
+
449
+ tcClient := meta .(* TencentCloudClient ).apiV3Conn
450
+ tagService := & TagService {client : tcClient }
451
+ resourceName := BuildTagResourceName ("vpc" , "nat" , tcClient .Region , d .Id ())
452
+ err := tagService .ModifyTags (ctx , resourceName , replaceTags , deleteTags )
453
+ if err != nil {
454
+ return err
455
+ }
456
+ d .SetPartial ("tags" )
457
+ }
458
+
410
459
d .Partial (false )
411
460
412
461
return nil
0 commit comments