Skip to content

r/aws_elasticache[user|user_group|replication_group]: deprecate non-exact engine values #42419

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

Merged
merged 2 commits into from
Apr 30, 2025
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
9 changes: 9 additions & 0 deletions .changelog/42419.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
```release-note:note
resource/aws_elasticache_replication_group: The ability to provide an uppercase `engine` value is deprecated
```
```release-note:note
resource/aws_elasticache_user: The ability to provide an uppercase `engine` value is deprecated
```
```release-note:note
resource/aws_elasticache_user_group: The ability to provide an uppercase `engine` value is deprecated
```
16 changes: 12 additions & 4 deletions internal/service/elasticache/replication_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,18 @@ func resourceReplicationGroup() *schema.Resource {
ValidateFunc: validation.StringIsNotEmpty,
},
names.AttrEngine: {
Type: schema.TypeString,
Optional: true,
Default: engineRedis,
ValidateFunc: validation.StringInSlice([]string{engineRedis, engineValkey}, true),
Type: schema.TypeString,
Optional: true,
Default: engineRedis,
ValidateDiagFunc: validation.AllDiag(
validation.ToDiagFunc(validation.StringInSlice([]string{engineRedis, engineValkey}, true)),
// While the existing validator makes it technically possible to provide an
// uppercase engine value, the absence of a diff suppression function makes
// it impractical to do so (a persistent diff will be present). To be
// conservative we will still run the deprecation validator to notify
// practitioners that stricter validation will be enforced in v7.0.0.
verify.CaseInsensitiveMatchDeprecation([]string{engineRedis, engineValkey}),
),
},
names.AttrEngineVersion: {
Type: schema.TypeString,
Expand Down
10 changes: 7 additions & 3 deletions internal/service/elasticache/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices"
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"
"github.com/hashicorp/terraform-provider-aws/names"
)

Expand Down Expand Up @@ -85,9 +86,12 @@ func resourceUser() *schema.Resource {
},
},
names.AttrEngine: {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{engineRedis, engineValkey}, true),
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: validation.AllDiag(
validation.ToDiagFunc(validation.StringInSlice([]string{engineRedis, engineValkey}, true)),
verify.CaseInsensitiveMatchDeprecation([]string{engineRedis, engineValkey}),
),
DiffSuppressFunc: sdkv2.SuppressEquivalentStringCaseInsensitive,
},
"no_password_required": {
Expand Down
10 changes: 7 additions & 3 deletions internal/service/elasticache/user_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices"
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"
"github.com/hashicorp/terraform-provider-aws/names"
)

Expand All @@ -45,9 +46,12 @@ func resourceUserGroup() *schema.Resource {
Computed: true,
},
names.AttrEngine: {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{engineRedis, engineValkey}, true),
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: validation.AllDiag(
validation.ToDiagFunc(validation.StringInSlice([]string{engineRedis, engineValkey}, true)),
verify.CaseInsensitiveMatchDeprecation([]string{engineRedis, engineValkey}),
),
DiffSuppressFunc: sdkv2.SuppressEquivalentStringCaseInsensitive,
},
names.AttrTags: tftags.TagsSchema(),
Expand Down
29 changes: 29 additions & 0 deletions internal/verify/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,3 +597,32 @@ func MapSizeBetween(min, max int) schema.SchemaValidateDiagFunc {
return diags
}
}

// CaseInsensitiveMatchDeprecation returns a warning diagnostic if the argument value
// matches a valid value using unicode case-folding, but is not an exact match
//
// This validator can be used to deprecate case insensitive value matching in favor
// of exact matching. A value which is an exact match or does not match any valid
// value will return with empty diagnostics.
func CaseInsensitiveMatchDeprecation(valid []string) schema.SchemaValidateDiagFunc {
return func(v any, path cty.Path) diag.Diagnostics {
var diags diag.Diagnostics
s := v.(string)

for _, item := range valid {
if s != item && strings.EqualFold(s, item) {
diags = append(diags, diag.Diagnostic{
Severity: diag.Warning,
Summary: "Case Insensitive Matching Deprecated",
Detail: fmt.Sprintf("Expected an exact match to %q, got %q. ", item, v) +
"Case insensitive matching is deprecated for this argument. Update the value " +
"to an exact match to suppress this warning and avoid breaking changes " +
"in a future major version.",
AttributePath: path,
})
}
}

return diags
}
}
36 changes: 36 additions & 0 deletions internal/verify/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,3 +940,39 @@ func TestMapKeysAre(t *testing.T) {
})
}
}

func TestCaseInsensitiveMatchDeprecation(t *testing.T) {
t.Parallel()

tests := []struct {
name string
value any
wantDiag bool
}{
{
name: "exact match",
value: "foo",
},
{
name: "no match",
value: "baz",
},
{
name: "case insensitive match",
value: "FOO",
wantDiag: true,
},
}

f := CaseInsensitiveMatchDeprecation([]string{"foo", "bar"})
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

diags := f(tt.value, cty.Path{})
if got, want := len(diags) > 0, tt.wantDiag; got != want {
t.Errorf("got = %v, want = %v", got, want)
}
})
}
}
15 changes: 15 additions & 0 deletions website/docs/guides/version-6-upgrade.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Upgrade topics:
- [resource/aws_ecs_task_definition](#resourceaws_ecs_task_definition)
- [resource/aws_eip](#resourceaws_eip)
- [resource/aws_elasticache_replication_group](#resourceaws_elasticache_replication_group)
- [resource/aws_elasticache_user](#resourceaws_elasticache_user)
- [resource/aws_elasticache_user_group](#resourceaws_elasticache_user_group)
- [resource/aws_eks_addon](#resourceaws_eks_addon)
- [resource/aws_flow_log](#resourceaws_flow_log)
- [resource/aws_guardduty_organization_configuration](#resourceaws_guardduty_organization_configuration)
Expand Down Expand Up @@ -368,6 +370,19 @@ Use `domain` instead.
The `auth_token_update_strategy` argument no longer has a default value.
If `auth_token` is set, this argument must also be explicitly configured.

The ability to provide an uppercase `engine` value is deprecated.
In `v7.0.0`, plan-time validation of the `engine` argument will require an entirely lowercase value to match the returned value from the AWS API without diff suppression.

## resource/aws_elasticache_user

The ability to provide an uppercase `engine` value is deprecated.
In `v7.0.0`, plan-time validation of the `engine` argument will require an entirely lowercase value to match the returned value from the AWS API without diff suppression.

## resource/aws_elasticache_user_group

The ability to provide an uppercase `engine` value is deprecated.
In `v7.0.0`, plan-time validation of the `engine` argument will require an entirely lowercase value to match the returned value from the AWS API without diff suppression.

## resource/aws_eks_addon

The `resolve_conflicts` argument has been removed. Use `resolve_conflicts_on_create` and `resolve_conflicts_on_update` instead.
Expand Down
Loading