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

Very slight behaviour change and extra tests #567

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
17 changes: 6 additions & 11 deletions provider/resource_rediscloud_pro_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,12 @@ func resourceRedisCloudProDatabase() *schema.Resource {
Description: "(Deprecated) Maximum memory usage for this specific database",
Type: schema.TypeFloat,
Optional: true,
Computed: true,
ExactlyOneOf: []string{"memory_limit_in_gb", "dataset_size_in_gb"},
},
"dataset_size_in_gb": {
Description: "Maximum amount of data in the dataset for this specific database in GB",
Type: schema.TypeFloat,
Optional: true,
Computed: true,
ExactlyOneOf: []string{"memory_limit_in_gb", "dataset_size_in_gb"},
},
"support_oss_cluster_api": {
Expand Down Expand Up @@ -659,16 +657,14 @@ 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 {
// The user (state) has one of dataset_size_in_gb and memory_limit_in_gb
if _, inState := d.GetOk("dataset_size_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 _, inState := d.GetOk("memory_limit_in_gb"); inState {
if err := d.Set("memory_limit_in_gb", redis.Float64Value(db.MemoryLimitInGB)); err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -827,10 +823,9 @@ 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("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))
}
}
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
216 changes: 210 additions & 6 deletions provider/resource_rediscloud_pro_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,10 @@ func TestAccResourceRedisCloudProDatabase_CRUDI(t *testing.T) {
},
// Test that that database is imported successfully
{
ResourceName: "rediscloud_subscription_database.no_password_database",
ImportState: true,
ImportStateVerify: true,
ResourceName: "rediscloud_subscription_database.no_password_database",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"dataset_size_in_gb"},
},
},
})
Expand Down Expand Up @@ -217,9 +218,10 @@ func TestAccResourceRedisCloudProDatabase_MultiModules(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"dataset_size_in_gb"},
},
},
})
Expand Down Expand Up @@ -257,6 +259,193 @@ func TestAccResourceRedisCloudProDatabase_respversion(t *testing.T) {
})
}

func TestAccResourceRedisCloudProDatabase_datasetSizeWithReplication(t *testing.T) {
name := acctest.RandomWithPrefix(testResourcePrefix)
subName := name + "-subscription"
dbName := name + "-database"
const resourceName = "rediscloud_subscription_database.example"
testCloudAccountName := os.Getenv("AWS_TEST_CLOUD_ACCOUNT_NAME")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccAwsPreExistingCloudAccountPreCheck(t) },
ProviderFactories: providerFactories,
CheckDestroy: testAccCheckProSubscriptionDestroy,
Steps: []resource.TestStep{
// Test database creation with dataset_size_in_gb
{
Config: fmt.Sprintf(testAccResourceRedisCloudProDatabaseDatasetMemory, testCloudAccountName, subName, dbName, "dataset_size_in_gb = 2", true),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "dataset_size_in_gb", "2"),
resource.TestCheckNoResourceAttr(resourceName, "memory_limit_in_gb"),
),
},
// Test dataset_size_in_gb updates
{
Config: fmt.Sprintf(testAccResourceRedisCloudProDatabaseDatasetMemory, testCloudAccountName, subName, dbName, "dataset_size_in_gb = 1", true),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "dataset_size_in_gb", "1"),
resource.TestCheckNoResourceAttr(resourceName, "memory_limit_in_gb"),
),
},
// Test switch to memory_limit_in_gb
{
Config: fmt.Sprintf(testAccResourceRedisCloudProDatabaseDatasetMemory, testCloudAccountName, subName, dbName, "memory_limit_in_gb = 1", true),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "dataset_size_in_gb", "0"),
resource.TestCheckResourceAttr(resourceName, "memory_limit_in_gb", "1"),
),
},
// Test memory_limit_in_gb updates
{
Config: fmt.Sprintf(testAccResourceRedisCloudProDatabaseDatasetMemory, testCloudAccountName, subName, dbName, "memory_limit_in_gb = 2", true),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "dataset_size_in_gb", "0"),
resource.TestCheckResourceAttr(resourceName, "memory_limit_in_gb", "2"),
),
},
// Test switch back to dataset_size_in_gb
{
Config: fmt.Sprintf(testAccResourceRedisCloudProDatabaseDatasetMemory, testCloudAccountName, subName, dbName, "dataset_size_in_gb = 1", true),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "dataset_size_in_gb", "1"),
resource.TestCheckResourceAttr(resourceName, "memory_limit_in_gb", "0"),
),
},
// Test that that database is imported successfully
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"dataset_size_in_gb", "memory_limit_in_gb"},
},
},
})
}

func TestAccResourceRedisCloudProDatabase_datasetSizeWithoutReplication(t *testing.T) {
name := acctest.RandomWithPrefix(testResourcePrefix)
subName := name + "-subscription"
dbName := name + "-database"
const resourceName = "rediscloud_subscription_database.example"
testCloudAccountName := os.Getenv("AWS_TEST_CLOUD_ACCOUNT_NAME")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccAwsPreExistingCloudAccountPreCheck(t) },
ProviderFactories: providerFactories,
CheckDestroy: testAccCheckProSubscriptionDestroy,
Steps: []resource.TestStep{
// Test database creation with dataset_size_in_gb
{
Config: fmt.Sprintf(testAccResourceRedisCloudProDatabaseDatasetMemory, testCloudAccountName, subName, dbName, "dataset_size_in_gb = 2", false),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "dataset_size_in_gb", "2"),
resource.TestCheckNoResourceAttr(resourceName, "memory_limit_in_gb"),
),
},
// Test dataset_size_in_gb updates
{
Config: fmt.Sprintf(testAccResourceRedisCloudProDatabaseDatasetMemory, testCloudAccountName, subName, dbName, "dataset_size_in_gb = 1", false),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "dataset_size_in_gb", "1"),
resource.TestCheckNoResourceAttr(resourceName, "memory_limit_in_gb"),
),
},
// Test switch to memory_limit_in_gb
{
Config: fmt.Sprintf(testAccResourceRedisCloudProDatabaseDatasetMemory, testCloudAccountName, subName, dbName, "memory_limit_in_gb = 1", false),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "dataset_size_in_gb", "0"),
resource.TestCheckResourceAttr(resourceName, "memory_limit_in_gb", "1"),
),
},
// Test memory_limit_in_gb updates
{
Config: fmt.Sprintf(testAccResourceRedisCloudProDatabaseDatasetMemory, testCloudAccountName, subName, dbName, "memory_limit_in_gb = 2", false),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "dataset_size_in_gb", "0"),
resource.TestCheckResourceAttr(resourceName, "memory_limit_in_gb", "2"),
),
}, // Test switch back to dataset_size_in_gb
{
Config: fmt.Sprintf(testAccResourceRedisCloudProDatabaseDatasetMemory, testCloudAccountName, subName, dbName, "dataset_size_in_gb = 1", false),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "dataset_size_in_gb", "1"),
resource.TestCheckResourceAttr(resourceName, "memory_limit_in_gb", "0"),
),
},
// Test that that database is imported successfully
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"dataset_size_in_gb", "memory_limit_in_gb"},
},
},
})
}

func TestAccResourceRedisCloudProDatabase_datasetSizeStartAsMemoryLimit(t *testing.T) {
name := acctest.RandomWithPrefix(testResourcePrefix)
subName := name + "-subscription"
dbName := name + "-database"
const resourceName = "rediscloud_subscription_database.example"
testCloudAccountName := os.Getenv("AWS_TEST_CLOUD_ACCOUNT_NAME")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccAwsPreExistingCloudAccountPreCheck(t) },
ProviderFactories: providerFactories,
CheckDestroy: testAccCheckProSubscriptionDestroy,
Steps: []resource.TestStep{
// Test database creation with memory_limit_in_gb
{
Config: fmt.Sprintf(testAccResourceRedisCloudProDatabaseDatasetMemory, testCloudAccountName, subName, dbName, "memory_limit_in_gb = 2", false),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckNoResourceAttr(resourceName, "dataset_size_in_gb"),
resource.TestCheckResourceAttr(resourceName, "memory_limit_in_gb", "2"),
),
},
// Test memory_limit_in_gb updates
{
Config: fmt.Sprintf(testAccResourceRedisCloudProDatabaseDatasetMemory, testCloudAccountName, subName, dbName, "memory_limit_in_gb = 1", false),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckNoResourceAttr(resourceName, "dataset_size_in_gb"),
resource.TestCheckResourceAttr(resourceName, "memory_limit_in_gb", "1"),
),
},
// Test switch to dataset_size_in_gb
{
Config: fmt.Sprintf(testAccResourceRedisCloudProDatabaseDatasetMemory, testCloudAccountName, subName, dbName, "dataset_size_in_gb = 1", false),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "dataset_size_in_gb", "1"),
resource.TestCheckResourceAttr(resourceName, "memory_limit_in_gb", "0"),
),
},
// Test dataset_size_in_gb updates
{
Config: fmt.Sprintf(testAccResourceRedisCloudProDatabaseDatasetMemory, testCloudAccountName, subName, dbName, "dataset_size_in_gb = 2", false),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "dataset_size_in_gb", "2"),
resource.TestCheckResourceAttr(resourceName, "memory_limit_in_gb", "0"),
),
}, // Test switch back to memory_limit_in_gb
{
Config: fmt.Sprintf(testAccResourceRedisCloudProDatabaseDatasetMemory, testCloudAccountName, subName, dbName, "memory_limit_in_gb = 1", false),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "memory_limit_in_gb", "1"),
resource.TestCheckResourceAttr(resourceName, "dataset_size_in_gb", "0"),
),
},
// Test that that database is imported successfully
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"dataset_size_in_gb", "memory_limit_in_gb"},
},
},
})
}

const proSubscriptionBoilerplate = `
data "rediscloud_payment_method" "card" {
card_type = "Visa"
Expand Down Expand Up @@ -524,3 +713,18 @@ resource "rediscloud_subscription_database" "example" {
resp_version = "%s"
}
`

const testAccResourceRedisCloudProDatabaseDatasetMemory = proSubscriptionBoilerplate + `

resource "rediscloud_subscription_database" "example" {
subscription_id = rediscloud_subscription.example.id
name = "%s"
# This is the dataset_size_in_gb/memory_limit_in_gb line
%s
data_persistence = "none"
data_eviction = "noeviction"
throughput_measurement_by = "operations-per-second"
throughput_measurement_value = 1000
replication = %t
}
`
4 changes: 2 additions & 2 deletions provider/resource_rediscloud_pro_tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestAccResourceRedisCloudSubscription_createWithDatabaseWithEnabledTlsAndSs
ResourceName: databaseName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"client_ssl_certificate", "client_tls_certificates"},
ImportStateVerifyIgnore: []string{"client_ssl_certificate", "client_tls_certificates", "dataset_size_in_gb"},
},
},
})
Expand Down Expand Up @@ -361,7 +361,7 @@ func TestAccResourceRedisCloudSubscription_createWithDatabaseWithEnabledTlsAndTl
ResourceName: databaseName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"client_tls_certificates"},
ImportStateVerifyIgnore: []string{"client_tls_certificates", "dataset_size_in_gb"},
},
},
})
Expand Down
Loading