@@ -10,6 +10,10 @@ resource "tencentcloud_nat_gateway" "foo" {
1010 bandwidth = 100
1111 max_concurrent = 1000000
1212 assigned_eip_set = ["1.1.1.1"]
13+
14+ tags = {
15+ test = "tf"
16+ }
1317}
1418```
1519
@@ -24,6 +28,7 @@ $ terraform import tencentcloud_nat_gateway.foo nat-1asg3t63
2428package tencentcloud
2529
2630import (
31+ "context"
2732 "fmt"
2833 "log"
2934 "time"
@@ -81,6 +86,12 @@ func resourceTencentCloudNatGateway() *schema.Resource {
8186 MaxItems : 10 ,
8287 Description : "EIP IP address set bound to the gateway. The value of at least 1 and at most 10." ,
8388 },
89+ "tags" : {
90+ Type : schema .TypeMap ,
91+ Optional : true ,
92+ Description : "The available tags within this NAT gateway." ,
93+ },
94+ //computed
8495 "created_time" : {
8596 Type : schema .TypeString ,
8697 Computed : true ,
@@ -161,6 +172,17 @@ func resourceTencentCloudNatGatewayCreate(d *schema.ResourceData, meta interface
161172 log .Printf ("[CRITAL]%s create NAT gateway failed, reason:%s\n " , logId , err .Error ())
162173 return err
163174 }
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+ }
164186 return resourceTencentCloudNatGatewayRead (d , meta )
165187}
166188
@@ -169,6 +191,7 @@ func resourceTencentCloudNatGatewayRead(d *schema.ResourceData, meta interface{}
169191 defer inconsistentCheck (d , meta )()
170192
171193 logId := getLogId (contextNil )
194+ ctx := context .WithValue (context .TODO (), logIdKey , logId )
172195
173196 natGatewayId := d .Id ()
174197 request := vpc .NewDescribeNatGatewaysRequest ()
@@ -201,6 +224,15 @@ func resourceTencentCloudNatGatewayRead(d *schema.ResourceData, meta interface{}
201224 _ = d .Set ("bandwidth" , * nat .InternetMaxBandwidthOut )
202225 _ = d .Set ("create_time" , * nat .CreatedTime )
203226 _ = 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+
204236 return nil
205237}
206238
@@ -407,6 +439,23 @@ func resourceTencentCloudNatGatewayUpdate(d *schema.ResourceData, meta interface
407439 }
408440
409441 }
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+
410459 d .Partial (false )
411460
412461 return nil
0 commit comments