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_vpc_endpoint: handle UnsupportedOperation tag-on-create errors #31801

Merged
merged 2 commits into from
Jun 7, 2023
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
3 changes: 3 additions & 0 deletions .changelog/31801.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_vpc_endpoint: Fix tagging error preventing use in ISO partitions
```
21 changes: 21 additions & 0 deletions internal/service/ec2/vpc_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/errs"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
Expand Down Expand Up @@ -228,6 +229,12 @@ func resourceVPCEndpointCreate(ctx context.Context, d *schema.ResourceData, meta

output, err := conn.CreateVpcEndpointWithContext(ctx, input)

// Some partitions (e.g. ISO) may not support tag-on-create.
if input.TagSpecifications != nil && errs.IsUnsupportedOperationInPartitionError(conn.PartitionID, err) {
input.TagSpecifications = nil
output, err = conn.CreateVpcEndpointWithContext(ctx, input)
}

if err != nil {
return sdkdiag.AppendErrorf(diags, "creating EC2 VPC Endpoint (%s): %s", serviceName, err)
}
Expand All @@ -245,6 +252,20 @@ func resourceVPCEndpointCreate(ctx context.Context, d *schema.ResourceData, meta
return sdkdiag.AppendErrorf(diags, "creating EC2 VPC Endpoint (%s): waiting for completion: %s", serviceName, err)
}

// For partitions not supporting tag-on-create, attempt tag after create.
if tags := GetTagsIn(ctx); input.TagSpecifications == nil && len(tags) > 0 {
err := createTags(ctx, conn, d.Id(), tags)

// If default tags only, continue. Otherwise, error.
if v, ok := d.GetOk(names.AttrTags); (!ok || len(v.(map[string]interface{})) == 0) && errs.IsUnsupportedOperationInPartitionError(conn.PartitionID, err) {
return append(diags, resourceVPCEndpointRead(ctx, d, meta)...)
}

if err != nil {
return sdkdiag.AppendErrorf(diags, "setting EC2 VPC Endpoint (%s) tags: %s", serviceName, err)
}
}

return append(diags, resourceVPCEndpointRead(ctx, d, meta)...)
}

Expand Down