Skip to content

azurerm_redis_cache - tighten validation for sku_name, family, capacity#29079

Merged
wyattfry merged 11 commits intomainfrom
wyatt/redis-sku-family-capacity-validation
Mar 20, 2025
Merged

azurerm_redis_cache - tighten validation for sku_name, family, capacity#29079
wyattfry merged 11 commits intomainfrom
wyatt/redis-sku-family-capacity-validation

Conversation

@wyattfry
Copy link
Contributor

@wyattfry wyattfry commented Mar 14, 2025

Community Note

  • Please vote on this PR by adding a 👍 reaction to the original PR to help the community and maintainers prioritize for review
  • Please do not leave comments along the lines of "+1", "me too" or "any updates", they generate extra noise for PR followers and do not help prioritize for review

Description

This PR tightens the validation for the combination of the arguments sku_name, family and capacity to replicate that which is implemented in the Azure CLI program. This will benefit the user by providing immediate feedback on their configuration, whereas the Azure API does not reliably validate these properties.

PR Checklist

  • I have followed the guidelines in our Contributing Documentation.
  • I have checked to ensure there aren't other open Pull Requests for the same update/change.
  • I have checked if my changes close any open issues. If so please include appropriate closing keywords below.
  • I have updated/added Documentation as required written in a helpful and kind way to assist users that may be unfamiliar with the resource / data source.
  • I have used a meaningful PR title to help maintainers and other users understand this change and help prevent duplicate work.
    For example: “resource_name_here - description of change e.g. adding property new_property_name_here

Changes to existing Resource / Data Source

  • I have added an explanation of what my changes do and why I'd like you to include them (This may be covered by linking to an issue above, but may benefit from additional explanation).
  • I have written new tests for my resource or datasource changes & updated any relevant documentation.
  • I have successfully run tests with my changes locally. If not, please provide details on testing challenges that prevented you running the tests.
  • (For changes that include a state migration only). I have manually tested the migration path between relevant versions of the provider.

Testing

  • My submission includes Test coverage as described in the Contribution Guide and the tests pass. (if this is not possible for any reason, please include details of why you did or could not add test coverage)
image

One unrelated failing acceptance test. This PR does not include any acceptance test changes because this demonstrates that existing valid configurations are still valid despite the tightened rules. If needed, an acceptance test could be added that ensures that invalid configuration triggers the new CustomizeDiffShim validation function.

Change Log

Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.

This is a (please select all that apply):

  • Bug Fix
  • New Feature (ie adding a service, resource, or data source)
  • Enhancement
  • Breaking Change

Related Issue(s)

Fixes IPL-7776

Note

If this PR changes meaningfully during the course of review please update the title and description as required.

@wyattfry wyattfry marked this pull request as ready for review March 14, 2025 20:54
@wyattfry wyattfry requested a review from a team as a code owner March 14, 2025 20:54
Comment on lines +403 to +410
capacity := diff.Get("capacity").(int)
validCombinations := map[string][]string{
string(redis.SkuNameBasic): {"C0", "C1", "C2", "C3", "C4", "C5", "C6"},
string(redis.SkuNameStandard): {"C0", "C1", "C2", "C3", "C4", "C5", "C6"},
string(redis.SkuNamePremium): {"P1", "P2", "P3", "P4", "P5"},
}
familyCapacity := fmt.Sprintf("%s%d", strings.ToUpper(family), capacity)
if !slices.Contains(validCombinations[skuName], familyCapacity) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace is desirable here

Suggested change
capacity := diff.Get("capacity").(int)
validCombinations := map[string][]string{
string(redis.SkuNameBasic): {"C0", "C1", "C2", "C3", "C4", "C5", "C6"},
string(redis.SkuNameStandard): {"C0", "C1", "C2", "C3", "C4", "C5", "C6"},
string(redis.SkuNamePremium): {"P1", "P2", "P3", "P4", "P5"},
}
familyCapacity := fmt.Sprintf("%s%d", strings.ToUpper(family), capacity)
if !slices.Contains(validCombinations[skuName], familyCapacity) {
capacity := diff.Get("capacity").(int)
validCombinations := map[string][]string{
string(redis.SkuNameBasic): {"C0", "C1", "C2", "C3", "C4", "C5", "C6"},
string(redis.SkuNameStandard): {"C0", "C1", "C2", "C3", "C4", "C5", "C6"},
string(redis.SkuNamePremium): {"P1", "P2", "P3", "P4", "P5"},
}
familyCapacity := fmt.Sprintf("%s%d", strings.ToUpper(family), capacity)
if !slices.Contains(validCombinations[skuName], familyCapacity) {

@github-actions github-actions bot added size/M and removed size/S labels Mar 20, 2025
@wyattfry
Copy link
Contributor Author

wyattfry commented Mar 20, 2025

Here is an example of what the error message looks like:

  | \t* invalid combination of `sku_name`, `family`, and `capacity`: 'Basic: P1'. Valid combinations are: map[Basic:[C0 C1 C2 C3 C4 C5 C6] Premium:[P1 P2 P3 P4 P5] Standard:[C0 C1 C2 C3 C4 C5 C6]]

@wyattfry
Copy link
Contributor Author

wyattfry commented Mar 20, 2025

Here's an example if it's limited to the SKU:

  | \t* invalid combination of `sku_name`, `family`, and `capacity`: 'Basic: P1'. Valid combinations for 'Basic' are: [C0 C1 C2 C3 C4 C5 C6]

Copy link
Member

@catriona-m catriona-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @wyattfry LGTM!

@wyattfry wyattfry merged commit 376866a into main Mar 20, 2025
30 checks passed
@wyattfry wyattfry deleted the wyatt/redis-sku-family-capacity-validation branch March 20, 2025 17:25
@github-actions github-actions bot added this to the v4.24.0 milestone Mar 20, 2025
wyattfry added a commit that referenced this pull request Mar 20, 2025
jackofallops added a commit that referenced this pull request Mar 21, 2025
* CHANGELOG.md for v4.24.0

* Update CHANGELOG.md #28173

* Update CHANGELOG.md #28964

* Update CHANGELOG.md #28569

* Update CHANGELOG.md for #28670

* Update CHANGELOG.md #29081

* Update CHANGELOG.md for #29082

* Update CHANGELOG.md #28888

* Update CHANGELOG.md #29012

* Update CHANGELOG.md #28485

* Update CHANGELOG.md for #29094

* Update CHANGELOG.md #29107

* Update CHANGELOG.md #28368

* Update for #29113 #28884 #28739 #28920 #29018 #28822 #28977 #29096 #29040

* Update for #29088

* Update CHANGELOG.md #29079

* Update CHANGELOG.md #28992

* prep for release

---------

Co-authored-by: sreallymatt <106555974+sreallymatt@users.noreply.github.com>
Co-authored-by: Wyatt Fry <wyattfry@gmail.com>
Co-authored-by: jackofallops <11830746+jackofallops@users.noreply.github.com>
Co-authored-by: Matthew Frahry <mbfrahry@gmail.com>
Co-authored-by: stephybun <steph@hashicorp.com>
Co-authored-by: jackofallops <ste@hashicorp.com>
@github-actions
Copy link
Contributor

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants