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

azurerm_redis_cache - Check if redis_configuration.rdb_backup_enabled and redis_configuration.aof_backup_enabled configured #22309

Merged
merged 4 commits into from
Jul 20, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
ignore rdb_backup_enabled when SKU is not Premium
  • Loading branch information
xuzhang3 authored and xuzhang3 committed Jul 13, 2023
commit 8002021c346a5dc63c25b42b415f5d9fc3c07da7
24 changes: 16 additions & 8 deletions internal/services/redis/redis_cache_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,13 +817,19 @@ func expandRedisConfiguration(d *pluginsdk.ResourceData) (*redis.RedisCommonProp
}

// RDB Backup
config := d.GetRawConfig().AsValueMap()["redis_configuration"].AsValueSlice()[0].AsValueMap()
if !config["rdb_backup_enabled"].IsNull() {
rdbBackupEnabled := d.Get("redis_configuration.0.rdb_backup_enabled").(bool)
if rdbBackupEnabled && raw["rdb_storage_connection_string"].(string) == "" {
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 {
skuName := d.Get("sku_name").(string)
// rdb_backup_enabled is available when SKU is Premium
if strings.EqualFold(skuName, string(redis.SkuNamePremium)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also check if the SKU is not valid for this property, and return an error in case the user sets rdb_backup_enabled = true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add a new constraint to cover the rdb_backup_enabled = true scenario.

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.(bool)))
}
output.RdbBackupEnabled = utils.String(strconv.FormatBool(rdbBackupEnabled))
}

if v := raw["rdb_backup_frequency"].(int); v > 0 {
Expand All @@ -843,8 +849,10 @@ func expandRedisConfiguration(d *pluginsdk.ResourceData) (*redis.RedisCommonProp
}

// AOF Backup
if !config["aof_backup_enabled"].IsNull() {
output.AofBackupEnabled = utils.String(strconv.FormatBool(d.Get("redis_configuration.0.aof_backup_enabled").(bool)))
// 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 != "" {
Expand Down