Skip to content

Commit

Permalink
Merge pull request #20708 from nitrocode/asg-initial_lifecycle_hook-F…
Browse files Browse the repository at this point in the history
…orceNew

aws_autoscaling_group `initial_lifecycle_hook` set `ForceNew: true`
  • Loading branch information
YakDriver authored Mar 25, 2022
2 parents a6d199c + 93e0f49 commit 1af230d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 36 deletions.
3 changes: 3 additions & 0 deletions .changelog/20708.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_autoscaling_group: Fix issue where group was not recreated if `initial_lifecycle_hook` changed
```
1 change: 1 addition & 0 deletions internal/service/autoscaling/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ func ResourceGroup() *schema.Resource {
"initial_lifecycle_hook": {
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Expand Down
76 changes: 40 additions & 36 deletions internal/service/autoscaling/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ func TestAccAutoScalingGroup_ALB_targetGroups(t *testing.T) {
var group autoscaling.Group
var tg elbv2.TargetGroup
var tg2 elbv2.TargetGroup
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

testCheck := func(targets []*elbv2.TargetGroup) resource.TestCheckFunc {
return func(*terraform.State) error {
Expand Down Expand Up @@ -769,7 +770,7 @@ func TestAccAutoScalingGroup_ALB_targetGroups(t *testing.T) {
CheckDestroy: testAccCheckGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccGroupConfig_ALB_TargetGroup_pre(),
Config: testAccGroupConfig_ALB_TargetGroup_pre(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckGroupExists("aws_autoscaling_group.bar", &group),
testAccCheckLBTargetGroupExists("aws_lb_target_group.test", &tg),
Expand All @@ -779,7 +780,7 @@ func TestAccAutoScalingGroup_ALB_targetGroups(t *testing.T) {
},

{
Config: testAccGroupConfig_ALB_TargetGroup_post_duo(),
Config: testAccGroupConfig_ALB_TargetGroup_post_duo(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckGroupExists("aws_autoscaling_group.bar", &group),
testAccCheckLBTargetGroupExists("aws_lb_target_group.test", &tg),
Expand All @@ -803,7 +804,7 @@ func TestAccAutoScalingGroup_ALB_targetGroups(t *testing.T) {
},
},
{
Config: testAccGroupConfig_ALB_TargetGroup_post(),
Config: testAccGroupConfig_ALB_TargetGroup_post(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckGroupExists("aws_autoscaling_group.bar", &group),
testAccCheckLBTargetGroupExists("aws_lb_target_group.test", &tg),
Expand Down Expand Up @@ -3085,9 +3086,10 @@ resource "aws_autoscaling_group" "bar" {
`)
}

func testAccGroupConfig_ALB_TargetGroup_pre() string {
return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptInDefaultExclude(),
`
func testAccGroupConfig_ALB_TargetGroup_pre(rName string) string {
return acctest.ConfigCompose(
acctest.ConfigAvailableAZsNoOptInDefaultExclude(),
fmt.Sprintf(`
resource "aws_vpc" "default" {
cidr_block = "10.0.0.0/16"
Expand All @@ -3097,7 +3099,7 @@ resource "aws_vpc" "default" {
}
resource "aws_lb_target_group" "test" {
name = "tf-example-alb-tg"
name = %[1]q
port = 80
protocol = "HTTP"
vpc_id = aws_vpc.default.id
Expand All @@ -3109,7 +3111,7 @@ resource "aws_subnet" "main" {
availability_zone = data.aws_availability_zones.available.names[0]
tags = {
Name = "tf-acc-autoscaling-group-alb-target-group-main"
Name = %[1]q
}
}
Expand All @@ -3119,7 +3121,7 @@ resource "aws_subnet" "alt" {
availability_zone = data.aws_availability_zones.available.names[1]
tags = {
Name = "tf-acc-autoscaling-group-alb-target-group-alt"
Name = %[1]q
}
}
Expand Down Expand Up @@ -3156,8 +3158,8 @@ resource "aws_autoscaling_group" "bar" {
}
resource "aws_security_group" "tf_test_self" {
name = "tf_test_alb_asg"
description = "tf_test_alb_asg"
name = %[1]q
description = %[1]q
vpc_id = aws_vpc.default.id
ingress {
Expand All @@ -3168,25 +3170,26 @@ resource "aws_security_group" "tf_test_self" {
}
tags = {
Name = "testAccAWSAutoScalingGroupConfig_ALB_TargetGroup"
Name = %[1]q
}
}
`)
`, rName))
}

func testAccGroupConfig_ALB_TargetGroup_post() string {
return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptInDefaultExclude(),
`
func testAccGroupConfig_ALB_TargetGroup_post(rName string) string {
return acctest.ConfigCompose(
acctest.ConfigAvailableAZsNoOptInDefaultExclude(),
fmt.Sprintf(`
resource "aws_vpc" "default" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "terraform-testacc-autoscaling-group-alb-target-group"
Name = %[1]q
}
}
resource "aws_lb_target_group" "test" {
name = "tf-example-alb-tg"
name = %[1]q
port = 80
protocol = "HTTP"
vpc_id = aws_vpc.default.id
Expand All @@ -3198,7 +3201,7 @@ resource "aws_subnet" "main" {
availability_zone = data.aws_availability_zones.available.names[0]
tags = {
Name = "tf-acc-autoscaling-group-alb-target-group-main"
Name = %[1]q
}
}
Expand All @@ -3208,7 +3211,7 @@ resource "aws_subnet" "alt" {
availability_zone = data.aws_availability_zones.available.names[1]
tags = {
Name = "tf-acc-autoscaling-group-alb-target-group-alt"
Name = "%[1]s-2"
}
}
Expand Down Expand Up @@ -3247,8 +3250,8 @@ resource "aws_autoscaling_group" "bar" {
}
resource "aws_security_group" "tf_test_self" {
name = "tf_test_alb_asg"
description = "tf_test_alb_asg"
name = %[1]q
description = %[1]q
vpc_id = aws_vpc.default.id
ingress {
Expand All @@ -3259,32 +3262,33 @@ resource "aws_security_group" "tf_test_self" {
}
tags = {
Name = "testAccAWSAutoScalingGroupConfig_ALB_TargetGroup"
Name = %[1]q
}
}
`)
`, rName))
}

func testAccGroupConfig_ALB_TargetGroup_post_duo() string {
return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptInDefaultExclude(),
`
func testAccGroupConfig_ALB_TargetGroup_post_duo(rName string) string {
return acctest.ConfigCompose(
acctest.ConfigAvailableAZsNoOptInDefaultExclude(),
fmt.Sprintf(`
resource "aws_vpc" "default" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "terraform-testacc-autoscaling-group-alb-target-group"
Name = %[1]q
}
}
resource "aws_lb_target_group" "test" {
name = "tf-example-alb-tg"
name = %[1]q
port = 80
protocol = "HTTP"
vpc_id = aws_vpc.default.id
}
resource "aws_lb_target_group" "test_more" {
name = "tf-example-alb-tg-more"
name = format("%%s-%%s", substr(%[1]q, 0, 28), "2")
port = 80
protocol = "HTTP"
vpc_id = aws_vpc.default.id
Expand All @@ -3296,7 +3300,7 @@ resource "aws_subnet" "main" {
availability_zone = data.aws_availability_zones.available.names[0]
tags = {
Name = "tf-acc-autoscaling-group-alb-target-group-main"
Name = %[1]q
}
}
Expand All @@ -3306,7 +3310,7 @@ resource "aws_subnet" "alt" {
availability_zone = data.aws_availability_zones.available.names[1]
tags = {
Name = "tf-acc-autoscaling-group-alb-target-group-alt"
Name = "%[1]s-2"
}
}
Expand Down Expand Up @@ -3348,8 +3352,8 @@ resource "aws_autoscaling_group" "bar" {
}
resource "aws_security_group" "tf_test_self" {
name = "tf_test_alb_asg"
description = "tf_test_alb_asg"
name = %[1]q
description = %[1]q
vpc_id = aws_vpc.default.id
ingress {
Expand All @@ -3360,10 +3364,10 @@ resource "aws_security_group" "tf_test_self" {
}
tags = {
Name = "testAccAWSAutoScalingGroupConfig_ALB_TargetGroup"
Name = %[1]q
}
}
`)
`, rName))
}

func testAccGroupConfig_TargetGroupARNs(rName string, tgCount int) string {
Expand Down

0 comments on commit 1af230d

Please sign in to comment.