diff --git a/.changelog/30828.txt b/.changelog/30828.txt new file mode 100644 index 00000000000..f31aee9c765 --- /dev/null +++ b/.changelog/30828.txt @@ -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 +``` \ No newline at end of file diff --git a/internal/service/autoscaling/attachment.go b/internal/service/autoscaling/attachment.go index 0658e438ad1..66ef21e1172 100644 --- a/internal/service/autoscaling/attachment.go +++ b/internal/service/autoscaling/attachment.go @@ -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, @@ -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"}, }, }, } @@ -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), @@ -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) } } @@ -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) { @@ -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), @@ -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) } } diff --git a/internal/service/autoscaling/attachment_test.go b/internal/service/autoscaling/attachment_test.go index 2f8ac4ff7d1..3c78e26fd4d 100644 --- a/internal/service/autoscaling/attachment_test.go +++ b/internal/service/autoscaling/attachment_test.go @@ -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) { @@ -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"]) } } diff --git a/website/docs/r/autoscaling_attachment.html.markdown b/website/docs/r/autoscaling_attachment.html.markdown index 41e23031a1d..0fb26bc6f49 100644 --- a/website/docs/r/autoscaling_attachment.html.markdown +++ b/website/docs/r/autoscaling_attachment.html.markdown @@ -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