@@ -65,7 +65,6 @@ func resourceTencentCloudEipAssociation() *schema.Resource {
65
65
Type : schema .TypeString ,
66
66
ForceNew : true ,
67
67
Optional : true ,
68
- Computed : true ,
69
68
ConflictsWith : []string {
70
69
"network_interface_id" ,
71
70
"private_ip" ,
@@ -77,7 +76,6 @@ func resourceTencentCloudEipAssociation() *schema.Resource {
77
76
Type : schema .TypeString ,
78
77
ForceNew : true ,
79
78
Optional : true ,
80
- Computed : true ,
81
79
ValidateFunc : validateStringLengthInRange (1 , 25 ),
82
80
ConflictsWith : []string {
83
81
"instance_id" ,
@@ -88,7 +86,6 @@ func resourceTencentCloudEipAssociation() *schema.Resource {
88
86
Type : schema .TypeString ,
89
87
ForceNew : true ,
90
88
Optional : true ,
91
- Computed : true ,
92
89
ValidateFunc : validateStringLengthInRange (7 , 25 ),
93
90
ConflictsWith : []string {
94
91
"instance_id" ,
@@ -239,24 +236,38 @@ func resourceTencentCloudEipAssociationRead(d *schema.ResourceData, meta interfa
239
236
if errRet != nil {
240
237
return retryError (errRet )
241
238
}
242
- if eip == nil {
239
+ if eip == nil || * eip . AddressStatus == EIP_STATUS_UNBIND {
243
240
d .SetId ("" )
241
+ return nil
242
+ }
243
+ // there is no easy way to ensure eip been bound to desired resource as all the InstanceId/NetworkInterfaceId/PrivateAddressIp fields been populated once bound
244
+ // eg: user want bind eip to cvm, but it's bound to the secondary eni of the same cvm instead, the only way to distinguish is by checking whether the eni is primary or not
245
+ d .Set ("eip_id" , * eip .AddressId )
246
+ // associate with instance
247
+ if len (association .InstanceId ) > 0 {
248
+ if eip .InstanceId != nil {
249
+ d .Set ("instance_id" , * eip .InstanceId )
250
+ } else {
251
+ d .Set ("instance_id" , "" )
252
+ }
253
+ } else {
254
+ if eip .NetworkInterfaceId != nil {
255
+ d .Set ("network_interface_id" , * eip .NetworkInterfaceId )
256
+ } else {
257
+ d .Set ("network_interface_id" , "" )
258
+ }
259
+ if eip .PrivateAddressIp != nil {
260
+ d .Set ("private_ip" , * eip .PrivateAddressIp )
261
+ } else {
262
+ d .Set ("private_ip" , "" )
263
+ }
244
264
}
245
265
return nil
246
266
})
247
267
if err != nil {
248
268
return err
249
269
}
250
270
251
- _ = d .Set ("eip_id" , association .EipId )
252
- // associate with instance
253
- if len (association .InstanceId ) > 0 {
254
- _ = d .Set ("instance_id" , association .InstanceId )
255
- return nil
256
- }
257
-
258
- _ = d .Set ("network_interface_id" , association .NetworkInterfaceId )
259
- _ = d .Set ("private_ip" , association .PrivateIp )
260
271
return nil
261
272
}
262
273
0 commit comments