Skip to content

Commit

Permalink
Add redis_configs parameter to Redis Cluster (#10515) (#17956)
Browse files Browse the repository at this point in the history
[upstream:210578d95111726e35616730a7d6e004bb536a1b]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Apr 25, 2024
1 parent 1dea3f7 commit d827814
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
42 changes: 42 additions & 0 deletions google/services/redis/resource_redis_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ projects/{network_project_id_or_number}/global/networks/{network_id}.`,
Description: `The nodeType for the Redis cluster.
If not provided, REDIS_HIGHMEM_MEDIUM will be used as default Possible values: ["REDIS_SHARED_CORE_NANO", "REDIS_HIGHMEM_MEDIUM", "REDIS_HIGHMEM_XLARGE", "REDIS_STANDARD_SMALL"]`,
},
"redis_configs": {
Type: schema.TypeMap,
Optional: true,
Description: `Configure Redis Cluster behavior using a subset of native Redis configuration parameters.
Please check Memorystore documentation for the list of supported parameters:
https://cloud.google.com/memorystore/docs/cluster/supported-instance-configurations`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"region": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -309,6 +317,12 @@ func resourceRedisClusterCreate(d *schema.ResourceData, meta interface{}) error
} else if v, ok := d.GetOkExists("shard_count"); !tpgresource.IsEmptyValue(reflect.ValueOf(shardCountProp)) && (ok || !reflect.DeepEqual(v, shardCountProp)) {
obj["shardCount"] = shardCountProp
}
redisConfigsProp, err := expandRedisClusterRedisConfigs(d.Get("redis_configs"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("redis_configs"); !tpgresource.IsEmptyValue(reflect.ValueOf(redisConfigsProp)) && (ok || !reflect.DeepEqual(v, redisConfigsProp)) {
obj["redisConfigs"] = redisConfigsProp
}

url, err := tpgresource.ReplaceVars(d, config, "{{RedisBasePath}}projects/{{project}}/locations/{{region}}/clusters?clusterId={{name}}")
if err != nil {
Expand Down Expand Up @@ -455,6 +469,9 @@ func resourceRedisClusterRead(d *schema.ResourceData, meta interface{}) error {
if err := d.Set("shard_count", flattenRedisClusterShardCount(res["shardCount"], d, config)); err != nil {
return fmt.Errorf("Error reading Cluster: %s", err)
}
if err := d.Set("redis_configs", flattenRedisClusterRedisConfigs(res["redisConfigs"], d, config)); err != nil {
return fmt.Errorf("Error reading Cluster: %s", err)
}

return nil
}
Expand Down Expand Up @@ -493,6 +510,12 @@ func resourceRedisClusterUpdate(d *schema.ResourceData, meta interface{}) error
} else if v, ok := d.GetOkExists("shard_count"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, shardCountProp)) {
obj["shardCount"] = shardCountProp
}
redisConfigsProp, err := expandRedisClusterRedisConfigs(d.Get("redis_configs"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("redis_configs"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, redisConfigsProp)) {
obj["redisConfigs"] = redisConfigsProp
}

url, err := tpgresource.ReplaceVars(d, config, "{{RedisBasePath}}projects/{{project}}/locations/{{region}}/clusters/{{name}}")
if err != nil {
Expand All @@ -514,6 +537,10 @@ func resourceRedisClusterUpdate(d *schema.ResourceData, meta interface{}) error
if d.HasChange("shard_count") {
updateMask = append(updateMask, "shardCount")
}

if d.HasChange("redis_configs") {
updateMask = append(updateMask, "redisConfigs")
}
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
// won't set it
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
Expand Down Expand Up @@ -875,6 +902,10 @@ func flattenRedisClusterShardCount(v interface{}, d *schema.ResourceData, config
return v // let terraform core handle it otherwise
}

func flattenRedisClusterRedisConfigs(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func expandRedisClusterAuthorizationMode(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Expand Down Expand Up @@ -920,3 +951,14 @@ func expandRedisClusterReplicaCount(v interface{}, d tpgresource.TerraformResour
func expandRedisClusterShardCount(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandRedisClusterRedisConfigs(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
}
m := make(map[string]string)
for k, val := range v.(map[string]interface{}) {
m[k] = val.(string)
}
return m, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ resource "google_redis_cluster" "cluster-ha" {
node_type = "REDIS_SHARED_CORE_NANO"
transit_encryption_mode = "TRANSIT_ENCRYPTION_MODE_DISABLED"
authorization_mode = "AUTH_MODE_DISABLED"
redis_configs = {
maxmemory-policy = "volatile-ttl"
}
depends_on = [
google_network_connectivity_service_connection_policy.default
]
Expand Down
9 changes: 9 additions & 0 deletions website/docs/r/redis_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ resource "google_redis_cluster" "cluster-ha" {
node_type = "REDIS_SHARED_CORE_NANO"
transit_encryption_mode = "TRANSIT_ENCRYPTION_MODE_DISABLED"
authorization_mode = "AUTH_MODE_DISABLED"
redis_configs = {
maxmemory-policy = "volatile-ttl"
}
depends_on = [
google_network_connectivity_service_connection_policy.default
]
Expand Down Expand Up @@ -137,6 +140,12 @@ The following arguments are supported:
(Optional)
Optional. The number of replica nodes per shard.

* `redis_configs` -
(Optional)
Configure Redis Cluster behavior using a subset of native Redis configuration parameters.
Please check Memorystore documentation for the list of supported parameters:
https://cloud.google.com/memorystore/docs/cluster/supported-instance-configurations

* `region` -
(Optional)
The name of the region of the Redis cluster.
Expand Down

0 comments on commit d827814

Please sign in to comment.