Skip to content

Commit

Permalink
Adds dataset_size_in_gb attribute (#564)
Browse files Browse the repository at this point in the history
* adds dataset_size_in_gb attribute

* increment Go API version

* addresses PR comments

* adds dataset_size_in_gb attribute

* addresses PR comments

* fix issue with update

* fix UT and add to docs
  • Loading branch information
greg-oc authored Sep 5, 2024
1 parent 0726603 commit 2cd463c
Show file tree
Hide file tree
Showing 15 changed files with 237 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ data "rediscloud_active_active_subscription_database" "example" {
`id` is set to the ID of the found subscription and database in the following format: `{subscription_id}/{db_id}`

* `memory_limit_in_gb` - The maximum memory usage for the database.
* `dataset_size_in_gb` - Maximum amount of data in the dataset for this specific database in GB.
* `support_oss_cluster_api` - Supports the Redis open-source (OSS) Cluster API.
* `external_endpoint_for_oss_cluster_api` - Use the external endpoint for open-source (OSS) Cluster API.
* `enable_tls` - Enable TLS for database.
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/rediscloud_database.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ data "rediscloud_database" "example" {
* `name` - The name of the database
* `protocol` - The protocol of the database.
* `memory_limit_in_gb` - The maximum memory usage for the database.
* `dataset_size_in_gb` - Maximum amount of data in the dataset for this specific database in GB.
* `support_oss_cluster_api` - Supports the Redis open-source (OSS) Cluster API.
* `resp_version` - Either `resp2` or `resp3`. Database's RESP version.
* `replica_of` - The set of Redis database URIs, in the format `redis://user:password@host:port`, that this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ output "us-east-2-private-endpoints" {
The following arguments are supported:
* `subscription_id`: (Required) The ID of the Active-Active subscription to create the database in. **Modifying this attribute will force creation of a new resource.**
* `name` - (Required) A meaningful name to identify the database. **Modifying this attribute will force creation of a new resource.**
* `memory_limit_in_gb` - (Required) Maximum memory usage for this specific database, including replication and other overhead
* `memory_limit_in_gb` - (Optional - **Required if `dataset_size_in_gb` is unset**) Maximum memory usage for this specific database, including replication and other overhead **Deprecated in favor of `dataset_size_in_gb` - not possible to import databases with this attribute set**
* `dataset_size_in_gb` - (Optional - **Required if `memory_limit_in_gb` is unset**) The maximum amount of data in the dataset for this specific database is in GB
* `support_oss_cluster_api` - (Optional) Support Redis open-source (OSS) Cluster API. Default: ‘false’
* `external_endpoint_for_oss_cluster_api` - (Optional) Should use the external endpoint for open-source (OSS) Cluster API.
Can only be enabled if OSS Cluster API support is enabled. Default: 'false'
Expand Down Expand Up @@ -178,3 +179,5 @@ $ terraform import rediscloud_active_active_subscription_database.database-resou

Note: Due to constraints in the Redis Cloud API, the import process will not import global attributes or override region attributes. If you wish to use these attributes in your Terraform configuration, you will need to manually add them to your Terraform configuration and run `terraform apply` to update the database.

Additionally, the `memory_limit_in_gb` cannot be set during imports as it is deprecated. If you need to set the `memory_limit_in_gb` attribute, you will need to create a new database resource. It is recommended to use the `dataset_size_in_gb` attribute instead.

5 changes: 3 additions & 2 deletions docs/resources/rediscloud_subscription.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ resource "rediscloud_subscription" "subscription-resource" {
// This block needs to be defined for provisioning a new subscription.
// This allows creation of a well-optimized hardware specification for databases in the cluster
creation_plan {
memory_limit_in_gb = 15
dataset_size_in_gb = 15
quantity = 1
replication = true
throughput_measurement_by = "operations-per-second"
Expand Down Expand Up @@ -98,7 +98,8 @@ The `cloud_provider` block supports:

The `creation_plan` block supports:

* `memory_limit_in_gb` - (Required) Maximum memory usage that will be used for your largest planned database.
* `memory_limit_in_gb` - (Required) Maximum memory usage that will be used for your largest planned database. You can not set both dataset_size_in_gb and memory_limit_in_gb. **Deprecated: Use `dataset_size_in_gb` instead**
* `dataset_size_in_gb` - (Required) The maximum amount of data in the dataset for this specific database is in GB. You can not set both dataset_size_in_gb and memory_limit_in_gb.
* `modules` - (Optional) a list of modules that will be used by the databases in this subscription. Not currently compatible with ‘ram-and-flash’ memory storage.
Example: `modules = ["RedisJSON", "RediSearch", "RedisTimeSeries", "RedisBloom"]`
* `support_oss_cluster_api` - (Optional) Support Redis open-source (OSS) Cluster API. Default: ‘false’
Expand Down
8 changes: 5 additions & 3 deletions docs/resources/rediscloud_subscription_database.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ resource "rediscloud_subscription" "subscription-resource" {
// This block needs to be defined for provisioning a new subscription.
// This allows creation of a well-optimized hardware specification for databases in the cluster
creation_plan {
memory_limit_in_gb = 15
dataset_size_in_gb = 15
quantity = 1
replication=true
throughput_measurement_by = "operations-per-second"
Expand All @@ -51,7 +51,7 @@ resource "rediscloud_subscription" "subscription-resource" {
resource "rediscloud_subscription_database" "database-resource" {
subscription_id = rediscloud_subscription.subscription-resource.id
name = "database-name"
memory_limit_in_gb = 15
dataset_size_in_gb = 15
data_persistence = "aof-every-write"
throughput_measurement_by = "operations-per-second"
throughput_measurement_value = 20000
Expand Down Expand Up @@ -82,7 +82,8 @@ The following arguments are supported:
* `name` - (Required) A meaningful name to identify the database
* `throughput_measurement_by` - (Required) Throughput measurement method that will be used by your databases. Either `number-of-shards` or `operations-per-second`. **`number-of-shards` is deprecated and only supported for legacy deployments.**
* `throughput_measurement_value` - (Required) Throughput value (as applies to selected measurement method)
* `memory_limit_in_gb` - (Required) Maximum memory usage for this specific database
* `memory_limit_in_gb` - (Optional - **Required if `dataset_size_in_gb` is unset**) Maximum memory usage for this specific database, including replication and other overhead **Deprecated in favor of `dataset_size_in_gb` - not possible to import databases with this attribute set**
* `dataset_size_in_gb` - (Optional - **Required if `memory_limit_in_gb` is unset**) The maximum amount of data in the dataset for this specific database is in GB
* `protocol` - (Optional) The protocol that will be used to access the database, (either ‘redis’ or ‘memcached’) Default: ‘redis’. **Modifying this attribute will force creation of a new resource.**
* `support_oss_cluster_api` - (Optional) Support Redis open-source (OSS) Cluster API. Default: ‘false’
* `resp_version` - (Optional) Either `resp2` or `resp3`. Database's RESP version. Must be compatible with the Redis version.
Expand Down Expand Up @@ -188,3 +189,4 @@ The `response` block `latest_import_status` contains:
$ terraform import rediscloud_subscription_database.database-resource 123456/12345678
```

Note: Due to constraints in the Redis Cloud API, the `memory_limit_in_gb` cannot be set during imports as it is deprecated. If you need to set the `memory_limit_in_gb` attribute, you will need to create a new database resource. It is recommended to use the `dataset_size_in_gb` attribute instead.
11 changes: 10 additions & 1 deletion provider/datasource_rediscloud_active_active_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"fmt"

"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 @@ -33,7 +34,12 @@ func dataSourceRedisCloudActiveActiveDatabase() *schema.Resource {
Optional: true,
},
"memory_limit_in_gb": {
Description: "Maximum memory usage for this specific database",
Description: "(Deprecated) Maximum memory usage for this specific database",
Type: schema.TypeFloat,
Computed: true,
},
"dataset_size_in_gb": {
Description: "Maximum amount of data in the dataset for this specific database in GB",
Type: schema.TypeFloat,
Computed: true,
},
Expand Down Expand Up @@ -284,6 +290,9 @@ func dataSourceRedisCloudActiveActiveDatabaseRead(ctx context.Context, d *schema
if err := d.Set("memory_limit_in_gb", redis.Float64(*db.CrdbDatabases[0].MemoryLimitInGB)); 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)
}
if err := d.Set("support_oss_cluster_api", redis.BoolValue(db.SupportOSSClusterAPI)); err != nil {
return diag.FromErr(err)
}
Expand Down
13 changes: 11 additions & 2 deletions provider/datasource_rediscloud_pro_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package provider
import (
"context"
"fmt"
"regexp"
"strconv"

"github.com/RedisLabs/rediscloud-go-api/redis"
"github.com/RedisLabs/rediscloud-go-api/service/databases"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"regexp"
"strconv"
)

func dataSourceRedisCloudProDatabase() *schema.Resource {
Expand Down Expand Up @@ -53,6 +54,11 @@ func dataSourceRedisCloudProDatabase() *schema.Resource {
Type: schema.TypeFloat,
Computed: true,
},
"dataset_size_in_gb": {
Description: "Maximum amount of data in the dataset for this specific database in GB",
Type: schema.TypeFloat,
Computed: true,
},
"support_oss_cluster_api": {
Description: "Supports the Redis open-source (OSS) Cluster API",
Type: schema.TypeBool,
Expand Down Expand Up @@ -374,6 +380,9 @@ func dataSourceRedisCloudProDatabaseRead(ctx context.Context, d *schema.Resource
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
26 changes: 13 additions & 13 deletions provider/rediscloud_active_active_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestAccResourceRedisCloudActiveActiveDatabase_CRUDI(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
// Test resource
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "memory_limit_in_gb", "3"),
resource.TestCheckResourceAttr(resourceName, "dataset_size_in_gb", "3"),
resource.TestCheckResourceAttr(resourceName, "support_oss_cluster_api", "false"),
resource.TestCheckResourceAttr(resourceName, "global_data_persistence", "none"),
resource.TestCheckResourceAttr(resourceName, "external_endpoint_for_oss_cluster_api", "false"),
Expand Down Expand Up @@ -107,7 +107,7 @@ func TestAccResourceRedisCloudActiveActiveDatabase_CRUDI(t *testing.T) {
resource.TestCheckResourceAttrSet(datasourceName, "subscription_id"),
resource.TestCheckResourceAttrSet(datasourceName, "db_id"),
resource.TestCheckResourceAttr(datasourceName, "name", name),
resource.TestCheckResourceAttr(datasourceName, "memory_limit_in_gb", "3"),
resource.TestCheckResourceAttr(datasourceName, "dataset_size_in_gb", "3"),
resource.TestCheckResourceAttr(datasourceName, "support_oss_cluster_api", "false"),
resource.TestCheckResourceAttr(datasourceName, "external_endpoint_for_oss_cluster_api", "false"),
resource.TestCheckResourceAttr(datasourceName, "enable_tls", "false"),
Expand All @@ -124,7 +124,7 @@ func TestAccResourceRedisCloudActiveActiveDatabase_CRUDI(t *testing.T) {
Config: fmt.Sprintf(testAccResourceRedisCloudActiveActiveDatabaseUpdate, subscriptionName, name),
Check: resource.ComposeAggregateTestCheckFunc(
// Test resource
resource.TestCheckResourceAttr(resourceName, "memory_limit_in_gb", "1"),
resource.TestCheckResourceAttr(resourceName, "dataset_size_in_gb", "1"),
resource.TestCheckResourceAttr(resourceName, "support_oss_cluster_api", "true"),
resource.TestCheckResourceAttr(resourceName, "external_endpoint_for_oss_cluster_api", "true"),
resource.TestCheckResourceAttr(resourceName, "global_data_persistence", "aof-every-1-second"),
Expand All @@ -147,7 +147,7 @@ func TestAccResourceRedisCloudActiveActiveDatabase_CRUDI(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "override_region.0.override_global_source_ips.#", "0"),

// Test datasource
resource.TestCheckResourceAttr(datasourceName, "memory_limit_in_gb", "1"),
resource.TestCheckResourceAttr(datasourceName, "dataset_size_in_gb", "1"),
resource.TestCheckResourceAttr(datasourceName, "support_oss_cluster_api", "true"),
resource.TestCheckResourceAttr(datasourceName, "external_endpoint_for_oss_cluster_api", "true"),
),
Expand All @@ -156,7 +156,7 @@ func TestAccResourceRedisCloudActiveActiveDatabase_CRUDI(t *testing.T) {
{
Config: fmt.Sprintf(testAccResourceRedisCloudActiveActiveDatabaseUpdateNoAlerts, subscriptionName, name),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "memory_limit_in_gb", "1"),
resource.TestCheckResourceAttr(resourceName, "dataset_size_in_gb", "1"),
resource.TestCheckResourceAttr(resourceName, "support_oss_cluster_api", "true"),
resource.TestCheckResourceAttr(resourceName, "external_endpoint_for_oss_cluster_api", "true"),
resource.TestCheckResourceAttr(resourceName, "global_data_persistence", "aof-every-1-second"),
Expand Down Expand Up @@ -259,7 +259,7 @@ const activeActiveSubscriptionBoilerplate = `
cloud_provider = "AWS"
creation_plan {
memory_limit_in_gb = 1
dataset_size_in_gb = 1
quantity = 1
region {
region = "us-east-1"
Expand All @@ -283,7 +283,7 @@ const testAccResourceRedisCloudActiveActiveDatabase = activeActiveSubscriptionBo
resource "rediscloud_active_active_subscription_database" "example" {
subscription_id = rediscloud_active_active_subscription.example.id
name = "%s"
memory_limit_in_gb = 3
dataset_size_in_gb = 3
support_oss_cluster_api = false
external_endpoint_for_oss_cluster_api = false
enable_tls = false
Expand Down Expand Up @@ -328,7 +328,7 @@ const testAccResourceRedisCloudActiveActiveDatabaseUpdate = activeActiveSubscrip
resource "rediscloud_active_active_subscription_database" "example" {
subscription_id = rediscloud_active_active_subscription.example.id
name = "%s"
memory_limit_in_gb = 1
dataset_size_in_gb = 1
support_oss_cluster_api = true
external_endpoint_for_oss_cluster_api = true
Expand Down Expand Up @@ -362,7 +362,7 @@ const testAccResourceRedisCloudActiveActiveDatabaseUpdateNoAlerts = activeActive
resource "rediscloud_active_active_subscription_database" "example" {
subscription_id = rediscloud_active_active_subscription.example.id
name = "%s"
memory_limit_in_gb = 1
dataset_size_in_gb = 1
support_oss_cluster_api = true
external_endpoint_for_oss_cluster_api = true
Expand All @@ -385,7 +385,7 @@ const testAccResourceRedisCloudActiveActiveDatabaseImport = activeActiveSubscrip
resource "rediscloud_active_active_subscription_database" "example" {
subscription_id = rediscloud_active_active_subscription.example.id
name = "%s"
memory_limit_in_gb = 1
dataset_size_in_gb = 1
}
`

Expand All @@ -401,7 +401,7 @@ resource "rediscloud_active_active_subscription" "example" {
redis_version = "latest"
creation_plan {
memory_limit_in_gb = 1
dataset_size_in_gb = 1
quantity = 1
region {
region = "us-east-1"
Expand All @@ -421,7 +421,7 @@ resource "rediscloud_active_active_subscription" "example" {
resource "rediscloud_active_active_subscription_database" "example" {
subscription_id = rediscloud_active_active_subscription.example.id
name = "%s"
memory_limit_in_gb = 3
dataset_size_in_gb = 3
support_oss_cluster_api = false
external_endpoint_for_oss_cluster_api = false
enable_tls = false
Expand Down Expand Up @@ -455,7 +455,7 @@ const testAccResourceRedisCloudActiveActiveDatabaseInvalidTimeUtc = activeActive
resource "rediscloud_active_active_subscription_database" "example" {
subscription_id = rediscloud_active_active_subscription.example.id
name = "%s"
memory_limit_in_gb = 3
dataset_size_in_gb = 3
support_oss_cluster_api = false
external_endpoint_for_oss_cluster_api = false
enable_tls = false
Expand Down
Loading

0 comments on commit 2cd463c

Please sign in to comment.