Skip to content

Commit

Permalink
Merge pull request #1191 from joshuaspence/classic-vpczoneidentifier
Browse files Browse the repository at this point in the history
Fix handling of `vpc_zone_identifier` for autoscaling groups in EC2 classic
  • Loading branch information
radeksimko authored Jul 20, 2017
2 parents 9680e02 + 88c2511 commit deb3eef
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
7 changes: 6 additions & 1 deletion aws/resource_aws_autoscaling_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,12 @@ func resourceAwsAutoscalingGroupRead(d *schema.ResourceData, meta interface{}) e
d.Set("tag", autoscalingTagDescriptionsToSlice(g.Tags))
}

d.Set("vpc_zone_identifier", strings.Split(*g.VPCZoneIdentifier, ","))
if len(*g.VPCZoneIdentifier) > 0 {
d.Set("vpc_zone_identifier", strings.Split(*g.VPCZoneIdentifier, ","))
} else {
d.Set("vpc_zone_identifier", []string{})
}

d.Set("protect_from_scale_in", g.NewInstancesProtectedFromScaleIn)

// If no termination polices are explicitly configured and the upstream state
Expand Down
36 changes: 36 additions & 0 deletions aws/resource_aws_autoscaling_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,26 @@ func testAccCheckAWSALBTargetGroupHealthy(res *elbv2.TargetGroup) resource.TestC
}
}

func TestAccAWSAutoScalingGroup_classicVpcZoneIdentifier(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_classicVpcZoneIdentifier,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.test", &group),
resource.TestCheckResourceAttr("aws_autoscaling_group.test", "vpc_zone_identifier.#", "0"),
),
},
},
})
}

const testAccAWSAutoScalingGroupConfig_autoGeneratedName = `
resource "aws_launch_configuration" "foobar" {
image_id = "ami-21f78e11"
Expand Down Expand Up @@ -1790,3 +1810,19 @@ resource "aws_autoscaling_group" "bar" {
}
`, name, name)
}

const testAccAWSAutoScalingGroupConfig_classicVpcZoneIdentifier = `
resource "aws_autoscaling_group" "test" {
min_size = 0
max_size = 0
availability_zones = ["us-west-2a"]
launch_configuration = "${aws_launch_configuration.test.name}"
vpc_zone_identifier = []
}
resource "aws_launch_configuration" "test" {
image_id = "ami-21f78e11"
instance_type = "t1.micro"
}
`

0 comments on commit deb3eef

Please sign in to comment.