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
20 changes: 8 additions & 12 deletions internal/services/redis/redis_cache_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,15 +817,13 @@ func expandRedisConfiguration(d *pluginsdk.ResourceData) (*redis.RedisCommonProp
}

// RDB Backup
// 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")
}
config := d.GetRawConfig().AsValueMap()["redis_configuration"].AsValueSlice()[0].AsValueMap()
Copy link
Member

Choose a reason for hiding this comment

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

We can't be using GetRawConfig since this functionality won't be available when we move to framework.

There is a wrapper function that can be used instead pluginsdk.IsExplicitlyNullInConfig.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

rdb_storage_connection_string is nested in redis_configuration. Cannot get it with pluginsdk.IsExplicitlyNullInConfig(d, "redis_configuration.0.rdb_backup_enabled")

Copy link
Contributor

Choose a reason for hiding this comment

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

In this case there's no need to use either IsExplicitlyNullInConfig or d.GetRawConfig().AsValueMap() - this should only be set if the value is set to true?

Copy link
Contributor Author

@xuzhang3 xuzhang3 Jul 10, 2023

Choose a reason for hiding this comment

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

rdb_backup_enabled can be false or true and it can only be set when SKU is Premium

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@avendretter @em-le-ts rdb_backup_enabled can be set when SKU is Premium. Current V2 SDK will auto set a default value(false) to it even not configured. So I need to know if this is configured in the HCL, One way to get it is use d.GetRawConfig().AsValueMap() but this function is not compatible with the terraform framework plugin. Currently we are blocked here.

Copy link

Choose a reason for hiding this comment

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

@xuzhang3 I used the Basic SKU and it was failing, saying that the rdb_backup_enabled option is only allowed for Premium, so I assume it will be set to true regardless of the inputs of SKU

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")
}
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 @@ -845,10 +843,8 @@ func expandRedisConfiguration(d *pluginsdk.ResourceData) (*redis.RedisCommonProp
}

// AOF Backup
// nolint : staticcheck
v, valExists = d.GetOkExists("redis_configuration.0.aof_backup_enabled")
if valExists {
output.AofBackupEnabled = utils.String(strconv.FormatBool(v.(bool)))
if !config["aof_backup_enabled"].IsNull() {
output.AofBackupEnabled = utils.String(strconv.FormatBool(d.Get("redis_configuration.0.aof_backup_enabled").(bool)))
}

if v := raw["aof_storage_connection_string_0"].(string); v != "" {
Expand Down