Skip to content

Commit 436c457

Browse files
authoredApr 11, 2025··
fix(vpc): [137104059] tencentcloud_vpc_end_point_service updace code and doc (#3295)
* add * add
1 parent 7092a82 commit 436c457

File tree

4 files changed

+60
-45
lines changed

4 files changed

+60
-45
lines changed
 

‎.changelog/3295.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_vpc_end_point_service: updace code and doc
3+
```

‎tencentcloud/services/pls/resource_tc_vpc_end_point_service.go

+40-28
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ func resourceTencentCloudVpcEndPointServiceCreate(d *schema.ResourceData, meta i
9393
defer tccommon.LogElapsed("resource.tencentcloud_vpc_end_point_service.create")()
9494
defer tccommon.InconsistentCheck(d, meta)()
9595

96-
logId := tccommon.GetLogId(tccommon.ContextNil)
97-
9896
var (
97+
logId = tccommon.GetLogId(tccommon.ContextNil)
9998
request = vpc.NewCreateVpcEndPointServiceRequest()
10099
response = vpc.NewCreateVpcEndPointServiceResponse()
101100
endPointServiceId string
102101
)
102+
103103
if v, ok := d.GetOk("vpc_id"); ok {
104104
request.VpcId = helper.String(v.(string))
105105
}
@@ -108,7 +108,7 @@ func resourceTencentCloudVpcEndPointServiceCreate(d *schema.ResourceData, meta i
108108
request.EndPointServiceName = helper.String(v.(string))
109109
}
110110

111-
if v, _ := d.GetOk("auto_accept_flag"); v != nil {
111+
if v, ok := d.GetOkExists("auto_accept_flag"); ok {
112112
request.AutoAcceptFlag = helper.Bool(v.(bool))
113113
}
114114

@@ -127,14 +127,24 @@ func resourceTencentCloudVpcEndPointServiceCreate(d *schema.ResourceData, meta i
127127
} else {
128128
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
129129
}
130+
131+
if result == nil || result.Response == nil {
132+
return resource.RetryableError(fmt.Errorf("Create vpc endPointService failed, Response is nil."))
133+
}
134+
130135
response = result
131136
return nil
132137
})
138+
133139
if err != nil {
134140
log.Printf("[CRITAL]%s create vpc endPointService failed, reason:%+v", logId, err)
135141
return err
136142
}
137143

144+
if response.Response.EndPointService == nil || response.Response.EndPointService.EndPointServiceId == nil {
145+
return fmt.Errorf("EndPointServiceId is nil.")
146+
}
147+
138148
endPointServiceId = *response.Response.EndPointService.EndPointServiceId
139149
d.SetId(endPointServiceId)
140150

@@ -145,16 +155,14 @@ func resourceTencentCloudVpcEndPointServiceRead(d *schema.ResourceData, meta int
145155
defer tccommon.LogElapsed("resource.tencentcloud_vpc_end_point_service.read")()
146156
defer tccommon.InconsistentCheck(d, meta)()
147157

148-
logId := tccommon.GetLogId(tccommon.ContextNil)
149-
150-
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
151-
152-
service := svcvpc.NewVpcService(meta.(tccommon.ProviderMeta).GetAPIV3Conn())
153-
154-
endPointServiceId := d.Id()
158+
var (
159+
logId = tccommon.GetLogId(tccommon.ContextNil)
160+
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
161+
service = svcvpc.NewVpcService(meta.(tccommon.ProviderMeta).GetAPIV3Conn())
162+
endPointServiceId = d.Id()
163+
)
155164

156165
endPointService, err := service.DescribeVpcEndPointServiceById(ctx, endPointServiceId)
157-
158166
if err != nil {
159167
return err
160168
}
@@ -211,36 +219,37 @@ func resourceTencentCloudVpcEndPointServiceUpdate(d *schema.ResourceData, meta i
211219
defer tccommon.LogElapsed("resource.tencentcloud_vpc_end_point_service.update")()
212220
defer tccommon.InconsistentCheck(d, meta)()
213221

214-
logId := tccommon.GetLogId(tccommon.ContextNil)
215-
216-
request := vpc.NewModifyVpcEndPointServiceAttributeRequest()
217-
218-
endPointServiceId := d.Id()
219-
220-
request.EndPointServiceId = &endPointServiceId
221-
222-
if v, ok := d.GetOk("vpc_id"); ok {
223-
request.VpcId = helper.String(v.(string))
224-
}
222+
var (
223+
logId = tccommon.GetLogId(tccommon.ContextNil)
224+
request = vpc.NewModifyVpcEndPointServiceAttributeRequest()
225+
endPointServiceId = d.Id()
226+
)
225227

226228
unsupportedUpdateFields := []string{
227229
"vpc_id",
228230
"service_type",
229231
}
232+
230233
for _, field := range unsupportedUpdateFields {
231234
if d.HasChange(field) {
232235
return fmt.Errorf("tencentcloud_vpc_end_point_service update on %s is not support yet", field)
233236
}
234237
}
235238

239+
request.EndPointServiceId = &endPointServiceId
240+
241+
if v, ok := d.GetOk("vpc_id"); ok {
242+
request.VpcId = helper.String(v.(string))
243+
}
244+
236245
if d.HasChange("end_point_service_name") {
237246
if v, ok := d.GetOk("end_point_service_name"); ok {
238247
request.EndPointServiceName = helper.String(v.(string))
239248
}
240249
}
241250

242251
if d.HasChange("auto_accept_flag") {
243-
if v, _ := d.GetOk("auto_accept_flag"); v != nil {
252+
if v, ok := d.GetOkExists("auto_accept_flag"); ok {
244253
request.AutoAcceptFlag = helper.Bool(v.(bool))
245254
}
246255
}
@@ -258,8 +267,10 @@ func resourceTencentCloudVpcEndPointServiceUpdate(d *schema.ResourceData, meta i
258267
} else {
259268
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
260269
}
270+
261271
return nil
262272
})
273+
263274
if err != nil {
264275
log.Printf("[CRITAL]%s create vpc endPointService failed, reason:%+v", logId, err)
265276
return err
@@ -272,11 +283,12 @@ func resourceTencentCloudVpcEndPointServiceDelete(d *schema.ResourceData, meta i
272283
defer tccommon.LogElapsed("resource.tencentcloud_vpc_end_point_service.delete")()
273284
defer tccommon.InconsistentCheck(d, meta)()
274285

275-
logId := tccommon.GetLogId(tccommon.ContextNil)
276-
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
277-
278-
service := svcvpc.NewVpcService(meta.(tccommon.ProviderMeta).GetAPIV3Conn())
279-
endPointServiceId := d.Id()
286+
var (
287+
logId = tccommon.GetLogId(tccommon.ContextNil)
288+
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
289+
service = svcvpc.NewVpcService(meta.(tccommon.ProviderMeta).GetAPIV3Conn())
290+
endPointServiceId = d.Id()
291+
)
280292

281293
if err := service.DeleteVpcEndPointServiceById(ctx, endPointServiceId); err != nil {
282294
return nil
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
Provides a resource to create a vpc end_point_service
1+
Provides a resource to create a VPC end point service
22

33
Example Usage
44

55
```hcl
6-
resource "tencentcloud_vpc_end_point_service" "end_point_service" {
7-
vpc_id = "vpc-391sv4w3"
8-
end_point_service_name = "terraform-endpoint-service"
9-
auto_accept_flag = false
10-
service_instance_id = "lb-o5f6x7ke"
11-
service_type = "CLB"
6+
resource "tencentcloud_vpc_end_point_service" "example" {
7+
end_point_service_name = "tf-example"
8+
vpc_id = "vpc-9r35gtih"
9+
auto_accept_flag = false
10+
service_type = "CLB"
11+
service_instance_id = "lb-jvb31e26"
1212
}
1313
```
1414

1515
Import
1616

17-
vpc end_point_service can be imported using the id, e.g.
17+
VPC end point service can be imported using the id, e.g.
1818

1919
```
20-
terraform import tencentcloud_vpc_end_point_service.end_point_service end_point_service_id
20+
terraform import tencentcloud_vpc_end_point_service.example vpcsvc-l770dxs5
2121
```

‎website/docs/r/vpc_end_point_service.html.markdown

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ layout: "tencentcloud"
44
page_title: "TencentCloud: tencentcloud_vpc_end_point_service"
55
sidebar_current: "docs-tencentcloud-resource-vpc_end_point_service"
66
description: |-
7-
Provides a resource to create a vpc end_point_service
7+
Provides a resource to create a VPC end point service
88
---
99

1010
# tencentcloud_vpc_end_point_service
1111

12-
Provides a resource to create a vpc end_point_service
12+
Provides a resource to create a VPC end point service
1313

1414
## Example Usage
1515

1616
```hcl
17-
resource "tencentcloud_vpc_end_point_service" "end_point_service" {
18-
vpc_id = "vpc-391sv4w3"
19-
end_point_service_name = "terraform-endpoint-service"
17+
resource "tencentcloud_vpc_end_point_service" "example" {
18+
end_point_service_name = "tf-example"
19+
vpc_id = "vpc-9r35gtih"
2020
auto_accept_flag = false
21-
service_instance_id = "lb-o5f6x7ke"
2221
service_type = "CLB"
22+
service_instance_id = "lb-jvb31e26"
2323
}
2424
```
2525

@@ -47,9 +47,9 @@ In addition to all arguments above, the following attributes are exported:
4747

4848
## Import
4949

50-
vpc end_point_service can be imported using the id, e.g.
50+
VPC end point service can be imported using the id, e.g.
5151

5252
```
53-
terraform import tencentcloud_vpc_end_point_service.end_point_service end_point_service_id
53+
terraform import tencentcloud_vpc_end_point_service.example vpcsvc-l770dxs5
5454
```
5555

0 commit comments

Comments
 (0)
Please sign in to comment.