Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress diffs when an empty set is specified for aws_autoscaling_group.availability_zones #1190

Merged
merged 1 commit into from
Jul 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
`