Skip to content

Commit

Permalink
r/aws_vpc_endpoint: handle UnsupportedOperation tag-on-create errors (#…
Browse files Browse the repository at this point in the history
…31801)

* r/aws_vpc_endpoint: handle unsupported operation tag-on-create errors

* chore: changelog
  • Loading branch information
jar-b authored Jun 7, 2023
1 parent 8d964d2 commit 20f7c08
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
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

0 comments on commit 20f7c08

Please sign in to comment.