Support Redis configuration (#1706)

<!-- This change is generated by MagicModules. -->
/cc @edevil 

Fixes #1547
This commit is contained in:
The Magician 2018-07-02 10:16:38 -07:00 committed by Dana Hoffman
parent 18e0d423d6
commit ded4eb8c64
3 changed files with 56 additions and 0 deletions

View File

@ -75,6 +75,11 @@ func resourceRedisInstance() *schema.Resource {
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"redis_configs": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"location_id": {
Type: schema.TypeString,
Computed: true,
@ -165,6 +170,12 @@ func resourceRedisInstanceCreate(d *schema.ResourceData, meta interface{}) error
} else if v, ok := d.GetOkExists("labels"); !isEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
obj["labels"] = labelsProp
}
redisConfigsProp, err := expandRedisInstanceRedisConfigs(d.Get("redis_configs"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("redis_configs"); !isEmptyValue(reflect.ValueOf(redisConfigsProp)) && (ok || !reflect.DeepEqual(v, redisConfigsProp)) {
obj["redisConfigs"] = redisConfigsProp
}
locationIdProp, err := expandRedisInstanceLocationId(d.Get("location_id"), d, config)
if err != nil {
return err
@ -296,6 +307,9 @@ func resourceRedisInstanceRead(d *schema.ResourceData, meta interface{}) error {
if err := d.Set("labels", flattenRedisInstanceLabels(res["labels"])); err != nil {
return fmt.Errorf("Error reading Instance: %s", err)
}
if err := d.Set("redis_configs", flattenRedisInstanceRedisConfigs(res["redisConfigs"])); err != nil {
return fmt.Errorf("Error reading Instance: %s", err)
}
if err := d.Set("location_id", flattenRedisInstanceLocationId(res["locationId"])); err != nil {
return fmt.Errorf("Error reading Instance: %s", err)
}
@ -360,6 +374,12 @@ func resourceRedisInstanceUpdate(d *schema.ResourceData, meta interface{}) error
} else if v, ok := d.GetOkExists("labels"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
obj["labels"] = labelsProp
}
redisConfigsProp, err := expandRedisInstanceRedisConfigs(d.Get("redis_configs"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("redis_configs"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, redisConfigsProp)) {
obj["redisConfigs"] = redisConfigsProp
}
locationIdProp, err := expandRedisInstanceLocationId(d.Get("location_id"), d, config)
if err != nil {
return err
@ -420,6 +440,9 @@ func resourceRedisInstanceUpdate(d *schema.ResourceData, meta interface{}) error
if d.HasChange("memory_size_gb") {
updateMask = append(updateMask, "memorySizeGb")
}
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 = addQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
@ -528,6 +551,10 @@ func flattenRedisInstanceLabels(v interface{}) interface{} {
return v
}
func flattenRedisInstanceRedisConfigs(v interface{}) interface{} {
return v
}
func flattenRedisInstanceLocationId(v interface{}) interface{} {
return v
}
@ -602,6 +629,17 @@ func expandRedisInstanceLabels(v interface{}, d *schema.ResourceData, config *Co
return m, nil
}
func expandRedisInstanceRedisConfigs(v interface{}, d *schema.ResourceData, config *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
}
func expandRedisInstanceLocationId(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
return v, nil
}

View File

@ -129,6 +129,11 @@ resource "google_redis_instance" "test" {
my_key = "my_val"
other_key = "other_val"
}
redis_configs {
maxmemory-policy = "allkeys-lru"
notify-keyspace-events = "KEA"
}
}`, name)
}
@ -143,6 +148,11 @@ resource "google_redis_instance" "test" {
my_key = "my_val"
other_key = "new_val"
}
redis_configs {
maxmemory-policy = "noeviction"
notify-keyspace-events = ""
}
}`, name)
}
@ -171,5 +181,10 @@ resource "google_redis_instance" "test" {
my_key = "my_val"
other_key = "other_val"
}
redis_configs {
maxmemory-policy = "allkeys-lru"
notify-keyspace-events = "KEA"
}
}`, network, name)
}

View File

@ -98,6 +98,9 @@ The following arguments are supported:
* `labels` -
(Optional)
Resource labels to represent user provided metadata.
* `redis_configs` -
(Optional)
Redis configuration parameters, according to http://redis.io/topics/config.
* `location_id` -
(Optional)
The zone where the instance will be provisioned. If not provided,