hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.6k stars 4.65k forks source link

azurerm_redis_cache fails to downgrade SKU #21123

Open Didjacome opened 1 year ago

Didjacome commented 1 year ago

Is there an existing issue for this?

Community Note

Terraform Version

1.4.2

AzureRM Provider Version

= 3.27.0

Affected Resource(s)/Data Source(s)

azurerm_redis_cache

Terraform Configuration Files

resource "azurerm_resource_group" "this" {
  name     = "redis-rg"
  location = "North Europe"
}

resource "azurerm_redis_cache" "this" {
  name                = "my-redis"
  location            = azurerm_resource_group.this.location
  resource_group_name = azurerm_resource_group.this.name
  capacity            = 0
  family              = "C"
  sku_name            = "Basic"
  enable_non_ssl_port = false
  minimum_tls_version = "1.0"

  redis_configuration {
  }
}

Debug Output/Panic Output

Error: updating Redi (Subscription: "***"
│ Resource Group Name: "redis-rg"
│ Redis Name: "my-redis"): redis.RedisClient#Update: Failure sending request: StatusCode=0 -- Original Error: Code="BadRequest" Message="Invalid update request: properties.sku.Capacity cannot be updated to C0.\r\nRequestID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
│ 
│   with module.redis[0].azurerm_redis_cache.main["redis-rg"],
│   on ../../terraform-modules-for-azure/modules/redis/main.tf line 4, in resource "azurerm_redis_cache" "main":
│    4: resource "azurerm_redis_cache" "main" {
│ 
╵
Releasing state lock. This may take a few moments...
##[error]Bash exited with code '1'.

Expected Behaviour

The provider should detect sku downgrade with following plan and attempt to recreate the Redis cache instead of doing an in-place update.

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:

Terraform will perform the following actions:

module.redis[0].azurerm_redis_cache.main["redis-rg"] will be updated in-place

~ resource "azurerm_redis_cache" "main" { ~ capacity = 2 -> 0 id = "/subscriptions/***/resourceGroups/redis-rg/providers/Microsoft.Cache/redis/my-redis" name = "redis-bko-dev" tags = { "environment" = "dev" "managed_by" = "Terraform" }

Plan: 0 to add, 1 to change, 0 to destroy

Actual Behaviour

Terraform plan = OK Terraform apply + error

Steps to Reproduce

terraform apply -auto-approve

Invalid update request: properties.sku.Capacity cannot be updated to C0. RequestID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Important Factoids

No response

References

https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.management.redis.fluent.models.sku.capacity?view=azure-dotnet https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/redis_cache#capacity

xuzhang3 commented 1 year ago

@Didjacome The resource is recreated for a different sku_name. For example, changing the sku_name from "Standard" to "Basic" will recreate the resource. Change the capacity will not trigger a recreate operation

Didjacome commented 1 year ago

Hello @xuzhang3 good morning actually today part of sku and capacity can be changed because of the vertical auto scaling, but the Azure Cache for Redis can not have a change from c2 to c0 according to microsoft documentation: https://learn.microsoft.com/en-us/azure/azure-cache-for-redis/cache-how-to-scale?tabs=scale-up-and-down-with-basic-standard-and-premium#prerequisiteslimitations-of-scaling-azure-cache-for-redis.

But I believe that the terraform api, when choosing a change from C2 to C0, should recreate the redis resource

xuzhang3 commented 1 year ago

@Didjacome This is a special scenario, capacity can be changed from 0 to a non-zero value but cannot from non-zero value to 0.

Didjacome commented 1 year ago

@xuzhang3 Exactly for this reason it is necessary to recreate the resource. in GO we can make a condition that if the value goes from any number other than 0 to 0, it will recreate the resource.

the big problem is that if you try to make a change and this cannot be done, you have to destroy the resource and recreate again

as is done in changing the name of the resource, for example