providers/aws: handle empty list configs, weird lb special case

This commit is contained in:
Jack Pearkes 2014-07-09 19:30:39 -04:00
parent 62a311a341
commit 930e3260ad
2 changed files with 15 additions and 8 deletions

View File

@ -21,7 +21,6 @@ func resource_aws_autoscaling_group_create(
// Merge the diff into the state so that we have all the attributes
// properly.
rs := s.MergeDiff(d)
log.Println(rs.Attributes["availability_zones"])
var err error
autoScalingGroupOpts := autoscaling.CreateAutoScalingGroup{}
@ -50,17 +49,17 @@ func resource_aws_autoscaling_group_create(
return nil, fmt.Errorf("Error parsing configuration: %s", err)
}
if rs.Attributes["availability_zones"] != "" {
if _, ok := rs.Attributes["availability_zones.#"]; ok {
autoScalingGroupOpts.AvailZone = expandStringList(flatmap.Expand(
rs.Attributes, "availability_zones").([]interface{}))
}
if rs.Attributes["load_balancers"] != "" {
if _, ok := rs.Attributes["load_balancers.#"]; ok {
autoScalingGroupOpts.LoadBalancerNames = expandStringList(flatmap.Expand(
rs.Attributes, "load_balancers").([]interface{}))
}
if rs.Attributes["vpc_identifier"] != "" {
if _, ok := rs.Attributes["vpc_identifier.#"]; ok {
autoScalingGroupOpts.VPCZoneIdentifier = expandStringList(flatmap.Expand(
rs.Attributes, "vpc_identifier").([]interface{}))
}
@ -154,7 +153,7 @@ func resource_aws_autoscaling_group_diff(
"launch_configuration": diff.AttrTypeCreate,
"vpc_zone_identifier": diff.AttrTypeCreate,
"load_balancers": diff.AttrTypeCreate,
"availability_zones": diff.AttrTypeCreate,
"availability_zone": diff.AttrTypeCreate,
},
ComputedAttrs: []string{},
@ -177,9 +176,15 @@ func resource_aws_autoscaling_group_update_state(
s.Attributes["launch_configuration"] = g.LaunchConfigurationName
s.Attributes["vpc_zone_identifier"] = g.VPCZoneIdentifier
// Flatten our sg values
// Flatten our group values
toFlatten := make(map[string]interface{})
toFlatten["load_balancers"] = flattenLoadBalancers(g.LoadBalancerNames)
// Special case the return of amazons load balancers names in the XML having
// a blank entry
if len(g.LoadBalancerNames) > 0 && g.LoadBalancerNames[0].LoadBalancerName != "" {
toFlatten["load_balancers"] = flattenLoadBalancers(g.LoadBalancerNames)
}
toFlatten["availability_zones"] = flattenAvailabilityZones(g.AvailabilityZones)
for k, v := range flatmap.Flatten(toFlatten) {

View File

@ -106,7 +106,9 @@ func flattenAvailabilityZones(list []autoscaling.AvailabilityZone) []string {
func flattenLoadBalancers(list []autoscaling.LoadBalancerName) []string {
result := make([]string, 0, len(list))
for _, g := range list {
result = append(result, g.LoadBalancerName)
if g.LoadBalancerName != "" {
result = append(result, g.LoadBalancerName)
}
}
return result
}