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 all 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
16 changes: 12 additions & 4 deletions internal/services/redis/redis_cache_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,12 +820,20 @@ func expandRedisConfiguration(d *pluginsdk.ResourceData) (*redis.RedisCommonProp
// 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")
skuName := d.Get("sku_name").(string)
rdbBackupEnabled := raw["rdb_backup_enabled"].(bool)

// 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 rdbBackupEnabled {
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(rdbBackupEnabled))
} else if rdbBackupEnabled && !strings.EqualFold(skuName, string(redis.SkuNamePremium)) {
return nil, fmt.Errorf("The `rdb_backup_enabled` property requires a `Premium` sku to be set")
}
output.RdbBackupEnabled = utils.String(strconv.FormatBool(v.(bool)))
}

if v := raw["rdb_backup_frequency"].(int); v > 0 {
Expand Down