Skip to content

Commit

Permalink
Lower-case keys and values, no single-character keys/values
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnSharpe committed Aug 30, 2024
1 parent 4e888dd commit ee4d29f
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ The following arguments are supported:
* `global_resp_version` - (Optional) Either 'resp2' or 'resp3'. Resp version for Crdb databases within the AA database. Must be compatible with Redis version.
* `port` - (Optional) TCP port on which the database is available - must be between 10000 and 19999. **Modifying this attribute will force creation of a new resource.**
* `override_region` - (Optional) Override region specific configuration, documented below
* `tags` - (Optional) A string/string map of tags to associate with this database. Note that all keys must be lowercase.
* `tags` - (Optional) A string/string map of tags to associate with this database. Note that all keys and values must be lowercase.

The `override_region` block supports:

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/rediscloud_essentials_database.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ The following arguments are supported:
* `password` - (Optional) Password to access the database. If not specified, a random 32 character long alphanumeric password will be automatically generated.
* `enable_default_user` - (Optional) When `true` enables connecting to the database with the default user. Default `true`.
* `alert` - (Optional) A block defining Redis database alert. Can be specified multiple times. Documented below.
* `tags` - (Optional) A string/string map of tags to associate with this database. Note that all keys must be lowercase.
* `tags` - (Optional) A string/string map of tags to associate with this database. Note that all keys and values must be lowercase.
* `modules` - (Optional) A list of modules objects, documented below. **Modifying this attribute will force creation of a new resource.**
* `enable_payg_features` - (Optional) Whether to enable features restricted to Pay-As-You-Go legacy databases. It is not supported for new databases. Default `false`.
* `memory_limit_in_gb` - (Optional) **Only used with Pay-As-You-Go databases.** Maximum memory usage for the database.
Expand Down
4 changes: 2 additions & 2 deletions docs/resources/rediscloud_subscription_database.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ resource "rediscloud_subscription_database" "database-resource" {
}
tags = {
"market" = "EMEA"
"market" = "emea"
}
}
```
Expand Down Expand Up @@ -110,7 +110,7 @@ The following arguments are supported:
* `port` - (Optional) TCP port on which the database is available - must be between 10000 and 19999. **Modifying this attribute will force creation of a new resource.**
* `remote_backup` (Optional) Specifies the backup options for the database, documented below
* `enable_default_user` (Optional) When `true` enables connecting to the database with the default user. Default `true`.
* `tags` - (Optional) A string/string map of Tags to associate with this database. Note that all keys must be lowercase.
* `tags` - (Optional) A string/string map of Tags to associate with this database. Note that all keys and values must be lowercase.

The `alert` block supports:

Expand Down
6 changes: 3 additions & 3 deletions provider/rediscloud_active_active_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestAccResourceRedisCloudActiveActiveDatabase_CRUDI(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "override_region.1.override_source_ips.#", "0"),

resource.TestCheckResourceAttr(resourceName, "tags.deployment_family", "blue"),
resource.TestCheckResourceAttr(resourceName, "tags.priority", "2"),
resource.TestCheckResourceAttr(resourceName, "tags.priority", "code-2"),

// Test databases exist
func(s *terraform.State) error {
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestAccResourceRedisCloudActiveActiveDatabase_CRUDI(t *testing.T) {
resource.TestCheckResourceAttr(datasourceName, "global_modules.0", "RedisJSON"),

resource.TestCheckResourceAttr(datasourceName, "tags.deployment_family", "blue"),
resource.TestCheckResourceAttr(datasourceName, "tags.priority", "2"),
resource.TestCheckResourceAttr(datasourceName, "tags.priority", "code-2"),
),
},
// Test database is updated successfully, including updates to both global and local alerts and clearing modules
Expand Down Expand Up @@ -312,7 +312,7 @@ resource "rediscloud_active_active_subscription_database" "example" {
tags = {
"deployment_family" = "blue"
"priority" = "2"
"priority" = "code-2"
}
}
Expand Down
2 changes: 1 addition & 1 deletion provider/rediscloud_essentials_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestAccRedisCloudEssentialsDatabase_BasicCRUDI(t *testing.T) {
},
{
Config: fmt.Sprintf(testAccResourceRedisCloudEssentialsDatabaseBasicWithUpperCaseTagKey, subscriptionName, databaseName),
ExpectError: regexp.MustCompile("tag keys must be lower case, invalid keys: UpperCaseKey"),
ExpectError: regexp.MustCompile("tag keys and values must be lower case, invalid keys: UpperCaseKey"),
},
{
Config: fmt.Sprintf(testAccResourceRedisCloudEssentialsDatabaseBasic, subscriptionName, databaseNameUpdated),
Expand Down
14 changes: 9 additions & 5 deletions provider/resource_rediscloud_pro_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -1043,15 +1043,19 @@ func writeTags(ctx context.Context, api *apiClient, subId int, databaseId int, d

func validateTagsfunc(tagsRaw interface{}, _ cty.Path) diag.Diagnostics {
tags := tagsRaw.(map[string]interface{})
invalidKeys := make([]string, 0)
for k := range tags {
invalid := make([]string, 0)
for k, v := range tags {
if k != strings.ToLower(k) {
invalidKeys = append(invalidKeys, k)
invalid = append(invalid, k)
}
vStr := v.(string)
if vStr != strings.ToLower(vStr) {
invalid = append(invalid, vStr)
}
}

if len(invalidKeys) > 0 {
return diag.Errorf("tag keys must be lower case, invalid keys: %s", strings.Join(invalidKeys, ", "))
if len(invalid) > 0 {
return diag.Errorf("tag keys and values must be lower case, invalid entries: %s", strings.Join(invalid, ", "))
}
return nil
}
4 changes: 2 additions & 2 deletions provider/resource_rediscloud_pro_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestAccResourceRedisCloudProDatabase_CRUDI(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "modules.0.name", "RedisBloom"),
resource.TestCheckResourceAttr(resourceName, "enable_default_user", "true"),

resource.TestCheckResourceAttr(resourceName, "tags.market", "EMEA"),
resource.TestCheckResourceAttr(resourceName, "tags.market", "emea"),
resource.TestCheckResourceAttr(resourceName, "tags.material", "cardboard"),

// Replica tests
Expand Down Expand Up @@ -372,7 +372,7 @@ resource "rediscloud_subscription_database" "example" {
]
tags = {
"market" = "EMEA"
"market" = "emea"
"material" = "cardboard"
}
}
Expand Down

0 comments on commit ee4d29f

Please sign in to comment.