diff --git a/aws/resource_aws_autoscaling_attachment_test.go b/aws/resource_aws_autoscaling_attachment_test.go index 7046b47b126..f4f00ab9094 100644 --- a/aws/resource_aws_autoscaling_attachment_test.go +++ b/aws/resource_aws_autoscaling_attachment_test.go @@ -250,6 +250,10 @@ resource "aws_autoscaling_group" "asg" { value = "terraform-asg-lg-assoc-test" propagate_at_launch = true } + + lifecycle { + ignore_changes = [load_balancers, target_group_arns] + } } resource "aws_launch_configuration" "as_conf" { @@ -313,6 +317,10 @@ resource "aws_autoscaling_group" "asg" { value = "terraform-asg-lg-assoc-test" propagate_at_launch = true } + + lifecycle { + ignore_changes = [load_balancers, target_group_arns] + } } `, rInt, rInt) } diff --git a/aws/resource_aws_autoscaling_group.go b/aws/resource_aws_autoscaling_group.go index c0a8f246c1b..16b31cb1025 100644 --- a/aws/resource_aws_autoscaling_group.go +++ b/aws/resource_aws_autoscaling_group.go @@ -262,12 +262,9 @@ func resourceAwsAutoscalingGroup() *schema.Resource { Optional: true, }, - // DEPRECATED: Computed: true should be removed in a major version release - // Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/9513 "load_balancers": { Type: schema.TypeSet, Optional: true, - Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, Set: schema.HashString, }, @@ -337,12 +334,9 @@ func resourceAwsAutoscalingGroup() *schema.Resource { Default: false, }, - // DEPRECATED: Computed: true should be removed in a major version release - // Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/9513 "target_group_arns": { Type: schema.TypeSet, Optional: true, - Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, Set: schema.HashString, }, diff --git a/aws/resource_aws_autoscaling_group_test.go b/aws/resource_aws_autoscaling_group_test.go index aa04db7a015..4c30c3ff443 100644 --- a/aws/resource_aws_autoscaling_group_test.go +++ b/aws/resource_aws_autoscaling_group_test.go @@ -461,6 +461,7 @@ func TestAccAWSAutoScalingGroup_WithLoadBalancer(t *testing.T) { func TestAccAWSAutoScalingGroup_WithLoadBalancer_ToTargetGroup(t *testing.T) { var group autoscaling.Group + resourceName := "aws_autoscaling_group.bar" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -470,13 +471,13 @@ func TestAccAWSAutoScalingGroup_WithLoadBalancer_ToTargetGroup(t *testing.T) { { Config: testAccAWSAutoScalingGroupConfigWithLoadBalancer, Check: resource.ComposeTestCheckFunc( - testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group), - resource.TestCheckResourceAttr("aws_autoscaling_group.bar", "load_balancers.#", "1"), - resource.TestCheckResourceAttr("aws_autoscaling_group.bar", "target_group_arns.#", "0"), + testAccCheckAWSAutoScalingGroupExists(resourceName, &group), + resource.TestCheckResourceAttr(resourceName, "load_balancers.#", "1"), + resource.TestCheckResourceAttr(resourceName, "target_group_arns.#", "0"), ), }, { - ResourceName: "aws_autoscaling_group.bar", + ResourceName: resourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{ @@ -492,14 +493,13 @@ func TestAccAWSAutoScalingGroup_WithLoadBalancer_ToTargetGroup(t *testing.T) { { Config: testAccAWSAutoScalingGroupConfigWithTargetGroup, Check: resource.ComposeTestCheckFunc( - testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group), - resource.TestCheckResourceAttr("aws_autoscaling_group.bar", "target_group_arns.#", "1"), - // DEPRECATED: This value will be 0 when Computed: true is removed - resource.TestCheckResourceAttr("aws_autoscaling_group.bar", "load_balancers.#", "1"), + testAccCheckAWSAutoScalingGroupExists(resourceName, &group), + resource.TestCheckResourceAttr(resourceName, "target_group_arns.#", "1"), + resource.TestCheckResourceAttr(resourceName, "load_balancers.#", "0"), ), }, { - ResourceName: "aws_autoscaling_group.bar", + ResourceName: resourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{ @@ -515,14 +515,13 @@ func TestAccAWSAutoScalingGroup_WithLoadBalancer_ToTargetGroup(t *testing.T) { { Config: testAccAWSAutoScalingGroupConfigWithLoadBalancer, Check: resource.ComposeTestCheckFunc( - testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group), - resource.TestCheckResourceAttr("aws_autoscaling_group.bar", "load_balancers.#", "1"), - // DEPRECATED: This value will be 0 when Computed: true is removed - resource.TestCheckResourceAttr("aws_autoscaling_group.bar", "target_group_arns.#", "1"), + testAccCheckAWSAutoScalingGroupExists(resourceName, &group), + resource.TestCheckResourceAttr(resourceName, "load_balancers.#", "1"), + resource.TestCheckResourceAttr(resourceName, "target_group_arns.#", "0"), ), }, { - ResourceName: "aws_autoscaling_group.bar", + ResourceName: resourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{ diff --git a/website/docs/guides/version-3-upgrade.html.md b/website/docs/guides/version-3-upgrade.html.md index da4b8197954..1d3d34fdb3b 100644 --- a/website/docs/guides/version-3-upgrade.html.md +++ b/website/docs/guides/version-3-upgrade.html.md @@ -160,6 +160,61 @@ output "lambda_result" { Specifying both the `availability_zones` and `vpc_zone_identifier` arguments previously led to confusing behavior and errors. Now this issue is reported at plan-time. Use the `null` value instead of `[]` (empty list) in conditionals to ensure this validation does not unexpectedly trigger. +### Drift detection enabled for `load_balancers` and `target_group_arns` arguments + +If you previously set one of these arguments to an empty list to enable drift detection (e.g. when migrating an ASG from ELB to ALB), this can be updated as follows. + +For example, given this previous configuration: + +```hcl +resource "aws_autoscaling_group" "example" { + # ... other configuration ... + load_balancers = [] + target_group_arns = [aws_lb_target_group.example.arn] +} +``` + +An updated configuration: + +```hcl +resource "aws_autoscaling_group" "example" { + # ... other configuration ... + target_group_arns = [aws_lb_target_group.example.arn] +} +``` + +If `aws_autoscaling_attachment` resources reference your ASG configurations, you will need to add the [`lifecycle` configuration block](/docs/configuration/resources.html#lifecycle-lifecycle-customizations) with an `ignore_changes` argument to prevent Terraform non-empty plans (i.e. forcing resource update) during the next state refresh. + +For example, given this previous configuration: + +```hcl +resource "aws_autoscaling_attachment" "example" { + autoscaling_group_name = aws_autoscaling_group.example.id + elb = aws_elb.example.id +} + +resource "aws_autoscaling_group" "example"{ + # ... other configuration ... +} +``` + +An updated configuration: + +```hcl +resource "aws_autoscaling_attachment" "example" { + autoscaling_group_name = aws_autoscaling_group.example.id + elb = aws_elb.example.id +} + +resource "aws_autoscaling_group" "example"{ + # ... other configuration ... + + lifecycle { + ignore_changes = [load_balancers, target_group_arns] + } +} +``` + ## Resource: aws_dx_gateway ### Removal of Automatic aws_dx_gateway_association Import diff --git a/website/docs/r/autoscaling_attachment.html.markdown b/website/docs/r/autoscaling_attachment.html.markdown index da821a60ff6..b276576fe42 100644 --- a/website/docs/r/autoscaling_attachment.html.markdown +++ b/website/docs/r/autoscaling_attachment.html.markdown @@ -12,26 +12,44 @@ Provides an AutoScaling Attachment resource. ~> **NOTE on AutoScaling Groups and ASG Attachments:** Terraform currently provides both a standalone ASG Attachment resource (describing an ASG attached to -an ELB), and an [AutoScaling Group resource](autoscaling_group.html) with -`load_balancers` defined in-line. At this time you cannot use an ASG with in-line -load balancers in conjunction with an ASG Attachment resource. Doing so will cause a -conflict and will overwrite attachments. +an ELB or ALB), and an [AutoScaling Group resource](autoscaling_group.html) with +`load_balancers` and `target_group_arns` defined in-line. At this time you can use an ASG with in-line +`load balancers` or `target_group_arns` in conjunction with an ASG Attachment resource, however, to prevent +unintended resource updates, the `aws_autoscaling_group` resource must be configured +to ignore changes to the `load_balancers` and `target_group_arns` arguments within a [`lifecycle` configuration block](/docs/configuration/resources.html#lifecycle-lifecycle-customizations). ## Example Usage ```hcl # Create a new load balancer attachment resource "aws_autoscaling_attachment" "asg_attachment_bar" { - autoscaling_group_name = "${aws_autoscaling_group.asg.id}" - elb = "${aws_elb.bar.id}" + autoscaling_group_name = aws_autoscaling_group.asg.id + elb = aws_elb.bar.id } ``` ```hcl # Create a new ALB Target Group attachment resource "aws_autoscaling_attachment" "asg_attachment_bar" { - autoscaling_group_name = "${aws_autoscaling_group.asg.id}" - alb_target_group_arn = "${aws_alb_target_group.test.arn}" + autoscaling_group_name = aws_autoscaling_group.asg.id + alb_target_group_arn = aws_alb_target_group.test.arn +} +``` + +## With An AutoScaling Group Resource + +```hcl +resource "aws_autoscaling_group" "asg" { + # ... other configuration ... + + lifecycle { + ignore_changes = [load_balancers, target_group_arns] + } +} + +resource "aws_autoscaling_attachment" "asg_attachment_bar" { + autoscaling_group_name = aws_autoscaling_group.asg.id + elb = aws_elb.test.id } ``` diff --git a/website/docs/r/autoscaling_group.html.markdown b/website/docs/r/autoscaling_group.html.markdown index e80090df56c..cf3a38180e5 100644 --- a/website/docs/r/autoscaling_group.html.markdown +++ b/website/docs/r/autoscaling_group.html.markdown @@ -304,10 +304,6 @@ In addition to all arguments above, the following attributes are exported: * `desired_capacity` -The number of Amazon EC2 instances that should be running in the group. * `launch_configuration` - The launch configuration of the autoscale group * `vpc_zone_identifier` (Optional) - The VPC zone identifier -* `load_balancers` (Optional) The load balancer names associated with the - autoscaling group. -* `target_group_arns` (Optional) list of Target Group ARNs that apply to this -AutoScaling Group ~> **NOTE:** When using `ELB` as the `health_check_type`, `health_check_grace_period` is required.