diff --git a/internal/services/redis/redis_cache_resource.go b/internal/services/redis/redis_cache_resource.go index d2c5f28f055c..3fb52ea19598 100644 --- a/internal/services/redis/redis_cache_resource.go +++ b/internal/services/redis/redis_cache_resource.go @@ -818,11 +818,15 @@ func expandRedisConfiguration(d *pluginsdk.ResourceData) (*redis.RedisCommonProp } // RDB Backup - if v := raw["rdb_backup_enabled"].(bool); v { - if connStr := raw["rdb_storage_connection_string"].(string); connStr == "" { - return nil, fmt.Errorf("The rdb_storage_connection_string property must be set when rdb_backup_enabled is true") + // nolint : staticcheck + v, valExists := d.GetOkExists("redis_configuration.0.rdb_backup_enabled") + if valExists { + if v := raw["rdb_backup_enabled"].(bool); v { + if connStr := raw["rdb_storage_connection_string"].(string); connStr == "" { + return nil, fmt.Errorf("The rdb_storage_connection_string property must be set when rdb_backup_enabled is true") + } } - output.RdbBackupEnabled = utils.String(strconv.FormatBool(v)) + output.RdbBackupEnabled = utils.String(strconv.FormatBool(v.(bool))) } if v := raw["rdb_backup_frequency"].(int); v > 0 { @@ -842,8 +846,10 @@ func expandRedisConfiguration(d *pluginsdk.ResourceData) (*redis.RedisCommonProp } // AOF Backup - if v := raw["aof_backup_enabled"].(bool); v { - output.AofBackupEnabled = utils.String(strconv.FormatBool(v)) + // nolint : staticcheck + v, valExists = d.GetOkExists("redis_configuration.0.aof_backup_enabled") + if valExists { + output.AofBackupEnabled = utils.String(strconv.FormatBool(v.(bool))) } if v := raw["aof_storage_connection_string_0"].(string); v != "" { @@ -853,7 +859,6 @@ func expandRedisConfiguration(d *pluginsdk.ResourceData) (*redis.RedisCommonProp if v := raw["aof_storage_connection_string_1"].(string); v != "" { output.AofStorageConnectionString1 = utils.String(v) } - authEnabled := raw["enable_authentication"].(bool) // Redis authentication can only be disabled if it is launched inside a VNET. if _, isPrivate := d.GetOk("subnet_id"); !isPrivate { diff --git a/internal/services/redis/redis_cache_resource_test.go b/internal/services/redis/redis_cache_resource_test.go index eb4744e958fe..904a924ea24d 100644 --- a/internal/services/redis/redis_cache_resource_test.go +++ b/internal/services/redis/redis_cache_resource_test.go @@ -143,6 +143,11 @@ func TestAccRedisCache_BackupDisabled(t *testing.T) { Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), + // `redis_configuration.0.aof_storage_connection_string_0` and `redis_configuration.0.aof_storage_connection_string_1` are returned as: + // "...;AccountKey=[key hidden]" rather than "...;AccountKey=fsjfvjnfnf" + // TODO: remove this once the Bug's been fixed: + // https://github.com/Azure/azure-rest-api-specs/issues/3037 + ExpectNonEmptyPlan: true, }, }) } @@ -178,7 +183,7 @@ func TestAccRedisCache_BackupEnabledDisabled(t *testing.T) { check.That(data.ResourceName).ExistsInAzure(r), ), // `redis_configuration.0.rdb_storage_connection_string` is returned as: - // "...;AccountKey=[key hidden]" rather than "...;AccountKey=fsjfvjnfnf" + // "...;AccountKey=[key hidden]" rather than "...;AccountKey=fsjfvjnfnf..." // TODO: remove this once the Bug's been fixed: // https://github.com/Azure/azure-rest-api-specs/issues/3037 ExpectNonEmptyPlan: true, @@ -188,8 +193,8 @@ func TestAccRedisCache_BackupEnabledDisabled(t *testing.T) { Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), - // `redis_configuration.0.rdb_storage_connection_string` is returned as: - // "...;AccountKey=[key hidden]" rather than "...;AccountKey=fsjfvjnfnf" + // `redis_configuration.0.aof_storage_connection_string_0` and `redis_configuration.0.aof_storage_connection_string_1` are returned as: + // "...;AccountKey=[key hidden]" rather than "...;AccountKey=fsjfvjnfnf..." // TODO: remove this once the Bug's been fixed: // https://github.com/Azure/azure-rest-api-specs/issues/3037 ExpectNonEmptyPlan: true, @@ -224,6 +229,9 @@ func TestAccRedisCache_AOFBackupEnabledDisabled(t *testing.T) { Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), + // `redis_configuration.0.aof_storage_connection_string_0` and `aof_storage_connection_string_1` are returned as: + // "...;AccountKey=[key hidden]" rather than "...;AccountKey=fsjfvjnfnf..." + // TODO: remove this once the Bug's been fixed: ExpectNonEmptyPlan: true, }, { @@ -231,6 +239,9 @@ func TestAccRedisCache_AOFBackupEnabledDisabled(t *testing.T) { Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), + // `redis_configuration.0.rdb_storage_connection_string` is returned as: + // "...;AccountKey=[key hidden]" rather than "...;AccountKey=fsjfvjnfnf..." + // TODO: remove this once the Bug's been fixed: ExpectNonEmptyPlan: true, }, }) @@ -690,6 +701,42 @@ resource "azurerm_resource_group" "test" { location = "%s" } +resource "azurerm_storage_account" "test" { + name = "acctestsa%s" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + account_tier = "Standard" + account_replication_type = "GRS" + + tags = { + environment = "staging" + } +} + +resource "azurerm_storage_account" "test2" { + name = "acctestsa2%s" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + account_tier = "Standard" + account_replication_type = "GRS" + + tags = { + environment = "staging" + } +} + +resource "azurerm_storage_account" "test3" { + name = "acctestsa3%s" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + account_tier = "Standard" + account_replication_type = "GRS" + + tags = { + environment = "staging" + } +} + resource "azurerm_redis_cache" "test" { name = "acctestRedis-%d" location = azurerm_resource_group.test.location @@ -700,10 +747,13 @@ resource "azurerm_redis_cache" "test" { enable_non_ssl_port = false redis_configuration { - rdb_backup_enabled = false + rdb_backup_enabled = false + aof_backup_enabled = true + aof_storage_connection_string_0 = azurerm_storage_account.test2.primary_connection_string + aof_storage_connection_string_1 = azurerm_storage_account.test3.primary_connection_string } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString, data.RandomString, data.RandomInteger) } func (RedisCacheResource) backupEnabled(data acceptance.TestData) string { @@ -742,7 +792,7 @@ resource "azurerm_redis_cache" "test" { rdb_backup_enabled = true rdb_backup_frequency = 60 rdb_backup_max_snapshot_count = 1 - rdb_storage_connection_string = "DefaultEndpointsProtocol=https;BlobEndpoint=${azurerm_storage_account.test.primary_blob_endpoint};AccountName=${azurerm_storage_account.test.name};AccountKey=${azurerm_storage_account.test.primary_access_key}" + rdb_storage_connection_string = azurerm_storage_account.test.primary_connection_string } } `, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) @@ -759,6 +809,42 @@ resource "azurerm_resource_group" "test" { location = "%s" } +resource "azurerm_storage_account" "test" { + name = "acctestsa%s" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + account_tier = "Standard" + account_replication_type = "GRS" + + tags = { + environment = "staging" + } +} + +resource "azurerm_storage_account" "test2" { + name = "acctestsa2%s" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + account_tier = "Standard" + account_replication_type = "GRS" + + tags = { + environment = "staging" + } +} + +resource "azurerm_storage_account" "test3" { + name = "acctestsa3%s" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + account_tier = "Standard" + account_replication_type = "GRS" + + tags = { + environment = "staging" + } +} + resource "azurerm_redis_cache" "test" { name = "acctestRedis-%d" location = azurerm_resource_group.test.location @@ -769,10 +855,14 @@ resource "azurerm_redis_cache" "test" { enable_non_ssl_port = false redis_configuration { - aof_backup_enabled = false + aof_backup_enabled = false + rdb_backup_enabled = true + rdb_backup_frequency = 60 + rdb_backup_max_snapshot_count = 1 + rdb_storage_connection_string = azurerm_storage_account.test3.primary_connection_string } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString, data.RandomString, data.RandomInteger) } func (RedisCacheResource) aofBackupEnabled(data acceptance.TestData) string { @@ -787,7 +877,19 @@ resource "azurerm_resource_group" "test" { } resource "azurerm_storage_account" "test" { - name = "unlikely23exst2acct%s" + name = "acctestsa%s" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + account_tier = "Standard" + account_replication_type = "GRS" + + tags = { + environment = "staging" + } +} + +resource "azurerm_storage_account" "test2" { + name = "acctestsa2%s" resource_group_name = azurerm_resource_group.test.name location = azurerm_resource_group.test.location account_tier = "Standard" @@ -809,11 +911,11 @@ resource "azurerm_redis_cache" "test" { redis_configuration { aof_backup_enabled = true - aof_storage_connection_string_0 = "DefaultEndpointsProtocol=https;BlobEndpoint=${azurerm_storage_account.test.primary_blob_endpoint};AccountName=${azurerm_storage_account.test.name};AccountKey=${azurerm_storage_account.test.primary_access_key}" - aof_storage_connection_string_1 = "DefaultEndpointsProtocol=https;BlobEndpoint=${azurerm_storage_account.test.primary_blob_endpoint};AccountName=${azurerm_storage_account.test.name};AccountKey=${azurerm_storage_account.test.secondary_access_key}" + aof_storage_connection_string_0 = azurerm_storage_account.test.primary_connection_string + aof_storage_connection_string_1 = azurerm_storage_account.test2.primary_connection_string } } -`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString, data.RandomInteger) } func (RedisCacheResource) patchSchedule(data acceptance.TestData) string { @@ -1192,8 +1294,8 @@ resource "azurerm_redis_cache" "test" { location = azurerm_resource_group.test.location resource_group_name = azurerm_resource_group.test.name capacity = 2 - family = "C" - sku_name = "Basic" + family = "P" + sku_name = "Premium" enable_non_ssl_port = false minimum_tls_version = "1.2" diff --git a/website/docs/r/redis_cache.html.markdown b/website/docs/r/redis_cache.html.markdown index 860295301dab..39761e9e1c64 100644 --- a/website/docs/r/redis_cache.html.markdown +++ b/website/docs/r/redis_cache.html.markdown @@ -107,7 +107,7 @@ An `identity` block supports the following: A `redis_configuration` block supports the following: -* `aof_backup_enabled` - (Optional) Enable or disable AOF persistence for this Redis Cache. +* `aof_backup_enabled` - (Optional) Enable or disable AOF persistence for this Redis Cache. Defaults to `false`. * `aof_storage_connection_string_0` - (Optional) First Storage Account connection string for AOF persistence. * `aof_storage_connection_string_1` - (Optional) Second Storage Account connection string for AOF persistence. @@ -131,7 +131,7 @@ redis_configuration { * `maxfragmentationmemory_reserved` - (Optional) Value in megabytes reserved to accommodate for memory fragmentation. Defaults are shown below. -* `rdb_backup_enabled` - (Optional) Is Backup Enabled? Only supported on Premium SKUs. +* `rdb_backup_enabled` - (Optional) Is Backup Enabled? Only supported on Premium SKUs. Defaults to `false`. -> **NOTE:** If `rdb_backup_enabled` set to `true`, `rdb_storage_connection_string` must also be set.