@@ -93,13 +93,13 @@ func resourceTencentCloudVpcEndPointServiceCreate(d *schema.ResourceData, meta i
93
93
defer tccommon .LogElapsed ("resource.tencentcloud_vpc_end_point_service.create" )()
94
94
defer tccommon .InconsistentCheck (d , meta )()
95
95
96
- logId := tccommon .GetLogId (tccommon .ContextNil )
97
-
98
96
var (
97
+ logId = tccommon .GetLogId (tccommon .ContextNil )
99
98
request = vpc .NewCreateVpcEndPointServiceRequest ()
100
99
response = vpc .NewCreateVpcEndPointServiceResponse ()
101
100
endPointServiceId string
102
101
)
102
+
103
103
if v , ok := d .GetOk ("vpc_id" ); ok {
104
104
request .VpcId = helper .String (v .(string ))
105
105
}
@@ -108,7 +108,7 @@ func resourceTencentCloudVpcEndPointServiceCreate(d *schema.ResourceData, meta i
108
108
request .EndPointServiceName = helper .String (v .(string ))
109
109
}
110
110
111
- if v , _ := d .GetOk ("auto_accept_flag" ); v != nil {
111
+ if v , ok := d .GetOkExists ("auto_accept_flag" ); ok {
112
112
request .AutoAcceptFlag = helper .Bool (v .(bool ))
113
113
}
114
114
@@ -127,14 +127,24 @@ func resourceTencentCloudVpcEndPointServiceCreate(d *schema.ResourceData, meta i
127
127
} else {
128
128
log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
129
129
}
130
+
131
+ if result == nil || result .Response == nil {
132
+ return resource .RetryableError (fmt .Errorf ("Create vpc endPointService failed, Response is nil." ))
133
+ }
134
+
130
135
response = result
131
136
return nil
132
137
})
138
+
133
139
if err != nil {
134
140
log .Printf ("[CRITAL]%s create vpc endPointService failed, reason:%+v" , logId , err )
135
141
return err
136
142
}
137
143
144
+ if response .Response .EndPointService == nil || response .Response .EndPointService .EndPointServiceId == nil {
145
+ return fmt .Errorf ("EndPointServiceId is nil." )
146
+ }
147
+
138
148
endPointServiceId = * response .Response .EndPointService .EndPointServiceId
139
149
d .SetId (endPointServiceId )
140
150
@@ -145,16 +155,14 @@ func resourceTencentCloudVpcEndPointServiceRead(d *schema.ResourceData, meta int
145
155
defer tccommon .LogElapsed ("resource.tencentcloud_vpc_end_point_service.read" )()
146
156
defer tccommon .InconsistentCheck (d , meta )()
147
157
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
+ )
155
164
156
165
endPointService , err := service .DescribeVpcEndPointServiceById (ctx , endPointServiceId )
157
-
158
166
if err != nil {
159
167
return err
160
168
}
@@ -211,36 +219,37 @@ func resourceTencentCloudVpcEndPointServiceUpdate(d *schema.ResourceData, meta i
211
219
defer tccommon .LogElapsed ("resource.tencentcloud_vpc_end_point_service.update" )()
212
220
defer tccommon .InconsistentCheck (d , meta )()
213
221
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
+ )
225
227
226
228
unsupportedUpdateFields := []string {
227
229
"vpc_id" ,
228
230
"service_type" ,
229
231
}
232
+
230
233
for _ , field := range unsupportedUpdateFields {
231
234
if d .HasChange (field ) {
232
235
return fmt .Errorf ("tencentcloud_vpc_end_point_service update on %s is not support yet" , field )
233
236
}
234
237
}
235
238
239
+ request .EndPointServiceId = & endPointServiceId
240
+
241
+ if v , ok := d .GetOk ("vpc_id" ); ok {
242
+ request .VpcId = helper .String (v .(string ))
243
+ }
244
+
236
245
if d .HasChange ("end_point_service_name" ) {
237
246
if v , ok := d .GetOk ("end_point_service_name" ); ok {
238
247
request .EndPointServiceName = helper .String (v .(string ))
239
248
}
240
249
}
241
250
242
251
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 {
244
253
request .AutoAcceptFlag = helper .Bool (v .(bool ))
245
254
}
246
255
}
@@ -258,8 +267,10 @@ func resourceTencentCloudVpcEndPointServiceUpdate(d *schema.ResourceData, meta i
258
267
} else {
259
268
log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
260
269
}
270
+
261
271
return nil
262
272
})
273
+
263
274
if err != nil {
264
275
log .Printf ("[CRITAL]%s create vpc endPointService failed, reason:%+v" , logId , err )
265
276
return err
@@ -272,11 +283,12 @@ func resourceTencentCloudVpcEndPointServiceDelete(d *schema.ResourceData, meta i
272
283
defer tccommon .LogElapsed ("resource.tencentcloud_vpc_end_point_service.delete" )()
273
284
defer tccommon .InconsistentCheck (d , meta )()
274
285
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
+ )
280
292
281
293
if err := service .DeleteVpcEndPointServiceById (ctx , endPointServiceId ); err != nil {
282
294
return nil
0 commit comments