Skip to content

Commit

Permalink
Merge pull request #1190 from joshuaspence/asg-az
Browse files Browse the repository at this point in the history
Suppress diffs when an empty set is specified for `aws_autoscaling_group.availability_zones`
  • Loading branch information
radeksimko authored Jul 24, 2017
2 parents 5a4a6cb + 4147c1e commit b08118c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 5 deletions.
10 changes: 10 additions & 0 deletions aws/diff_suppress_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,13 @@ func suppressOpenIdURL(k, old, new string, d *schema.ResourceData) bool {

return oldUrl.String() == newUrl.String()
}

func suppressAutoscalingGroupAvailabilityZoneDiffs(k, old, new string, d *schema.ResourceData) bool {
// If VPC zone identifiers are provided then there is no need to explicitly
// specify availability zones.
if _, ok := d.GetOk("vpc_zone_identifier"); ok {
return true
}

return false
}
11 changes: 6 additions & 5 deletions aws/resource_aws_autoscaling_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ func resourceAwsAutoscalingGroup() *schema.Resource {
},

"availability_zones": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
DiffSuppressFunc: suppressAutoscalingGroupAvailabilityZoneDiffs,
},

"placement_group": {
Expand Down
45 changes: 45 additions & 0 deletions aws/resource_aws_autoscaling_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,26 @@ func TestAccAWSAutoScalingGroup_classicVpcZoneIdentifier(t *testing.T) {
})
}

func TestAccAWSAutoScalingGroup_emptyAvailabilityZones(t *testing.T) {
var group autoscaling.Group

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
IDRefreshName: "aws_autoscaling_group.test",
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSAutoScalingGroupDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSAutoScalingGroupConfig_emptyAvailabilityZones,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.test", &group),
resource.TestCheckResourceAttr("aws_autoscaling_group.test", "availability_zones.#", "1"),
),
},
},
})
}

const testAccAWSAutoScalingGroupConfig_autoGeneratedName = `
resource "aws_launch_configuration" "foobar" {
image_id = "ami-21f78e11"
Expand Down Expand Up @@ -1826,3 +1846,28 @@ resource "aws_launch_configuration" "test" {
instance_type = "t1.micro"
}
`

const testAccAWSAutoScalingGroupConfig_emptyAvailabilityZones = `
resource "aws_vpc" "test" {
cidr_block = "10.0.0.0/16"
}
resource "aws_subnet" "test" {
vpc_id = "${aws_vpc.test.id}"
cidr_block = "10.0.0.0/16"
}
resource "aws_autoscaling_group" "test" {
min_size = 0
max_size = 0
availability_zones = []
launch_configuration = "${aws_launch_configuration.test.name}"
vpc_zone_identifier = ["${aws_subnet.test.id}"]
}
resource "aws_launch_configuration" "test" {
image_id = "ami-21f78e11"
instance_type = "t1.micro"
}
`

0 comments on commit b08118c

Please sign in to comment.