@@ -5,24 +5,23 @@ Example Usage
55
66```hcl
77resource "tencentcloud_tem_application_service" "application_service" {
8- environment_id = "en-xxx "
9- application_id = "xxx "
8+ environment_id = "en-dpxyydl5 "
9+ application_id = "app-jrl3346j "
1010 service {
1111 type = "CLUSTER"
12- service_name = "consumer "
12+ service_name = "test0-1 "
1313 port_mapping_item_list {
1414 port = 80
1515 target_port = 80
1616 protocol = "tcp"
1717 }
18-
1918 }
2019}
2120```
2221
2322Import
2423
25- tem application_service can be imported using the id , e.g.
24+ tem application_service can be imported using the environmentId#applicationId#serviceName , e.g.
2625
2726```
2827terraform import tencentcloud_tem_application_service.application_service application_service_id
@@ -122,6 +121,7 @@ func resourceTencentCloudTemApplicationServiceCreate(d *schema.ResourceData, met
122121 request = tem .NewCreateApplicationServiceRequest ()
123122 environmentId string
124123 applicationId string
124+ serviceName string
125125 )
126126 if v , ok := d .GetOk ("environment_id" ); ok {
127127 environmentId = v .(string )
@@ -139,6 +139,7 @@ func resourceTencentCloudTemApplicationServiceCreate(d *schema.ResourceData, met
139139 servicePortMapping .Type = helper .String (v .(string ))
140140 }
141141 if v , ok := dMap ["service_name" ]; ok {
142+ serviceName = v .(string )
142143 servicePortMapping .ServiceName = helper .String (v .(string ))
143144 }
144145 if v , ok := dMap ["port_mapping_item_list" ]; ok {
@@ -174,7 +175,7 @@ func resourceTencentCloudTemApplicationServiceCreate(d *schema.ResourceData, met
174175 return err
175176 }
176177
177- d .SetId (environmentId + FILED_SP + applicationId )
178+ d .SetId (environmentId + FILED_SP + applicationId + FILED_SP + serviceName )
178179
179180 return resourceTencentCloudTemApplicationServiceRead (d , meta )
180181}
@@ -190,11 +191,12 @@ func resourceTencentCloudTemApplicationServiceRead(d *schema.ResourceData, meta
190191 service := TemService {client : meta .(* TencentCloudClient ).apiV3Conn }
191192
192193 idSplit := strings .Split (d .Id (), FILED_SP )
193- if len (idSplit ) != 2 {
194+ if len (idSplit ) != 3 {
194195 return fmt .Errorf ("id is broken,%s" , d .Id ())
195196 }
196197 environmentId := idSplit [0 ]
197198 applicationId := idSplit [1 ]
199+ serviceName := idSplit [2 ]
198200
199201 res , err := service .DescribeTemApplicationServiceById (ctx , environmentId , applicationId )
200202 if err != nil {
@@ -209,7 +211,12 @@ func resourceTencentCloudTemApplicationServiceRead(d *schema.ResourceData, meta
209211 _ = d .Set ("environment_id" , environmentId )
210212 _ = d .Set ("application_id" , applicationId )
211213
212- applicationService := res .Result .ServicePortMappingList [0 ]
214+ var applicationService * tem.ServicePortMapping
215+ for _ , v := range res .Result .ServicePortMappingList {
216+ if * v .ServiceName == serviceName {
217+ applicationService = v
218+ }
219+ }
213220
214221 if applicationService != nil {
215222 serviceMap := map [string ]interface {}{}
@@ -242,10 +249,13 @@ func resourceTencentCloudTemApplicationServiceRead(d *schema.ResourceData, meta
242249 portMappingItemListList = append (portMappingItemListList , portMappingItemListMap )
243250 }
244251
245- serviceMap ["port_mapping_item_list" ] = [] interface {}{ portMappingItemListList }
252+ serviceMap ["port_mapping_item_list" ] = portMappingItemListList
246253 }
247254
248- _ = d .Set ("service" , []interface {}{serviceMap })
255+ err = d .Set ("service" , []interface {}{serviceMap })
256+ if err != nil {
257+ return err
258+ }
249259 }
250260
251261 return nil
@@ -257,14 +267,24 @@ func resourceTencentCloudTemApplicationServiceUpdate(d *schema.ResourceData, met
257267
258268 logId := getLogId (contextNil )
259269
270+ unsupportedUpdateFields := []string {
271+ "service" ,
272+ }
273+ for _ , field := range unsupportedUpdateFields {
274+ if d .HasChange (field ) {
275+ return fmt .Errorf ("tencentcloud_tem_application_service update on %s is not support yet" , field )
276+ }
277+ }
278+
260279 request := tem .NewModifyApplicationServiceRequest ()
261280
262281 idSplit := strings .Split (d .Id (), FILED_SP )
263- if len (idSplit ) != 2 {
282+ if len (idSplit ) != 3 {
264283 return fmt .Errorf ("id is broken,%s" , d .Id ())
265284 }
266285 environmentId := idSplit [0 ]
267286 applicationId := idSplit [1 ]
287+ serviceName := idSplit [2 ]
268288
269289 request .EnvironmentId = & environmentId
270290 request .ApplicationId = & applicationId
@@ -274,9 +294,8 @@ func resourceTencentCloudTemApplicationServiceUpdate(d *schema.ResourceData, met
274294 if v , ok := dMap ["type" ]; ok {
275295 servicePortMapping .Type = helper .String (v .(string ))
276296 }
277- if v , ok := dMap ["service_name" ]; ok {
278- servicePortMapping .ServiceName = helper .String (v .(string ))
279- }
297+
298+ servicePortMapping .ServiceName = & serviceName
280299 if v , ok := dMap ["port_mapping_item_list" ]; ok {
281300 for _ , item := range v .([]interface {}) {
282301 portMappingItemListMap := item .(map [string ]interface {})
@@ -323,14 +342,15 @@ func resourceTencentCloudTemApplicationServiceDelete(d *schema.ResourceData, met
323342
324343 service := TemService {client : meta .(* TencentCloudClient ).apiV3Conn }
325344 idSplit := strings .Split (d .Id (), FILED_SP )
326- if len (idSplit ) != 2 {
345+ if len (idSplit ) != 3 {
327346 return fmt .Errorf ("id is broken,%s" , d .Id ())
328347 }
329348 environmentId := idSplit [0 ]
330349 applicationId := idSplit [1 ]
350+ serviceName := idSplit [2 ]
331351
332- if err := service .DeleteTemApplicationServiceById (ctx , environmentId , applicationId ); err != nil {
333- return nil
352+ if err := service .DeleteTemApplicationServiceById (ctx , environmentId , applicationId , serviceName ); err != nil {
353+ return err
334354 }
335355
336356 return nil
0 commit comments