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/eks_addon: Deprecate resolve_conflicts attribute #29555

Merged
merged 11 commits into from
May 9, 2023
Merged
2 changes: 2 additions & 0 deletions .changelog/29555.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
```release-note:note
resource/aws_eks_addon: The `resolve_conflicts` argument has been deprecated. Use the `resolve_conflicts_on_create` and/or `resolve_conflicts_on_update` arguments instead
82 changes: 42 additions & 40 deletions internal/provider/tags_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import (
"context"

"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"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"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/types"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
"github.com/hashicorp/terraform-provider-aws/names"
)

Expand All @@ -26,6 +25,19 @@ func tagsUpdateFunc(ctx context.Context, d schemaResourceData, sp conns.ServiceP
return ctx, diags
}

var identifier string
if identifierAttribute := spt.IdentifierAttribute; identifierAttribute == "id" {
identifier = d.Id()
} else {
identifier = d.Get(identifierAttribute).(string)
}

// Some old resources may not have the required attribute set after Read:
// https://github.com/hashicorp/terraform-provider-aws/issues/31180
if identifier == "" {
return ctx, diags
}

configTags := make(map[string]string)
if config := d.GetRawConfig(); !config.IsNull() && config.IsKnown() {
c := config.GetAttr(names.AttrTags)
Expand Down Expand Up @@ -54,12 +66,6 @@ func tagsUpdateFunc(ctx context.Context, d schemaResourceData, sp conns.ServiceP
toAdd := configAll.Difference(tagsAll)
toRemove := tagsAll.Difference(configAll)

var identifier string
if identifierAttribute := spt.IdentifierAttribute; identifierAttribute == "id" {
identifier = d.Id()
} else {
identifier = d.Get(identifierAttribute).(string)
}
// If the service package has a generic resource update tags methods, call it.
var err error

Expand All @@ -73,13 +79,8 @@ func tagsUpdateFunc(ctx context.Context, d schemaResourceData, sp conns.ServiceP
err = v.UpdateTags(ctx, meta, identifier, spt.ResourceType, toRemove, toAdd)
}

if verify.ErrorISOUnsupported(meta.(*conns.AWSClient).Partition, err) {
// ISO partitions may not support tagging, giving error
tflog.Warn(ctx, "failed updating tags for resource", map[string]interface{}{
spt.IdentifierAttribute: identifier,
"error": err.Error(),
})

// ISO partitions may not support tagging, giving error.
if errs.IsUnsupportedOperationInPartitionError(meta.(*conns.AWSClient).Partition, err) {
return ctx, diags
}

Expand Down Expand Up @@ -107,35 +108,36 @@ func tagsReadFunc(ctx context.Context, d schemaResourceData, sp conns.ServicePac
identifier = d.Get(identifierAttribute).(string)
}

var err error
if v, ok := sp.(interface {
ListTags(context.Context, any, string) error
}); ok {
err = v.ListTags(ctx, meta, identifier) // Sets tags in Context
} else if v, ok := sp.(interface {
ListTags(context.Context, any, string, string) error
}); ok && spt.ResourceType != "" {
err = v.ListTags(ctx, meta, identifier, spt.ResourceType) // Sets tags in Context
}
// Some old resources may not have the required attribute set after Read:
// https://github.com/hashicorp/terraform-provider-aws/issues/31180
if identifier != "" {
var err error

if verify.ErrorISOUnsupported(meta.(*conns.AWSClient).Partition, err) {
// ISO partitions may not support tagging, giving error
tflog.Warn(ctx, "failed listing tags for resource", map[string]interface{}{
spt.IdentifierAttribute: d.Id(),
"error": err.Error(),
})
return ctx, diags
}
if v, ok := sp.(interface {
ListTags(context.Context, any, string) error
}); ok {
err = v.ListTags(ctx, meta, identifier) // Sets tags in Context
} else if v, ok := sp.(interface {
ListTags(context.Context, any, string, string) error
}); ok && spt.ResourceType != "" {
err = v.ListTags(ctx, meta, identifier, spt.ResourceType) // Sets tags in Context
}

if inContext.ServicePackageName == names.DynamoDB && err != nil {
// When a DynamoDB Table is `ARCHIVED`, ListTags returns `ResourceNotFoundException`.
if tfresource.NotFound(err) || tfawserr.ErrMessageContains(err, "UnknownOperationException", "Tagging is not currently supported in DynamoDB Local.") {
err = nil
// ISO partitions may not support tagging, giving error.
if errs.IsUnsupportedOperationInPartitionError(meta.(*conns.AWSClient).Partition, err) {
return ctx, diags
}
}

if err != nil {
return ctx, sdkdiag.AppendErrorf(diags, "listing tags for %s %s (%s): %s", serviceName, resourceName, identifier, err)
if inContext.ServicePackageName == names.DynamoDB && err != nil {
// When a DynamoDB Table is `ARCHIVED`, ListTags returns `ResourceNotFoundException`.
if tfresource.NotFound(err) || tfawserr.ErrMessageContains(err, "UnknownOperationException", "Tagging is not currently supported in DynamoDB Local.") {
err = nil
}
}

if err != nil {
return ctx, sdkdiag.AppendErrorf(diags, "listing tags for %s %s (%s): %s", serviceName, resourceName, identifier, err)
}
}

// Remove any provider configured ignore_tags and system tags from those returned from the service API.
Expand Down
22 changes: 0 additions & 22 deletions internal/service/ec2/vpc_subnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,28 +375,6 @@ func TestAccVPCSubnet_DefaultTagsProviderAndResource_overlappingTag(t *testing.T
})
}

func TestAccVPCSubnet_DefaultTagsProviderAndResource_duplicateTag(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: acctest.ConfigCompose(
acctest.ConfigDefaultTags_Tags1("overlapkey", "overlapvalue"),
testAccVPCSubnetConfig_tags1(rName, "overlapkey", "overlapvalue"),
),
PlanOnly: true,
ExpectError: regexp.MustCompile(`"tags" are identical to those in the "default_tags" configuration block`),
},
},
})
}

func TestAccVPCSubnet_defaultAndIgnoreTags(t *testing.T) {
ctx := acctest.Context(t)
var subnet ec2.Subnet
Expand Down
Loading