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

aws_autoscaling_group initial_lifecycle_hook set ForceNew: true #20708

Merged
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
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