terraform-provider-aws: Cannot delete launch configuration because it is attached to AutoScalingGroup
Community Note
- Please vote on this issue by adding a π reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave β+1β or βme tooβ comments, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Terraform Version
terraform -v
Terraform v0.11.13
+ provider.aws v2.7.0
+ provider.null v2.1.1
+ provider.random v2.1.1
Affected Resource(s)
- aws_autoscaling_group
- aws_launch_configuration
Terraform Configuration Files
directory layout
.
βββ main.tf
βββ modules
βΒ Β βββ app
βΒ Β βββ terraform-aws-autoscaling
modules/app/main.tf
variable "private_subnets" {
type = "list"
}
variable "name" {}
variable "userdata" {}
module "app_asg" {
source = "../terraform-aws-autoscaling"
name = "${var.name}"
lc_name = "${var.name}"
asg_name = "${var.name}"
image_id = "ami-0e219142c0bee4a6e"
instance_type = "t2.micro"
root_block_device = [
{
volume_size = "10"
volume_type = "gp2"
delete_on_termination = true
},
]
user_data = "${var.userdata}"
vpc_zone_identifier = ["${var.private_subnets}"]
health_check_type = "EC2"
min_size = 1
max_size = 1
desired_capacity = 1
wait_for_capacity_timeout = 0
recreate_asg_when_lc_changes = true
}
main.tf
First apply with this configuration:
provider "aws" {
region = "eu-west-1"
}
module "app-001" {
source = "modules/app"
name = "app-001"
userdata = "echo hello there version 1"
}
Second apply with this configuration:
provider "aws" {
region = "eu-west-1"
}
module "app-001" {
source = "modules/app"
name = "app-001"
userdata = "echo hello there version 2" ## <- just changed this
}
Third apply with this configuration:
provider "aws" {
region = "eu-west-1"
}
# module "app-001" {
# source = "modules/app"
# name = "app-001"
# userdata = "echo hello there version 2" ## <- just changed this
# }
Debug Output
Panic Output
No
Expected Behavior
Terraform to apply the configuration and delete the commented out resources successfully.
Actual Behavior
Got an error:
module.app-001.app_asg.aws_autoscaling_group.this: Still destroying... (ID: app-001-tight-bengal-20190430102834949100000002, 1m0s elapsed)
module.app-001.app_asg.aws_autoscaling_group.this: Still destroying... (ID: app-001-tight-bengal-20190430102834949100000002, 1m10s elapsed)
module.app-001.module.app_asg.aws_autoscaling_group.this: Destruction complete after 1m15s
Error: Error applying plan:
1 error(s) occurred:
* module.app-001.module.app_asg.aws_launch_configuration.this (destroy): 1 error(s) occurred:
* aws_launch_configuration.this: error deleting Autoscaling Launch Configuration (app-001-20190430102834111500000001): ResourceInUse: Cannot delete launch configuration app-001-20190430102834111500000001 because it is attached to AutoScalingGroup app-001-tight-bengal-20190430102834949100000002
status code: 400, request id: 2f89b9c4-6b33-11e9-8d9d-711c4d69f590
Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
Steps to Reproduce
terraform apply- change configuration as stated above
terraform apply- change configuration as stated above, so we delete the module
terraform apply
Important Factoids
References
Opening a new issue, as the original one was closed.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 70
- Comments: 16 (3 by maintainers)
Commits related to this issue
- Remove the requirement for an ASG ASG's are flaky, and there is an open issue on the aws provider https://github.com/terraform-providers/terraform-provider-aws/issues/8485 This prevents terraform fr... — committed to dotmesh-io/dotscience-tf by deleted user 4 years ago
- try to fix https://github.com/hashicorp/terraform-provider-aws/issues/8485 — committed to deersheep330/terraform-aws-ecs-free-tier by deersheep330 3 years ago
- Fix deleting launch configuration because it is attached to AutoScalingGroup https://github.com/hashicorp/terraform-provider-aws/issues/8485 https://registry.terraform.io/providers/hashicorp/aws/la... — committed to yilinjuang/terraform-retool-modules by yilinjuang 2 years ago
I ran into this error as well and updated the LC/ASG resources as suggested by these Terraform docs.
Summary:
lifecycleblock withcreate_before_destroy = truein both LC and ASG resourcesname_prefixinstead ofnameTerraform and AWS provider versions:
This is a snippet from my working config in case anyone is interested (
var.create_before_destroy --> true):The punch line of this bug:
aws_launch_configurationβs attributenamebreaks theaws_autoscaling_groupdependency chain, when interpolated.Anytime
aws_launch_configurationhas a change, it needs to be recreated:(new resource required). Knowingaws_launch_configurationis immutable and their names need to be unique per region, interpolatingnameintoaws_autoscaling_groupshould always force a new resource if itβs being destroyed / created.Now the work around is to use
name_prefixinaws_launch_configurationinstead, asaws_autoscaling_grouprecognizes this interpolated change, and is able to update without destroyingaws_autoscaling_group(saving running instances in the process). EDIT: And addingcreate_before_destroy = true.Still an issue two years later β¦
Weβve started migrating from Launch Configurations to Launch Templates. We have to run TF twice to get the Launch Configurations to delete. I suspect these issues are related, but I can open a new issue if itβs requested.
TL;DWrite would be:
Is there a work around for this?