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

resource/autoscaling_group: reintroduce changes made in #9478 #14064

Merged
merged 3 commits into from
Jul 14, 2020
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
8 changes: 8 additions & 0 deletions aws/resource_aws_autoscaling_attachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 0 additions & 6 deletions aws/resource_aws_autoscaling_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand Down
27 changes: 13 additions & 14 deletions aws/resource_aws_autoscaling_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand Down
55 changes: 55 additions & 0 deletions website/docs/guides/version-3-upgrade.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 26 additions & 8 deletions website/docs/r/autoscaling_attachment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```

Expand Down
4 changes: 0 additions & 4 deletions website/docs/r/autoscaling_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down