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

r/aws_vpclattice_access_log_subscription: Show actionable error message when CloudWatch Logs destination_arn is not suffixed with wildcard #32186

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
7 changes: 7 additions & 0 deletions .changelog/32186.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:bug
resource/aws_vpclattice_access_log_subscription: Avoid recreating resource when passing an ARN as `resource_identifier`
```

```release-note:bug
resource/aws_vpclattice_access_log_subscription: Avoid recreating resource when passing a non-wildcard CloudWatch Logs log group ARN as `destination_arn`
```
50 changes: 29 additions & 21 deletions internal/service/vpclattice/access_log_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ package vpclattice

import (
"context"
"errors"
"log"
"strings"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/vpclattice"
Expand All @@ -17,6 +17,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/create"
"github.com/hashicorp/terraform-provider-aws/internal/errs"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
Expand All @@ -25,7 +26,7 @@ import (

// @SDKResource("aws_vpclattice_access_log_subscription", name="Access Log Subscription")
// @Tags(identifierAttribute="arn")
func ResourceAccessLogSubscription() *schema.Resource {
func resourceAccessLogSubscription() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceAccessLogSubscriptionCreate,
ReadWithoutTimeout: resourceAccessLogSubscriptionRead,
Expand All @@ -42,19 +43,21 @@ func ResourceAccessLogSubscription() *schema.Resource {
Computed: true,
},
"destination_arn": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: verify.ValidARN,
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: verify.ValidARN,
DiffSuppressFunc: suppressEquivalentCloudWatchLogsLogGroupARN,
},
"resource_arn": {
Type: schema.TypeString,
Computed: true,
},
"resource_identifier": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: suppressEquivalentIDOrARN,
},
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
Expand Down Expand Up @@ -125,12 +128,11 @@ func resourceAccessLogSubscriptionDelete(ctx context.Context, d *schema.Resource
AccessLogSubscriptionIdentifier: aws.String(d.Id()),
})

if err != nil {
var nfe *types.ResourceNotFoundException
if errors.As(err, &nfe) {
return nil
}
if errs.IsA[*types.ResourceNotFoundException](err) {
return nil
}

if err != nil {
return create.DiagError(names.VPCLattice, create.ErrActionDeleting, ResNameAccessLogSubscription, d.Id(), err)
}

Expand All @@ -142,15 +144,15 @@ func findAccessLogSubscriptionByID(ctx context.Context, conn *vpclattice.Client,
AccessLogSubscriptionIdentifier: aws.String(id),
}
out, err := conn.GetAccessLogSubscription(ctx, in)
if err != nil {
var nfe *types.ResourceNotFoundException
if errors.As(err, &nfe) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: in,
}

if errs.IsA[*types.ResourceNotFoundException](err) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: in,
}
}

if err != nil {
return nil, err
}

Expand All @@ -160,3 +162,9 @@ func findAccessLogSubscriptionByID(ctx context.Context, conn *vpclattice.Client,

return out, nil
}

// suppressEquivalentCloudWatchLogsLogGroupARN provides custom difference suppression
// for strings that represent equal CloudWatch Logs log group ARNs.
func suppressEquivalentCloudWatchLogsLogGroupARN(_, old, new string, _ *schema.ResourceData) bool {
return strings.TrimSuffix(old, ":*") == strings.TrimSuffix(new, ":*")
}
Loading