@@ -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
0 commit comments