@@ -440,6 +440,7 @@ func Setup(fieldsMap map[commons.FieldName]*commons.GenericField) {
440
440
Elem : & schema.Schema {Type : schema .TypeString },
441
441
ConflictsWith : []string {string (AvailabilityZones )},
442
442
Optional : true ,
443
+ Deprecated : "This field will soon be deprecated and handled by availability_zones" ,
443
444
},
444
445
func (resourceObject interface {}, resourceData * schema.ResourceData , meta interface {}) error {
445
446
egWrapper := resourceObject .(* commons.ElastigroupWrapper )
@@ -536,39 +537,65 @@ func Setup(fieldsMap map[commons.FieldName]*commons.GenericField) {
536
537
AvailabilityZones ,
537
538
& schema.Schema {
538
539
Type : schema .TypeList ,
539
- Elem : & schema.Schema {Type : schema .TypeString },
540
540
Optional : true ,
541
+ Elem : & schema.Resource {
542
+ Schema : map [string ]* schema.Schema {
543
+ string (SubnetIDs ): {
544
+ Type : schema .TypeList ,
545
+ Optional : true ,
546
+ Elem : & schema.Schema {
547
+ Type : schema .TypeString },
548
+ },
549
+ string (AvailabilityZoneName ): {
550
+ Type : schema .TypeString ,
551
+ Required : true ,
552
+ },
553
+ string (PlacementGroupName ): {
554
+ Type : schema .TypeString ,
555
+ Optional : true ,
556
+ },
557
+ },
558
+ },
541
559
},
542
560
func (resourceObject interface {}, resourceData * schema.ResourceData , meta interface {}) error {
543
- // Skip
561
+ egWrapper := resourceObject .(* commons.ElastigroupWrapper )
562
+ elastigroup := egWrapper .GetElastigroup ()
563
+ var result []interface {} = nil
564
+ if elastigroup .Compute != nil && elastigroup .Compute .AvailabilityZones != nil {
565
+ az := elastigroup .Compute .AvailabilityZones
566
+ result = flattenAvailabilityZones (az )
567
+ }
568
+ if result != nil {
569
+ if err := resourceData .Set (string (AvailabilityZones ), result ); err != nil {
570
+ return fmt .Errorf ("failed to set availabilityZone configuration: %#v" , err )
571
+ }
572
+ }
544
573
return nil
545
574
},
546
575
func (resourceObject interface {}, resourceData * schema.ResourceData , meta interface {}) error {
547
576
egWrapper := resourceObject .(* commons.ElastigroupWrapper )
548
577
elastigroup := egWrapper .GetElastigroup ()
549
- if _ , exists := resourceData .GetOk (string (SubnetIDs )); ! exists {
550
- if value , ok := resourceData .GetOk (string (AvailabilityZones )); ok {
551
- if zones , err := expandAvailabilityZonesSlice (value ); err != nil {
552
- return err
553
- } else {
554
- elastigroup .Compute .SetAvailabilityZones (zones )
555
- }
578
+ if v , ok := resourceData .GetOk (string (AvailabilityZones )); ok {
579
+ if availabilityZones , err := expandAvailabilityZones (v ); err != nil {
580
+ return err
581
+ } else {
582
+ elastigroup .Compute .SetAvailabilityZones (availabilityZones )
556
583
}
557
584
}
558
585
return nil
559
586
},
560
587
func (resourceObject interface {}, resourceData * schema.ResourceData , meta interface {}) error {
561
588
egWrapper := resourceObject .(* commons.ElastigroupWrapper )
562
589
elastigroup := egWrapper .GetElastigroup ()
563
- if _ , exists := resourceData .GetOk (string (SubnetIDs )); ! exists {
564
- if value , ok := resourceData .GetOk (string (AvailabilityZones )); ok {
565
- if zones , err := expandAvailabilityZonesSlice (value ); err != nil {
566
- return err
567
- } else {
568
- elastigroup .Compute .SetAvailabilityZones (zones )
569
- }
590
+ var result []* aws.AvailabilityZone = nil
591
+ if v , ok := resourceData .GetOk (string (AvailabilityZones )); ok {
592
+ if availabilityZones , err := expandAvailabilityZones (v ); err != nil {
593
+ return err
594
+ } else {
595
+ result = availabilityZones
570
596
}
571
597
}
598
+ elastigroup .Compute .SetAvailabilityZones (result )
572
599
return nil
573
600
},
574
601
nil ,
@@ -1384,3 +1411,49 @@ func extractTargetGroupFromArn(arn string) (string, error) {
1384
1411
}
1385
1412
return name , nil
1386
1413
}
1414
+
1415
+ func expandAvailabilityZones (data interface {}) ([]* aws.AvailabilityZone , error ) {
1416
+ if list := data .([]interface {}); len (list ) > 0 {
1417
+ availabilityZones := make ([]* aws.AvailabilityZone , 0 , len (list ))
1418
+ for _ , item := range list {
1419
+ m := item .(map [string ]interface {})
1420
+ availabilityZone := & aws.AvailabilityZone {}
1421
+
1422
+ if v , ok := m [string (AvailabilityZoneName )].(string ); ok && v != "" {
1423
+ availabilityZone .SetName (spotinst .String (v ))
1424
+ }
1425
+
1426
+ if v , ok := m [string (PlacementGroupName )].(string ); ok && v != "" {
1427
+ availabilityZone .SetPlacementGroupName (spotinst .String (v ))
1428
+ }
1429
+
1430
+ if v , ok := m [string (SubnetIDs )]; ok && len (v .([]interface {})) > 0 {
1431
+ if subnetIDs , err := expandSubnetIDs (v ); err != nil {
1432
+ return nil , err
1433
+ } else {
1434
+ availabilityZone .SetSubnetIDs (subnetIDs )
1435
+ }
1436
+ }
1437
+ availabilityZones = append (availabilityZones , availabilityZone )
1438
+ }
1439
+ return availabilityZones , nil
1440
+ }
1441
+ return nil , nil
1442
+
1443
+ }
1444
+
1445
+ func flattenAvailabilityZones (availabilityZones []* aws.AvailabilityZone ) []interface {} {
1446
+ result := make ([]interface {}, 0 , len (availabilityZones ))
1447
+
1448
+ for _ , availabilityZone := range availabilityZones {
1449
+ m := make (map [string ]interface {})
1450
+ if availabilityZone .SubnetIDs != nil {
1451
+ m [string (SubnetIDs )] = spotinst .StringSlice (availabilityZone .SubnetIDs )
1452
+ }
1453
+ m [string (AvailabilityZoneName )] = spotinst .StringValue (availabilityZone .Name )
1454
+ m [string (PlacementGroupName )] = spotinst .StringValue (availabilityZone .PlacementGroupName )
1455
+
1456
+ result = append (result , m )
1457
+ }
1458
+ return result
1459
+ }
0 commit comments