-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Apply fails when aws_autoscaling_group is into a module and its aws_launch_configuration changes. #11557
Comments
I am experiencing this as well (v0.8.5). In my case, as part of a blue/green deployment mechanism, I am issuing To provide more detail, when both resources are in the root module, running
Notice the 29 second delay between commencing ASG destruction and commencing LC destruction, implying the correct dependency graph. In contrast, when both resources are in a child module, Terraform attempts to destroy them at the same time:
Notice how destruction of both resources is commenced at the same time. Note, the bug does not occur when I issue Terraform Configuration 1: ASG and LC in root module
Terraform Configuration 2: ASG and LC in child modules
Note that the usual |
As of today, I have noticed that |
I have similar issues with both v0.8.4 and v0.8.6. Both my launch configuration and autoscaling group resources are inside modules. I have lifecycle create_before_destroy for both and pass the launch_config id as module output to module input of the module that has the autoscaling group. At initial creation everything is fine but if anything changes that forces recreation of the launch configuration I get the following:
|
I have similar issues in 0.8.6 using Here are detailed configs and logs for three cases:
In each case I attach the debug log output for the initial terraform apply and the debug log output for the modification of the launch config. Inline launch config name (works as expected)Terraform config: # Centos7 default
variable "image_id" {
default = "ami-bb373ddf"
}
provider "aws" {
region = "eu-west-2"
}
resource "aws_launch_configuration" "launch_configuration" {
image_id = "${var.image_id}"
instance_type = "t2.micro"
lifecycle {
create_before_destroy = true
}
}
resource "aws_cloudformation_stack" "all_zones_asg" {
name = "my-asg"
template_body = <<EOF
{
"Resources": {
"MyAsg": {
"Type": "AWS::AutoScaling::AutoScalingGroup",
"Properties": {
"AvailabilityZones": {"Fn::GetAZs": "eu-west-2"},
"LaunchConfigurationName": "${aws_launch_configuration.launch_configuration.name}",
"MaxSize": 2,
"MinSize": 2
},
"UpdatePolicy": {
"AutoScalingRollingUpdate": {
"MinInstancesInService": "1",
"MaxBatchSize": "1",
"PauseTime": "PT0S"
}
}
}
}
}
EOF
}
Launch config name as template variable (fails on recreation of launch_configuration)Terraform config: # Centos7 default
variable "image_id" {
default = "ami-bb373ddf"
}
provider "aws" {
region = "eu-west-2"
}
resource "aws_launch_configuration" "launch_configuration" {
image_id = "${var.image_id}"
instance_type = "t2.micro"
lifecycle {
create_before_destroy = true
}
}
resource "aws_cloudformation_stack" "all_zones_asg" {
name = "my-asg"
template_body = "${data.template_file.cloudformation_auto_scaling_group.rendered}"
}
data "template_file" "cloudformation_auto_scaling_group" {
template = "${file("./cf.tpl")}"
vars {
launch_configuration = "${aws_launch_configuration.launch_configuration.name}"
max_size = 2
min_size = 2
}
} Template:
Launch config name as module variable (fails on recreation of launch_configuration)Terraform config: # Centos7 default
variable "image_id" {
default = "ami-bb373ddf"
}
provider "aws" {
region = "eu-west-2"
}
resource "aws_launch_configuration" "launch_configuration" {
image_id = "${var.image_id}"
instance_type = "t2.micro"
lifecycle {
create_before_destroy = true
}
}
module "asg" {
source = "./modules/asg"
launch_config_name = "${aws_launch_configuration.launch_configuration.name}"
max_size = 2
min_size = 2
min_instances_in_service = 1
} Module: variable "launch_config_name" {}
variable "max_size" {}
variable "min_size" {}
variable "min_instances_in_service" {}
variable "max_batch_size" {
default = 1
}
variable "region" {
default = "eu-west-2"
}
resource "aws_cloudformation_stack" "multi_zone_rolling_upgrade_asg" {
name = "my-asg"
template_body = <<EOF
{
"Resources": {
"MyAsg": {
"Type": "AWS::AutoScaling::AutoScalingGroup",
"Properties": {
"AvailabilityZones": {"Fn::GetAZs": "${var.region}"},
"LaunchConfigurationName": "${var.launch_config_name}",
"MaxSize": ${var.max_size},
"MinSize": ${var.min_size}
},
"UpdatePolicy": {
"AutoScalingRollingUpdate": {
"MinInstancesInService": ${var.min_instances_in_service},
"MaxBatchSize": ${var.max_batch_size}
}
}
}
}
}
EOF
}
Notes
|
After a bunch of investigation I've figured out where the bug lies and a workaround for now. By using |
@theramis We used your workaround |
Can you confirm that it works too when using Something like: |
Confirmed hitting this on 0.8.6. Same situation as others, using launch configuration and ASGs inside modules. |
Just to confirm that |
this is nasty...
Maybe due to using the plan/apply outfile behavior? e.g. I can use So I still reprod the issue when doing a plan/apply that way |
@eedwardsdisco I'm using this is how my command is structured. I think from memory having the |
@theramis Aha! I just confirmed I was using I will try your suggestion. I would certainly prefer that this was limited to the new graphing structure, good repros are always easier to fix ;) |
I've confirmed it's still broken in 0.9.0 |
Still broken in 0.9.5. Causing mayhem with our deploys today as we roll out patched Windows AMIs to 200+ ASGs. Also appears to be a duplicate of #13517 |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Terraform Version
Terraform v0.8.5
Affected Resource(s)
Terraform Configuration Files
The
main.tf
file:The
aws_autoscaling_group_module
module file:Debug Output
https://gist.github.com/jordiclariana/151f1d04c32b60c856fab970ab560bd7
Expected Behavior
It is expected to work the first time, and also when you change
aws_launch_configuration
andapply
again.Actual Behavior
It works the first time, but if run after changing the
aws_launch_configuration
we get this message:Steps to Reproduce
terraform apply
aws_launch_configuration.aws_lc
(like for instance, changeinstance_type
from t2.small to t2.medium)terraform apply
again. We then get the error.References
This is related with #1109, and the proposed solution (add the lifecycle parameter) normally works, but when the aws_autoscaling_group is into a separated module it fails.
The text was updated successfully, but these errors were encountered: