Skip to content

Commit

Permalink
fix issue with update
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-oc committed Sep 3, 2024
1 parent bc21a7c commit 3c1919d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 23 deletions.
25 changes: 16 additions & 9 deletions provider/resource_rediscloud_active_active_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,16 +633,23 @@ func resourceRedisCloudActiveActiveDatabaseRead(ctx context.Context, d *schema.R
return diag.FromErr(err)
}

if err := d.Set("memory_limit_in_gb", redis.Float64(*db.CrdbDatabases[0].MemoryLimitInGB)); err != nil {
if err := d.Set("enable_tls", redis.BoolValue(db.CrdbDatabases[0].Security.EnableTls)); err != nil {
return diag.FromErr(err)
}

if err := d.Set("dataset_size_in_gb", redis.Float64(*db.CrdbDatabases[0].DatasetSizeInGB)); err != nil {
return diag.FromErr(err)
// To prevent both fields being included in API requests, only one of these two fields should be set in the state
// Only add `dataset_size_in_gb` to the state if `memory_limit_in_gb` is not already in the state
if _, inState := d.GetOk("memory_limit_in_gb"); !inState {
if err := d.Set("dataset_size_in_gb", redis.Float64(*db.CrdbDatabases[0].DatasetSizeInGB)); err != nil {
return diag.FromErr(err)
}
}

if err := d.Set("enable_tls", redis.BoolValue(db.CrdbDatabases[0].Security.EnableTls)); err != nil {
return diag.FromErr(err)
// Likewise, only add `memory_limit_in_gb` to the state if `dataset_size_in_gb` is not already in the state
if _, inState := d.GetOk("dataset_size_in_gb"); !inState {
if err := d.Set("memory_limit_in_gb", redis.Float64(*db.CrdbDatabases[0].MemoryLimitInGB)); err != nil {
return diag.FromErr(err)
}
}

var regionDbConfigs []map[string]interface{}
Expand Down Expand Up @@ -867,14 +874,14 @@ func resourceRedisCloudActiveActiveDatabaseUpdate(ctx context.Context, d *schema
}

// One of the following fields must be set in the request, validation is handled in the schema (ExactlyOneOf)
if v, ok := d.GetOk("memory_limit_in_gb"); ok {
update.MemoryLimitInGB = redis.Float64(v.(float64))
}

if v, ok := d.GetOk("dataset_size_in_gb"); ok {
update.DatasetSizeInGB = redis.Float64(v.(float64))
}

if v, ok := d.GetOk("memory_limit_in_gb"); ok {
update.MemoryLimitInGB = redis.Float64(v.(float64))
}

// The below fields are optional and will only be sent in the request if they are present in the Terraform configuration
if len(globalSourceIps) == 0 {
update.GlobalSourceIP = []*string{redis.String("0.0.0.0/0")}
Expand Down
36 changes: 22 additions & 14 deletions provider/resource_rediscloud_pro_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package provider
import (
"context"
"fmt"
redisTags "github.com/RedisLabs/rediscloud-go-api/service/tags"
"github.com/hashicorp/go-cty/cty"
"strconv"
"strings"
"time"

redisTags "github.com/RedisLabs/rediscloud-go-api/service/tags"
"github.com/hashicorp/go-cty/cty"

"github.com/RedisLabs/rediscloud-go-api/redis"
"github.com/RedisLabs/rediscloud-go-api/service/databases"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -605,14 +606,6 @@ func resourceRedisCloudProDatabaseRead(ctx context.Context, d *schema.ResourceDa
return diag.FromErr(err)
}

if err := d.Set("memory_limit_in_gb", redis.Float64Value(db.MemoryLimitInGB)); err != nil {
return diag.FromErr(err)
}

if err := d.Set("dataset_size_in_gb", redis.Float64Value(db.DatasetSizeInGB)); err != nil {
return diag.FromErr(err)
}

if err := d.Set("support_oss_cluster_api", redis.BoolValue(db.SupportOSSClusterAPI)); err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -666,6 +659,21 @@ func resourceRedisCloudProDatabaseRead(ctx context.Context, d *schema.ResourceDa
return diag.FromErr(err)
}

// To prevent both fields being included in API requests, only one of these two fields should be set in the state
// Only add `dataset_size_in_gb` to the state if `memory_limit_in_gb` is not already in the state
if _, inState := d.GetOk("memory_limit_in_gb"); !inState {
if err := d.Set("dataset_size_in_gb", redis.Float64Value(db.DatasetSizeInGB)); err != nil {
return diag.FromErr(err)
}
}

// Likewise, only add `memory_limit_in_gb` to the state if `dataset_size_in_gb` is not already in the state
if _, inState := d.GetOk("dataset_size_in_gb"); !inState {
if err := d.Set("memory_limit_in_gb", redis.Float64Value(db.MemoryLimitInGB)); err != nil {
return diag.FromErr(err)
}
}

password := d.Get("password").(string)
if redis.StringValue(db.Protocol) == "redis" {
// Only db with the "redis" protocol returns the password.
Expand Down Expand Up @@ -817,12 +825,12 @@ func resourceRedisCloudProDatabaseUpdate(ctx context.Context, d *schema.Resource
}

// One of the following fields must be set, validation is handled in the schema (ExactlyOneOf)
if v, ok := d.GetOk("memory_limit_in_gb"); ok {
update.MemoryLimitInGB = redis.Float64(v.(float64))
}

if v, ok := d.GetOk("dataset_size_in_gb"); ok {
update.DatasetSizeInGB = redis.Float64(v.(float64))
} else {
if v, ok := d.GetOk("memory_limit_in_gb"); ok {
update.MemoryLimitInGB = redis.Float64(v.(float64))
}
}

// The below fields are optional and will only be sent in the request if they are present in the Terraform configuration
Expand Down

0 comments on commit 3c1919d

Please sign in to comment.