@@ -100,17 +100,18 @@ func resourceTencentCloudEniIpv6AddressCreate(d *schema.ResourceData, meta inter
100
100
defer tccommon .LogElapsed ("resource.tencentcloud_eni_ipv6_address.create" )()
101
101
defer tccommon .InconsistentCheck (d , meta )()
102
102
103
- logId := tccommon .GetLogId (tccommon .ContextNil )
104
-
105
103
var (
104
+ logId = tccommon .GetLogId (tccommon .ContextNil )
105
+ ctx = context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
106
+ vpcService = VpcService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
106
107
request = vpc .NewAssignIpv6AddressesRequest ()
107
108
response = vpc .NewAssignIpv6AddressesResponse ()
108
109
networkInterfaceId string
109
110
)
110
111
111
112
if v , ok := d .GetOk ("network_interface_id" ); ok {
112
- networkInterfaceId = v .(string )
113
113
request .NetworkInterfaceId = helper .String (v .(string ))
114
+ networkInterfaceId = v .(string )
114
115
}
115
116
116
117
if v , ok := d .GetOk ("ipv6_addresses" ); ok {
@@ -120,21 +121,27 @@ func resourceTencentCloudEniIpv6AddressCreate(d *schema.ResourceData, meta inter
120
121
if v , ok := dMap ["address" ]; ok {
121
122
ipv6Address .Address = helper .String (v .(string ))
122
123
}
124
+
123
125
if v , ok := dMap ["primary" ]; ok {
124
126
ipv6Address .Primary = helper .Bool (v .(bool ))
125
127
}
128
+
126
129
if v , ok := dMap ["address_id" ]; ok {
127
130
ipv6Address .AddressId = helper .String (v .(string ))
128
131
}
132
+
129
133
if v , ok := dMap ["description" ]; ok {
130
134
ipv6Address .Description = helper .String (v .(string ))
131
135
}
136
+
132
137
if v , ok := dMap ["is_wan_ip_blocked" ]; ok {
133
138
ipv6Address .IsWanIpBlocked = helper .Bool (v .(bool ))
134
139
}
140
+
135
141
if v , ok := dMap ["state" ]; ok {
136
142
ipv6Address .State = helper .String (v .(string ))
137
143
}
144
+
138
145
request .Ipv6Addresses = append (request .Ipv6Addresses , & ipv6Address )
139
146
}
140
147
}
@@ -150,40 +157,51 @@ func resourceTencentCloudEniIpv6AddressCreate(d *schema.ResourceData, meta inter
150
157
} else {
151
158
log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
152
159
}
160
+
161
+ if result == nil || result .Response == nil {
162
+ return resource .NonRetryableError (fmt .Errorf ("Create vpc ipv6EniAddress failed, Response is nil." ))
163
+ }
164
+
153
165
response = result
154
166
return nil
155
167
})
168
+
156
169
if err != nil {
157
170
log .Printf ("[CRITAL]%s create vpc ipv6EniAddress failed, reason:%+v" , logId , err )
158
171
return err
159
172
}
160
173
161
- addressSet := response .Response .Ipv6AddressSet
162
- if len (addressSet ) < 1 {
174
+ if response .Response .Ipv6AddressSet == nil || len (response .Response .Ipv6AddressSet ) < 1 {
163
175
return fmt .Errorf ("assign ipv6 addresses failed." )
164
176
}
165
177
166
- time .Sleep (5 * time .Second )
167
-
168
178
d .SetId (networkInterfaceId )
169
179
180
+ // wait
181
+ if response .Response .RequestId != nil {
182
+ err = vpcService .DescribeVpcTaskResult (ctx , response .Response .RequestId )
183
+ if err != nil {
184
+ return err
185
+ }
186
+ } else {
187
+ time .Sleep (15 * time .Second )
188
+ }
189
+
170
190
return resourceTencentCloudEniIpv6AddressRead (d , meta )
171
191
}
172
192
173
193
func resourceTencentCloudEniIpv6AddressRead (d * schema.ResourceData , meta interface {}) error {
174
194
defer tccommon .LogElapsed ("resource.tencentcloud_eni_ipv6_address.read" )()
175
195
defer tccommon .InconsistentCheck (d , meta )()
176
196
177
- logId := tccommon .GetLogId (tccommon .ContextNil )
178
-
179
- ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
180
-
181
- service := VpcService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
182
-
183
- networkInterfaceId := d .Id ()
197
+ var (
198
+ logId = tccommon .GetLogId (tccommon .ContextNil )
199
+ ctx = context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
200
+ service = VpcService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
201
+ networkInterfaceId = d .Id ()
202
+ )
184
203
185
204
enis , err := service .DescribeEniById (ctx , []string {networkInterfaceId })
186
-
187
205
if err != nil {
188
206
return err
189
207
}
@@ -195,7 +213,6 @@ func resourceTencentCloudEniIpv6AddressRead(d *schema.ResourceData, meta interfa
195
213
}
196
214
197
215
eni := enis [0 ]
198
-
199
216
ipv6s := make ([]map [string ]interface {}, 0 , len (eni .Ipv6AddressSet ))
200
217
for _ , ipv6 := range eni .Ipv6AddressSet {
201
218
ipv6s = append (ipv6s , map [string ]interface {}{
@@ -219,14 +236,14 @@ func resourceTencentCloudEniIpv6AddressDelete(d *schema.ResourceData, meta inter
219
236
defer tccommon .LogElapsed ("resource.tencentcloud_eni_ipv6_address.delete" )()
220
237
defer tccommon .InconsistentCheck (d , meta )()
221
238
222
- logId := tccommon .GetLogId (tccommon .ContextNil )
223
- ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
224
-
225
- service := VpcService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
226
- networkInterfaceId := d .Id ()
239
+ var (
240
+ logId = tccommon .GetLogId (tccommon .ContextNil )
241
+ ctx = context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
242
+ service = VpcService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
243
+ networkInterfaceId = d .Id ()
244
+ )
227
245
228
246
enis , err := service .DescribeEniById (ctx , []string {networkInterfaceId })
229
-
230
247
if err != nil {
231
248
return err
232
249
}
0 commit comments