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

After import aws_autoscaling_group terraform plan doesn't show load_balancers diff #5197

Closed
savankumargudaas opened this issue Jul 14, 2018 · 7 comments · Fixed by #9478
Closed
Labels
bug Addresses a defect in current functionality. service/autoscaling Issues and PRs that pertain to the autoscaling service.
Milestone

Comments

@savankumargudaas
Copy link

Hi!

Let me give a background

I imported ASG against my local terraform resource file. ASG in AWS have couple of ELB(classic) association. I can see that imported state contains ELB related information.

When I run plan, plan doesn't show any difference of load_balancers.

asg.tf
resource "aws_autoscaling_group" "existing-asg" {
...//without load_balancers value
}

terraform import aws_autoscaling_group.existing-asg existing-asg-name

terraform state show aws_autoscaling_group.existing-asg
...
load_balancers.#                   = 2
load_balancers.1433097967          = first-elb-name
load_balancers.653101771           = second-elb-name
....

terraform plan
 ~ aws_autoscaling_group.existing-asg
      force_delete:              "" => "false"

Why the plan not showing like below?

 ~ aws_autoscaling_group.existing-asg
      force_delete:              "" => "false"
      load_balancers.#        2 => 0
      load_balancers.1433097967     "first-elb-name" => ""
      load_balancers.653101771        "second-elb-name" => ""

I just wonder, is it a bug? Or it's intended behaviour, why so?

@bflad bflad added bug Addresses a defect in current functionality. service/autoscaling Issues and PRs that pertain to the autoscaling service. labels Jul 16, 2018
@MetricMike
Copy link
Contributor

I'm having a similar issue migrating an aws_autoscaling_group from ELB/load_balancers to ALB/target_group_arns

going from:

resource "aws_autoscaling_group" {
    ...
    load_balancers = ["${split(",", var.asg_load_balancer_names)}"]
    ...
}

to:

resource "aws_autoscaling_group" {
    ...
    target_group_arns = ["${split(",", var.asg_target_group_arns)}"]
    ...
}

generates the following diff:

  ~ module.auto_scaling_groups.aws_autoscaling_group.default
      target_group_arns.#:                                                                "" => <computed>

This causes issue when autoscaling, as the ASG still references an ELB that might have been deleted. Specifying load_balancers = [] produces the following diff:

  ~ module.auto_scaling_groups.aws_autoscaling_group.default
      load_balancers.#:                                                                   "1" => "0"
      load_balancers.3481940168:                                                          "sample-elb" => ""
      target_group_arns.#:                                                                "" => <computed>

which behaves as expected. I expect this might be because the load_balancers attribute is defined without a default, and the HasChange code is retrieving the current state instead of the expected null, but I'm not familiar enough with Go to parse where exactly the breakdown is.

@lizthegrey
Copy link

Also seeing this bug. I applied a change in TFE (AWS provider version 2.15.0, TF version 0.11.14) that attempted to remove the line from an aws_autoscaling_group stanza:

load_balancers = ["${aws_elb.foo_lb.name}"]

but no change was planned or applied and the ASG was not modified to remove the ELB check, causing future scale-ups to fail.

@lizthegrey
Copy link

lizthegrey commented Jul 8, 2019

addendum: it'll add the field if it's missing but won't remove it.

nywilken added a commit that referenced this issue Jul 24, 2019
…ns issue

Closes: #5197

Upon configuring an ASG with load_balancers, it was found that swapping the load_balancers argument with a list of target_group_arns would result in no diff for the load_balancers despite them being removed.
This issue being the computed property on `load_balancers`, which refreshes the configuration at plan time resulting in `load_balancers` being added back to the configuration as they are still part of the referenced infrastructure.
This change fixes that be removing the `Computed` property on both `load_balancers` and `target_group_arns` to ensure Terraform always honors the arguments within a provided configuration.

```
--- PASS: TestAccAWSAutoScalingGroup_WithLoadBalancer (390.68s)
--- PASS: TestAccAWSAutoScalingGroup_WithLoadBalancer_ToTargetGroup (468.74s)
```
nywilken added a commit that referenced this issue Jul 25, 2019
…ns issue

Closes: #5197

Upon configuring an ASG with load_balancers, it was found that swapping the load_balancers argument with a list of target_group_arns would result in no diff for the load_balancers despite them being removed.
This issue being the computed property on `load_balancers`, which refreshes the configuration at plan time resulting in `load_balancers` being added back to the configuration as they are still part of the referenced infrastructure.
This change fixes that be removing the `Computed` property on both `load_balancers` and `target_group_arns` to ensure Terraform always honors the arguments within a provided configuration.

```
--- PASS: TestAccAWSAutoScalingGroup_WithLoadBalancer (390.68s)
--- PASS: TestAccAWSAutoScalingGroup_WithLoadBalancer_ToTargetGroup (468.74s)
```
nywilken added a commit that referenced this issue Jul 25, 2019
Closes: #5197

Upon configuring an ASG with load_balancers, it was found that swapping the load_balancers argument with a list of target_group_arns would result in no diff for the load_balancers despite them being removed.
This issue being the computed property on `load_balancers`, which refreshes the configuration at plan time resulting in `load_balancers` being added back to the configuration as they are still part of the referenced infrastructure.
This change fixes that be removing the `Computed` property on both `load_balancers` and `target_group_arns` to ensure Terraform always honors the arguments within a provided configuration.

```
--- PASS: TestAccAWSAutoScalingGroup_WithLoadBalancer (390.68s)
--- PASS: TestAccAWSAutoScalingGroup_WithLoadBalancer_ToTargetGroup (468.74s)
```
@nywilken nywilken added this to the v2.21.0 milestone Jul 25, 2019
@nywilken
Copy link
Contributor

Folks, thanks for the help with this issue. I was able to reproduce it successfully within our testing. The fix to the aws_autoscaling_group resource has been merged and will be released with version 2.21.0 of the Terraform AWS provider, possibly later today.

@lizthegrey
Copy link

Thank you so much!

@bflad
Copy link
Contributor

bflad commented Jul 26, 2019

This has been released in version 2.21.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

However, please note that this introduces an unexpected behavior change in load_balancers and target_group_arns for those also using aws_autoscaling_attachment resources. We may need to revert this change until a major version release of the Terraform AWS Provider, but that has not been decided at the moment. Please follow #9513 for updates.

I'm going to proactively lock this issue only to encourage consolidation of discussions and efforts in #9513.

@hashicorp hashicorp locked and limited conversation to collaborators Jul 26, 2019
@hashicorp hashicorp unlocked this conversation Jul 26, 2019
@hashicorp hashicorp locked and limited conversation to collaborators Jul 26, 2019
@nywilken
Copy link
Contributor

Hi Folks, given the need to support the original functionality of aws_autoscaling_group with respect to the load_balancers and target_group_arns arguments we have rolled back the changes in Terraform AWS provider v2.21.0. The fix is now considered a breaking change for the aws_autoscaling_attachment resource which will be addressed in the next major release v3.0.0 of the provider.

At this time the suggested workaround for this issue is to explicitly set the argument for either load_balancers or target_group_arns to an empty list in order for Terraform to properly handle the drift detection on the referenced infrastructure.

Example load_balancers to target_group_arns

Initial configuration

resource "aws_autoscaling_group" {
    ...
    load_balancers = ["${aws_elb.example.name}"]  
    ...
}

Updated configuration

resource "aws_autoscaling_group" {
    ...
    load_balancers = []
    target_group_arns = ["${aws_lb_target_group.example.arn}"]
    ...
}

If you have any questions about the workaround or wish to discuss this particular issue further please add your comments to #9513

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/autoscaling Issues and PRs that pertain to the autoscaling service.
Projects
None yet
5 participants