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

Enhance - azurerm_redis_cache - Recreate Redis cache when downgrade the SKU #17767

Merged
merged 6 commits into from
Aug 30, 2022
Merged
Changes from 2 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
15 changes: 15 additions & 0 deletions internal/services/redis/redis_cache_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

var skuWeight = map[string]int8{
"Basic": 1,
"Standard": 2,
"Premium": 3,
}

func resourceRedisCache() *pluginsdk.Resource {
return &pluginsdk.Resource{
Create: resourceRedisCacheCreate,
Expand Down Expand Up @@ -330,6 +336,15 @@ func resourceRedisCache() *pluginsdk.Resource {

"tags": tags.Schema(),
},
CustomizeDiff: pluginsdk.CustomDiffWithAll(
pluginsdk.ForceNewIfChange("sku_name", func(ctx context.Context, old, new, meta interface{}) bool {
// downgrade the SKU is not supported, recreate the resource
if old.(string) != "" && new.(string) != "" {
return skuWeight[old.(string)] > skuWeight[new.(string)]
}
return false
}),
),
}
}

Expand Down