Skip to content

Commit f9cc4a9

Browse files
gitmknanonymous
andauthored
fix: support ip and vpc_id subnet_id (#1514)
* fix: support ip and vpc_id subnet_id * fix: merge master * feat: add changelog Co-authored-by: anonymous <anonymous@mail.org>
1 parent da62295 commit f9cc4a9

File tree

8 files changed

+94
-7
lines changed

8 files changed

+94
-7
lines changed

.changelog/1514.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_tem_application_service: Support for inputting vpc_id and subnet_id, and adding IP for output
3+
```

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ require (
7474
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.578
7575
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdcpg v1.0.533
7676
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq v1.0.564
77-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.573
77+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.578
7878
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.529
7979
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.549
8080
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tsf v1.0.577

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.527 h1:nRFYv2e
660660
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.527/go.mod h1:mWXRd5WNzX7ypg1MNliZvz5mlfIJ9h0KvyOGnH86KFc=
661661
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.573 h1:cf0nErWh7i85lgJZwN/1I65CbhmlCZrN458vmSeIYtQ=
662662
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.573/go.mod h1:rZTntzTRsDs4Rhs2gjbxduXWGt7/lTHHflf/mfy68Gc=
663+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.578 h1:vBpQhUroO+FAslUmsDWGi8nvczsqZBWVgQwlnyT0Aj8=
664+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.578/go.mod h1:UlojGQh/9wb7/uXPNi7PvMral1CNAskVDNgqJEV83l0=
663665
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.529 h1:vWUgseUvHs1fW/Ok+x3ld9UIhrYRNO9Yr8ccX8wmkkY=
664666
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.529/go.mod h1:vOd23iOVeQqm5LSEXUmE8773kiUCwGuoJnTO0po5D+Q=
665667
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.519 h1:o8NsQPLV6T8TD4sHxufCwtCsqYM4CUM1132zut6toww=

tencentcloud/resource_tc_tem_application_service.go

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem/v20210701/client.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem/v20210701/errors.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr/v20190924
641641
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdcpg/v20211118
642642
# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq v1.0.564
643643
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq/v20200217
644-
# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.573
644+
# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.578
645645
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem/v20210701
646646
# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.529
647647
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220901

website/docs/r/tem_application_service.html.markdown

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ resource "tencentcloud_tem_application_service" "application_service" {
2323
port_mapping_item_list {
2424
port = 80
2525
target_port = 80
26-
protocol = "tcp"
26+
protocol = "TCP"
2727
}
2828
}
2929
}
@@ -47,7 +47,9 @@ The `service` object supports the following:
4747

4848
* `port_mapping_item_list` - (Optional, List) port mapping item list.
4949
* `service_name` - (Optional, String) application service name.
50+
* `subnet_id` - (Optional, String) ID of subnet instance, required when type is `VPC`.
5051
* `type` - (Optional, String) application service type: EXTERNAL | VPC | CLUSTER.
52+
* `vpc_id` - (Optional, String) ID of vpc instance, required when type is `VPC`.
5153

5254
## Attributes Reference
5355

0 commit comments

Comments
 (0)