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

Redis API Upgrade - 2020-12-01 to 2021-06-01 #16532

Merged
merged 4 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion internal/services/redis/client/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package client

import (
"github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2020-12-01/redis"
"github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2021-06-01/redis"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

Expand Down
115 changes: 58 additions & 57 deletions internal/services/redis/redis_cache_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import (
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2020-12-01/redis"
"github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2021-06-01/redis"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-helpers/resourcemanager/zones"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
azValidate "github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
Expand Down Expand Up @@ -732,8 +731,10 @@ func redisStateRefreshFunc(ctx context.Context, client *redis.Client, resourceGr
}
}

func expandRedisConfiguration(d *pluginsdk.ResourceData) (map[string]*string, error) {
output := make(map[string]*string)
func expandRedisConfiguration(d *pluginsdk.ResourceData) (*redis.CommonPropertiesRedisConfiguration, error) {
output := &redis.CommonPropertiesRedisConfiguration{
AdditionalProperties: map[string]interface{}{},
}

input := d.Get("redis_configuration").([]interface{})
if len(input) == 0 || input[0] == nil {
Expand All @@ -742,62 +743,62 @@ func expandRedisConfiguration(d *pluginsdk.ResourceData) (map[string]*string, er
raw := input[0].(map[string]interface{})

if v := raw["maxclients"].(int); v > 0 {
output["maxclients"] = utils.String(strconv.Itoa(v))
output.Maxclients = utils.String(strconv.Itoa(v))
}

if d.Get("sku_name").(string) != string(redis.SkuNameBasic) {
if v := raw["maxmemory_delta"].(int); v > 0 {
output["maxmemory-delta"] = utils.String(strconv.Itoa(v))
output.MaxmemoryDelta = utils.String(strconv.Itoa(v))
}

if v := raw["maxmemory_reserved"].(int); v > 0 {
output["maxmemory-reserved"] = utils.String(strconv.Itoa(v))
output.MaxmemoryReserved = utils.String(strconv.Itoa(v))
}

if v := raw["maxfragmentationmemory_reserved"].(int); v > 0 {
output["maxfragmentationmemory-reserved"] = utils.String(strconv.Itoa(v))
output.MaxfragmentationmemoryReserved = utils.String(strconv.Itoa(v))
}
}

if v := raw["maxmemory_policy"].(string); v != "" {
output["maxmemory-policy"] = utils.String(v)
output.MaxmemoryPolicy = utils.String(v)
}

// 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")
}
output["rdb-backup-enabled"] = utils.String(strconv.FormatBool(v))
output.RdbBackupEnabled = utils.String(strconv.FormatBool(v))
}

if v := raw["rdb_backup_frequency"].(int); v > 0 {
output["rdb-backup-frequency"] = utils.String(strconv.Itoa(v))
output.RdbBackupFrequency = utils.String(strconv.Itoa(v))
}

if v := raw["rdb_backup_max_snapshot_count"].(int); v > 0 {
output["rdb-backup-max-snapshot-count"] = utils.String(strconv.Itoa(v))
output.RdbBackupMaxSnapshotCount = utils.String(strconv.Itoa(v))
}

if v := raw["rdb_storage_connection_string"].(string); v != "" {
output["rdb-storage-connection-string"] = utils.String(v)
output.RdbStorageConnectionString = utils.String(v)
}

if v := raw["notify_keyspace_events"].(string); v != "" {
output["notify-keyspace-events"] = utils.String(v)
output.AdditionalProperties["notify-keyspace-events"] = utils.String(v)
}

// AOF Backup
if v := raw["aof_backup_enabled"].(bool); v {
output["aof-backup-enabled"] = utils.String(strconv.FormatBool(v))
output.AdditionalProperties["aof-backup-enabled"] = utils.String(strconv.FormatBool(v))
}

if v := raw["aof_storage_connection_string_0"].(string); v != "" {
output["aof-storage-connection-string-0"] = utils.String(v)
output.AofStorageConnectionString0 = utils.String(v)
}

if v := raw["aof_storage_connection_string_1"].(string); v != "" {
output["aof-storage-connection-string-1"] = utils.String(v)
output.AofStorageConnectionString1 = utils.String(v)
}

authEnabled := raw["enable_authentication"].(bool)
Expand All @@ -808,7 +809,7 @@ func expandRedisConfiguration(d *pluginsdk.ResourceData) (map[string]*string, er
}
} else {
value := isAuthNotRequiredAsString(authEnabled)
output["authnotrequired"] = utils.String(value)
output.AdditionalProperties["authnotrequired"] = utils.String(value)
}
return output, nil
}
Expand Down Expand Up @@ -864,89 +865,89 @@ func flattenTenantSettings(input map[string]*string) map[string]*string {
return output
}

func flattenRedisConfiguration(input map[string]*string) ([]interface{}, error) {
outputs := make(map[string]interface{}, len(input))
func flattenRedisConfiguration(input *redis.CommonPropertiesRedisConfiguration) ([]interface{}, error) {
outputs := make(map[string]interface{})

if v := input["maxclients"]; v != nil {
i, err := strconv.Atoi(*v)
if input.Maxclients != nil {
i, err := strconv.Atoi(*input.Maxclients)
if err != nil {
return nil, fmt.Errorf("parsing `maxclients` %q: %+v", *v, err)
return nil, fmt.Errorf("parsing `maxclients` %q: %+v", *input.Maxclients, err)
}
outputs["maxclients"] = i
}
if v := input["maxmemory-delta"]; v != nil {
i, err := strconv.Atoi(*v)
if input.MaxmemoryDelta != nil {
i, err := strconv.Atoi(*input.MaxmemoryDelta)
if err != nil {
return nil, fmt.Errorf("parsing `maxmemory-delta` %q: %+v", *v, err)
return nil, fmt.Errorf("parsing `maxmemory-delta` %q: %+v", *input.MaxmemoryDelta, err)
}
outputs["maxmemory_delta"] = i
}
if v := input["maxmemory-reserved"]; v != nil {
i, err := strconv.Atoi(*v)
if input.MaxmemoryReserved != nil {
i, err := strconv.Atoi(*input.MaxmemoryReserved)
if err != nil {
return nil, fmt.Errorf("parsing `maxmemory-reserved` %q: %+v", *v, err)
return nil, fmt.Errorf("parsing `maxmemory-reserved` %q: %+v", *input.MaxmemoryReserved, err)
}
outputs["maxmemory_reserved"] = i
}
if v := input["maxmemory-policy"]; v != nil {
outputs["maxmemory_policy"] = *v
if input.MaxmemoryPolicy != nil {
outputs["maxmemory_policy"] = *input.MaxmemoryPolicy
}

if v := input["maxfragmentationmemory-reserved"]; v != nil {
i, err := strconv.Atoi(*v)
if input.MaxfragmentationmemoryReserved != nil {
i, err := strconv.Atoi(*input.MaxfragmentationmemoryReserved)
if err != nil {
return nil, fmt.Errorf("parsing `maxfragmentationmemory-reserved` %q: %+v", *v, err)
return nil, fmt.Errorf("parsing `maxfragmentationmemory-reserved` %q: %+v", *input.MaxfragmentationmemoryReserved, err)
}
outputs["maxfragmentationmemory_reserved"] = i
}

// delta, reserved, enabled, frequency,, count,
if v := input["rdb-backup-enabled"]; v != nil {
b, err := strconv.ParseBool(*v)
if input.RdbBackupEnabled != nil {
b, err := strconv.ParseBool(*input.RdbBackupEnabled)
if err != nil {
return nil, fmt.Errorf("parsing `rdb-backup-enabled` %q: %+v", *v, err)
return nil, fmt.Errorf("parsing `rdb-backup-enabled` %q: %+v", *input.RdbBackupEnabled, err)
}
outputs["rdb_backup_enabled"] = b
}
if v := input["rdb-backup-frequency"]; v != nil {
i, err := strconv.Atoi(*v)
if input.RdbBackupFrequency != nil {
i, err := strconv.Atoi(*input.RdbBackupFrequency)
if err != nil {
return nil, fmt.Errorf("parsing `rdb-backup-frequency` %q: %+v", *v, err)
return nil, fmt.Errorf("parsing `rdb-backup-frequency` %q: %+v", *input.RdbBackupFrequency, err)
}
outputs["rdb_backup_frequency"] = i
}
if v := input["rdb-backup-max-snapshot-count"]; v != nil {
i, err := strconv.Atoi(*v)
if input.RdbBackupMaxSnapshotCount != nil {
i, err := strconv.Atoi(*input.RdbBackupMaxSnapshotCount)
if err != nil {
return nil, fmt.Errorf("parsing `rdb-backup-max-snapshot-count` %q: %+v", *v, err)
return nil, fmt.Errorf("parsing `rdb-backup-max-snapshot-count` %q: %+v", *input.RdbBackupMaxSnapshotCount, err)
}
outputs["rdb_backup_max_snapshot_count"] = i
}
if v := input["rdb-storage-connection-string"]; v != nil {
outputs["rdb_storage_connection_string"] = *v
if input.RdbStorageConnectionString != nil {
outputs["rdb_storage_connection_string"] = *input.RdbStorageConnectionString
}
if v := input["notify-keyspace-events"]; v != nil {
outputs["notify_keyspace_events"] = *v
if v := input.AdditionalProperties["notify-keyspace-events"]; v != nil {
outputs["notify_keyspace_events"] = v
}

if v := input["aof-backup-enabled"]; v != nil {
b, err := strconv.ParseBool(*v)
if v := input.AdditionalProperties["aof-backup-enabled"]; v != nil {
b, err := strconv.ParseBool(v.(string))
if err != nil {
return nil, fmt.Errorf("parsing `aof-backup-enabled` %q: %+v", *v, err)
return nil, fmt.Errorf("parsing `aof-backup-enabled` %q: %+v", v, err)
}
outputs["aof_backup_enabled"] = b
}
if v := input["aof-storage-connection-string-0"]; v != nil {
outputs["aof_storage_connection_string_0"] = *v
if input.AofStorageConnectionString0 != nil {
outputs["aof_storage_connection_string_0"] = *input.AofStorageConnectionString0
}
if v := input["aof-storage-connection-string-1"]; v != nil {
outputs["aof_storage_connection_string_1"] = *v
if input.AofStorageConnectionString1 != nil {
outputs["aof_storage_connection_string_1"] = *input.AofStorageConnectionString1
}

// `authnotrequired` is not set for instances launched outside a VNET
outputs["enable_authentication"] = true
if v := input["authnotrequired"]; v != nil {
outputs["enable_authentication"] = isAuthRequiredAsBool(*v)
if v := input.AdditionalProperties["authnotrequired"]; v != nil {
outputs["enable_authentication"] = isAuthRequiredAsBool(v.(string))
}

return []interface{}{outputs}, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/services/redis/redis_firewall_rule_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"time"

"github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2020-12-01/redis"
"github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2021-06-01/redis"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down
2 changes: 1 addition & 1 deletion internal/services/redis/redis_linked_server_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"log"
"time"

"github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2020-12-01/redis"
"github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2021-06-01/redis"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading