@@ -33,8 +33,8 @@ func resourceLoadBalancer() *schema.Resource {
33
33
Delete : schema .DefaultTimeout (5 * time .Minute ),
34
34
},
35
35
Importer : & schema.ResourceImporter {
36
- StateContext : func (ctx context.Context , d * schema.ResourceData , meta interface {}) ([]* schema.ResourceData , error ) {
37
- projectID , regionID , lbID , err := ImportStringParser (d .Id ())
36
+ StateContext : func (ctx context.Context , d * schema.ResourceData , m interface {}) ([]* schema.ResourceData , error ) {
37
+ projectID , regionID , lbID , listenerID , err := ImportStringParserExtended (d .Id ())
38
38
39
39
if err != nil {
40
40
return nil , err
@@ -43,6 +43,24 @@ func resourceLoadBalancer() *schema.Resource {
43
43
d .Set ("region_id" , regionID )
44
44
d .SetId (lbID )
45
45
46
+ config := m .(* Config )
47
+ provider := config .Provider
48
+
49
+ listenersClient , err := CreateClient (provider , d , LBListenersPoint , versionPointV1 )
50
+ if err != nil {
51
+ return nil , err
52
+ }
53
+
54
+ listener , err := listeners .Get (listenersClient , listenerID ).Extract ()
55
+ if err != nil {
56
+ return nil , err
57
+ }
58
+
59
+ l := extractListenerIntoMap (listener )
60
+ if err := d .Set ("listener" , []interface {}{l }); err != nil {
61
+ return nil , err
62
+ }
63
+
46
64
return []* schema.ResourceData {d }, nil
47
65
},
48
66
},
@@ -278,12 +296,13 @@ func resourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, m int
278
296
d .Set ("project_id" , lb .ProjectID )
279
297
d .Set ("region_id" , lb .RegionID )
280
298
d .Set ("name" , lb .Name )
299
+ d .Set ("flavor" , lb .Flavor .FlavorName )
281
300
282
301
if lb .VipAddress != nil {
283
302
d .Set ("vip_address" , lb .VipAddress .String ())
284
303
}
285
304
286
- fields := []string {"flavor" , " vip_network_id" , "vip_subnet_id" }
305
+ fields := []string {"vip_network_id" , "vip_subnet_id" }
287
306
revertState (d , & fields )
288
307
289
308
listenersClient , err := CreateClient (provider , d , LBListenersPoint , versionPointV1 )
@@ -307,14 +326,9 @@ func resourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, m int
307
326
if err != nil {
308
327
return diag .FromErr (err )
309
328
}
310
-
311
- if listener .ProtocolPort == currentL ["protocol_port" ].(int ) && listener .Protocol .String () == currentL ["protocol" ] {
312
- currentL ["id" ] = listener .ID
313
- currentL ["name" ] = listener .Name
314
- currentL ["protocol" ] = listener .Protocol .String ()
315
- currentL ["protocol_port" ] = listener .ProtocolPort
316
- currentL ["secret_id" ] = listener .SecretID
317
- currentL ["sni_secret_id" ] = listener .SNISecretID
329
+ port , _ := currentL ["protocol_port" ].(int )
330
+ if (listener .ProtocolPort == port && listener .Protocol .String () == currentL ["protocol" ]) || len (cls ) == 0 {
331
+ currentL = extractListenerIntoMap (listener )
318
332
break
319
333
}
320
334
}
0 commit comments