@@ -12,6 +12,9 @@ resource "tencentcloud_tem_application" "application" {
1212 repo_type = 2
1313 repo_name = "qcloud/nginx"
1414 repo_server = "ccr.ccs.tencentyun.com"
15+ tags = {
16+ "created" = "terraform"
17+ }
1518}
1619```
1720*/
@@ -87,6 +90,11 @@ func resourceTencentCloudTemApplication() *schema.Resource {
8790 Computed : true ,
8891 Description : "tcr instance id." ,
8992 },
93+ "tags" : {
94+ Type : schema .TypeMap ,
95+ Optional : true ,
96+ Description : "application tag list." ,
97+ },
9098 },
9199 }
92100}
@@ -96,6 +104,7 @@ func resourceTencentCloudTemApplicationCreate(d *schema.ResourceData, meta inter
96104 defer inconsistentCheck (d , meta )()
97105
98106 logId := getLogId (contextNil )
107+ ctx := context .WithValue (context .TODO (), logIdKey , logId )
99108
100109 var (
101110 request = tem .NewCreateApplicationRequest ()
@@ -132,6 +141,16 @@ func resourceTencentCloudTemApplicationCreate(d *schema.ResourceData, meta inter
132141 request .InstanceId = helper .String (v .(string ))
133142 }
134143
144+ if v , ok := d .GetOk ("tags" ); ok {
145+ for key , value := range v .(map [string ]interface {}) {
146+ tag := tem.Tag {
147+ TagKey : helper .String (key ),
148+ TagValue : helper .String (value .(string )),
149+ }
150+ request .Tags = append (request .Tags , & tag )
151+ }
152+ }
153+
135154 request .DeployMode = helper .String ("IMAGE" )
136155
137156 err := resource .Retry (writeRetryTimeout , func () * resource.RetryError {
@@ -154,6 +173,16 @@ func resourceTencentCloudTemApplicationCreate(d *schema.ResourceData, meta inter
154173 applicationId := * response .Response .Result
155174
156175 d .SetId (applicationId )
176+
177+ if tags := helper .GetTags (d , "tags" ); len (tags ) > 0 {
178+ tagService := TagService {client : meta .(* TencentCloudClient ).apiV3Conn }
179+ region := meta .(* TencentCloudClient ).apiV3Conn .Region
180+ resourceName := fmt .Sprintf ("qcs::tem:%s:uin/:application/%s" , region , applicationId )
181+ if err := tagService .ModifyTags (ctx , resourceName , tags , nil ); err != nil {
182+ return err
183+ }
184+ }
185+
157186 return resourceTencentCloudTemApplicationRead (d , meta )
158187}
159188
@@ -209,6 +238,15 @@ func resourceTencentCloudTemApplicationRead(d *schema.ResourceData, meta interfa
209238 _ = d .Set ("instance_id" , application .InstanceId )
210239 }
211240
241+ client := meta .(* TencentCloudClient ).apiV3Conn
242+ tagService := TagService {client : client }
243+ region := client .Region
244+ tags , err := tagService .DescribeResourceTags (ctx , "tem" , "application" , region , applicationId )
245+ if err != nil {
246+ return err
247+ }
248+ _ = d .Set ("tags" , tags )
249+
212250 return nil
213251}
214252
@@ -217,6 +255,7 @@ func resourceTencentCloudTemApplicationUpdate(d *schema.ResourceData, meta inter
217255 defer inconsistentCheck (d , meta )()
218256
219257 logId := getLogId (contextNil )
258+ ctx := context .WithValue (context .TODO (), logIdKey , logId )
220259
221260 request := tem .NewModifyApplicationInfoRequest ()
222261
@@ -226,10 +265,8 @@ func resourceTencentCloudTemApplicationUpdate(d *schema.ResourceData, meta inter
226265 return fmt .Errorf ("`application_name` do not support change now." )
227266 }
228267
229- if d .HasChange ("description" ) {
230- if v , ok := d .GetOk ("description" ); ok {
231- request .Description = helper .String (v .(string ))
232- }
268+ if v , ok := d .GetOk ("description" ); ok {
269+ request .Description = helper .String (v .(string ))
233270 }
234271
235272 if d .HasChange ("coding_language" ) {
@@ -271,6 +308,17 @@ func resourceTencentCloudTemApplicationUpdate(d *schema.ResourceData, meta inter
271308 return err
272309 }
273310
311+ if d .HasChange ("tags" ) {
312+ tcClient := meta .(* TencentCloudClient ).apiV3Conn
313+ tagService := & TagService {client : tcClient }
314+ oldTags , newTags := d .GetChange ("tags" )
315+ replaceTags , deleteTags := diffTags (oldTags .(map [string ]interface {}), newTags .(map [string ]interface {}))
316+ resourceName := BuildTagResourceName ("tem" , "application" , tcClient .Region , d .Id ())
317+ if err := tagService .ModifyTags (ctx , resourceName , replaceTags , deleteTags ); err != nil {
318+ return err
319+ }
320+ }
321+
274322 return resourceTencentCloudTemApplicationRead (d , meta )
275323}
276324
0 commit comments