Skip to content

Commit

Permalink
Merge pull request #30828 from hashicorp/b-autoscaling-attachment-rem…
Browse files Browse the repository at this point in the history
…ove-alb

autoscaling/attachment: Remove alb_target_group_arn
  • Loading branch information
YakDriver authored Apr 20, 2023
2 parents 34aaf87 + bbbbf29 commit 6c50885
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 48 deletions.
7 changes: 7 additions & 0 deletions .changelog/30828.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:breaking-change
resource/aws_autoscaling_attachment: `alb_target_group_arn` has been removed -- use `lb_target_group_arn` instead
```

```release-note:note
resource/aws_autoscaling_attachment: Update configurations to use `lb_target_group_arn` instead of `alb_target_group_arn` which has been removed
```
44 changes: 8 additions & 36 deletions internal/service/autoscaling/attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ func ResourceAttachment() *schema.Resource {
DeleteWithoutTimeout: resourceAttachmentDelete,

Schema: map[string]*schema.Schema{
"alb_target_group_arn": {
Type: schema.TypeString,
ForceNew: true,
Optional: true,
Deprecated: "Use lb_target_group_arn instead",
ExactlyOneOf: []string{"alb_target_group_arn", "elb", "lb_target_group_arn"},
},
"autoscaling_group_name": {
Type: schema.TypeString,
ForceNew: true,
Expand All @@ -40,13 +33,13 @@ func ResourceAttachment() *schema.Resource {
Type: schema.TypeString,
ForceNew: true,
Optional: true,
ExactlyOneOf: []string{"alb_target_group_arn", "elb", "lb_target_group_arn"},
ExactlyOneOf: []string{"elb", "lb_target_group_arn"},
},
"lb_target_group_arn": {
Type: schema.TypeString,
ForceNew: true,
Optional: true,
ExactlyOneOf: []string{"alb_target_group_arn", "elb", "lb_target_group_arn"},
ExactlyOneOf: []string{"elb", "lb_target_group_arn"},
},
},
}
Expand Down Expand Up @@ -75,16 +68,9 @@ func resourceAttachmentCreate(ctx context.Context, d *schema.ResourceData, meta
return sdkdiag.AppendErrorf(diags, "attaching Auto Scaling Group (%s) load balancer (%s): %s", asgName, lbName, err)
}
} else {
var targetGroupARN string
if v, ok := d.GetOk("alb_target_group_arn"); ok {
targetGroupARN = v.(string)
} else if v, ok := d.GetOk("lb_target_group_arn"); ok {
targetGroupARN = v.(string)
}

input := &autoscaling.AttachLoadBalancerTargetGroupsInput{
AutoScalingGroupName: aws.String(asgName),
TargetGroupARNs: aws.StringSlice([]string{targetGroupARN}),
TargetGroupARNs: aws.StringSlice([]string{d.Get("lb_target_group_arn").(string)}),
}

_, err := tfresource.RetryWhenAWSErrMessageContains(ctx, d.Timeout(schema.TimeoutCreate),
Expand All @@ -94,7 +80,7 @@ func resourceAttachmentCreate(ctx context.Context, d *schema.ResourceData, meta
ErrCodeValidationError, "update too many")

if err != nil {
return sdkdiag.AppendErrorf(diags, "attaching Auto Scaling Group (%s) target group (%s): %s", asgName, targetGroupARN, err)
return sdkdiag.AppendErrorf(diags, "attaching Auto Scaling Group (%s) target group (%s): %s", asgName, d.Get("lb_target_group_arn").(string), err)
}
}

Expand All @@ -112,16 +98,9 @@ func resourceAttachmentRead(ctx context.Context, d *schema.ResourceData, meta in
var err error

if v, ok := d.GetOk("elb"); ok {
lbName := v.(string)
err = FindAttachmentByLoadBalancerName(ctx, conn, asgName, lbName)
err = FindAttachmentByLoadBalancerName(ctx, conn, asgName, v.(string))
} else {
var targetGroupARN string
if v, ok := d.GetOk("alb_target_group_arn"); ok {
targetGroupARN = v.(string)
} else if v, ok := d.GetOk("lb_target_group_arn"); ok {
targetGroupARN = v.(string)
}
err = FindAttachmentByTargetGroupARN(ctx, conn, asgName, targetGroupARN)
err = FindAttachmentByTargetGroupARN(ctx, conn, asgName, d.Get("lb_target_group_arn").(string))
}

if !d.IsNewResource() && tfresource.NotFound(err) {
Expand Down Expand Up @@ -159,16 +138,9 @@ func resourceAttachmentDelete(ctx context.Context, d *schema.ResourceData, meta
return sdkdiag.AppendErrorf(diags, "detaching Auto Scaling Group (%s) load balancer (%s): %s", asgName, lbName, err)
}
} else {
var targetGroupARN string
if v, ok := d.GetOk("alb_target_group_arn"); ok {
targetGroupARN = v.(string)
} else if v, ok := d.GetOk("lb_target_group_arn"); ok {
targetGroupARN = v.(string)
}

input := &autoscaling.DetachLoadBalancerTargetGroupsInput{
AutoScalingGroupName: aws.String(asgName),
TargetGroupARNs: aws.StringSlice([]string{targetGroupARN}),
TargetGroupARNs: aws.StringSlice([]string{d.Get("lb_target_group_arn").(string)}),
}

_, err := tfresource.RetryWhenAWSErrMessageContains(ctx, d.Timeout(schema.TimeoutCreate),
Expand All @@ -178,7 +150,7 @@ func resourceAttachmentDelete(ctx context.Context, d *schema.ResourceData, meta
ErrCodeValidationError, "update too many")

if err != nil {
return sdkdiag.AppendErrorf(diags, "detaching Auto Scaling Group (%s) target group (%s): %s", asgName, targetGroupARN, err)
return sdkdiag.AppendErrorf(diags, "detaching Auto Scaling Group (%s) target group (%s): %s", asgName, d.Get("lb_target_group_arn").(string), err)
}
}

Expand Down
15 changes: 4 additions & 11 deletions internal/service/autoscaling/attachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,10 @@ func testAccCheckAttachmentDestroy(ctx context.Context) resource.TestCheckFunc {

var err error

if targetGroupARN := rs.Primary.Attributes["lb_target_group_arn"]; targetGroupARN == "" {
targetGroupARN = rs.Primary.Attributes["alb_target_group_arn"]

err = tfautoscaling.FindAttachmentByTargetGroupARN(ctx, conn, rs.Primary.Attributes["autoscaling_group_name"], targetGroupARN)
if lbName := rs.Primary.Attributes["elb"]; lbName != "" {
err = tfautoscaling.FindAttachmentByLoadBalancerName(ctx, conn, rs.Primary.Attributes["autoscaling_group_name"], lbName)
} else {
err = tfautoscaling.FindAttachmentByLoadBalancerName(ctx, conn, rs.Primary.Attributes["autoscaling_group_name"], rs.Primary.Attributes["elb"])
err = tfautoscaling.FindAttachmentByTargetGroupARN(ctx, conn, rs.Primary.Attributes["autoscaling_group_name"], rs.Primary.Attributes["lb_target_group_arn"])
}

if tfresource.NotFound(err) {
Expand Down Expand Up @@ -173,12 +171,7 @@ func testAccCheckAttachmentByTargetGroupARNExists(ctx context.Context, n string)

conn := acctest.Provider.Meta().(*conns.AWSClient).AutoScalingConn()

targetGroupARN := rs.Primary.Attributes["lb_target_group_arn"]
if targetGroupARN == "" {
targetGroupARN = rs.Primary.Attributes["alb_target_group_arn"]
}

return tfautoscaling.FindAttachmentByTargetGroupARN(ctx, conn, rs.Primary.Attributes["autoscaling_group_name"], targetGroupARN)
return tfautoscaling.FindAttachmentByTargetGroupARN(ctx, conn, rs.Primary.Attributes["autoscaling_group_name"], rs.Primary.Attributes["lb_target_group_arn"])
}
}

Expand Down
1 change: 0 additions & 1 deletion website/docs/r/autoscaling_attachment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ The following arguments are supported:

* `autoscaling_group_name` - (Required) Name of ASG to associate with the ELB.
* `elb` - (Optional) Name of the ELB.
* `alb_target_group_arn` - (Optional, **Deprecated** use `lb_target_group_arn` instead) ARN of an ALB Target Group.
* `lb_target_group_arn` - (Optional) ARN of a load balancer target group.

## Attributes Reference
Expand Down

0 comments on commit 6c50885

Please sign in to comment.