@@ -13,7 +13,7 @@ resource "tencentcloud_tem_application_service" "application_service" {
1313 port_mapping_item_list {
1414 port = 80
1515 target_port = 80
16- protocol = "tcp "
16+ protocol = "TCP "
1717 }
1818 }
1919}
@@ -71,15 +71,31 @@ func resourceTencentCloudTemApplicationService() *schema.Resource {
7171 Elem : & schema.Resource {
7272 Schema : map [string ]* schema.Schema {
7373 "type" : {
74- Type : schema .TypeString ,
75- Optional : true ,
76- Description : "application service type: EXTERNAL | VPC | CLUSTER." ,
74+ Type : schema .TypeString ,
75+ Optional : true ,
76+ Description : "application service type: EXTERNAL | VPC | CLUSTER." ,
77+ ValidateFunc : validateAllowedStringValue ([]string {"EXTERNAL" , "VPC" , "CLUSTER" }),
7778 },
7879 "service_name" : {
7980 Type : schema .TypeString ,
8081 Optional : true ,
8182 Description : "application service name." ,
8283 },
84+ "vpc_id" : {
85+ Optional : true ,
86+ Type : schema .TypeString ,
87+ Description : "ID of vpc instance, required when type is `VPC`." ,
88+ },
89+ "subnet_id" : {
90+ Optional : true ,
91+ Type : schema .TypeString ,
92+ Description : "ID of subnet instance, required when type is `VPC`." ,
93+ },
94+ "ip" : {
95+ Type : schema .TypeString ,
96+ Computed : true ,
97+ Description : "ip address of application service." ,
98+ },
8399 "port_mapping_item_list" : {
84100 Type : schema .TypeList ,
85101 Optional : true ,
@@ -137,6 +153,18 @@ func resourceTencentCloudTemApplicationServiceCreate(d *schema.ResourceData, met
137153 servicePortMapping := tem.ServicePortMapping {}
138154 if v , ok := dMap ["type" ]; ok {
139155 servicePortMapping .Type = helper .String (v .(string ))
156+ if v .(string ) == "VPC" {
157+ if vv , ok := dMap ["vpc_id" ]; ok && vv != "" {
158+ servicePortMapping .VpcId = helper .String (vv .(string ))
159+ } else {
160+ return fmt .Errorf ("vpc_id is required when type is `VPC`" )
161+ }
162+ if vv , ok := dMap ["subnet_id" ]; ok && vv != "" {
163+ servicePortMapping .SubnetId = helper .String (vv .(string ))
164+ } else {
165+ return fmt .Errorf ("subnet_id is required when type is `VPC`" )
166+ }
167+ }
140168 }
141169 if v , ok := dMap ["service_name" ]; ok {
142170 serviceName = v .(string )
@@ -175,6 +203,22 @@ func resourceTencentCloudTemApplicationServiceCreate(d *schema.ResourceData, met
175203 return err
176204 }
177205
206+ ctx := context .WithValue (context .TODO (), logIdKey , logId )
207+ service := TemService {client : meta .(* TencentCloudClient ).apiV3Conn }
208+ err = resource .Retry (3 * readRetryTimeout , func () * resource.RetryError {
209+ service , errRet := service .DescribeTemApplicationServiceById (ctx , environmentId , applicationId )
210+ if errRet != nil {
211+ return retryError (errRet , InternalError )
212+ }
213+ if * service .Result .AllIpDone {
214+ return nil
215+ }
216+ return resource .RetryableError (fmt .Errorf ("service is not ready %v, retry..." , * service .Result .AllIpDone ))
217+ })
218+ if err != nil {
219+ return err
220+ }
221+
178222 d .SetId (environmentId + FILED_SP + applicationId + FILED_SP + serviceName )
179223
180224 return resourceTencentCloudTemApplicationServiceRead (d , meta )
@@ -223,12 +267,29 @@ func resourceTencentCloudTemApplicationServiceRead(d *schema.ResourceData, meta
223267
224268 if applicationService .Type != nil {
225269 serviceMap ["type" ] = applicationService .Type
270+ if * applicationService .Type == "VPC" {
271+ if applicationService .VpcId != nil {
272+ serviceMap ["vpc_id" ] = applicationService .VpcId
273+ }
274+
275+ if applicationService .SubnetId != nil {
276+ serviceMap ["subnet_id" ] = applicationService .SubnetId
277+ }
278+ }
226279 }
227280
228281 if applicationService .ServiceName != nil {
229282 serviceMap ["service_name" ] = applicationService .ServiceName
230283 }
231284
285+ if applicationService .Type != nil {
286+ if * applicationService .Type == "CLUSTER" {
287+ serviceMap ["ip" ] = applicationService .ClusterIp
288+ } else {
289+ serviceMap ["ip" ] = applicationService .ExternalIp
290+ }
291+ }
292+
232293 if applicationService .PortMappingItemList != nil {
233294 portMappingItemListList := []interface {}{}
234295 for _ , portMappingItemList := range applicationService .PortMappingItemList {
@@ -284,6 +345,18 @@ func resourceTencentCloudTemApplicationServiceUpdate(d *schema.ResourceData, met
284345 servicePortMapping := tem.ServicePortMapping {}
285346 if v , ok := dMap ["type" ]; ok {
286347 servicePortMapping .Type = helper .String (v .(string ))
348+ if v .(string ) == "VPC" {
349+ if vv , ok := dMap ["vpc_id" ]; ok && vv != "" {
350+ servicePortMapping .VpcId = helper .String (vv .(string ))
351+ } else {
352+ return fmt .Errorf ("vpc_id is required when type is `VPC`" )
353+ }
354+ if vv , ok := dMap ["subnet_id" ]; ok && vv != "" {
355+ servicePortMapping .SubnetId = helper .String (vv .(string ))
356+ } else {
357+ return fmt .Errorf ("subnet_id is required when type is `VPC`" )
358+ }
359+ }
287360 }
288361
289362 servicePortMapping .ServiceName = & serviceName
0 commit comments