Skip to content

Commit 263cdc4

Browse files
Merge pull request #653 from RedisLabs/feat/OPCR-34-datasource-redis-db-versions
OPCR-34: Adding redis_version support to the pro and AA database data sources
2 parents c32e56f + 8dfd047 commit 263cdc4

11 files changed

+116
-74
lines changed

docs/data-sources/rediscloud_active_active_subscription.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: |-
55
Active Active Subscription data source in the Redis Cloud Terraform provider.
66
---
77

8-
# Resource: rediscloud_active_active_subscription
8+
# Data Source: rediscloud_active_active_subscription
99

1010
This data source allows access to the details of an existing subscription within your Redis Enterprise Cloud account.
1111

docs/data-sources/rediscloud_active_active_subscription_database.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: |-
55
Database data source for Active-Active Subscriptions in the Redis Cloud Terraform provider.
66
---
77

8-
# Resource: rediscloud_active_active_subscription_database
8+
# Data Source: rediscloud_active_active_subscription_database
99

1010
This data source allows access to the details of an existing database within your Redis Enterprise Cloud account.
1111

@@ -45,6 +45,7 @@ data "rediscloud_active_active_subscription_database" "example" {
4545
* `memory_limit_in_gb` - The maximum memory usage for the database.
4646
* `dataset_size_in_gb` - Maximum amount of data in the dataset for this specific database in GB.
4747
* `support_oss_cluster_api` - Supports the Redis open-source (OSS) Cluster API.
48+
* `redis_version` - The Redis version of the database.
4849
* `external_endpoint_for_oss_cluster_api` - Use the external endpoint for open-source (OSS) Cluster API.
4950
* `enable_tls` - Enable TLS for database.
5051
* `tls_certificate` - TLS certificate used for authentication.

docs/data-sources/rediscloud_database.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ data "rediscloud_database" "example" {
4545
* `memory_limit_in_gb` - The maximum memory usage for the database.
4646
* `dataset_size_in_gb` - Maximum amount of data in the dataset for this specific database in GB.
4747
* `support_oss_cluster_api` - Supports the Redis open-source (OSS) Cluster API.
48+
* `redis_version` - The Redis version of the database.
4849
* `resp_version` - Either `resp2` or `resp3`. Database's RESP version.
4950
* `replica_of` - The set of Redis database URIs, in the format `redis://user:password@host:port`, that this
5051
database will be a replica of.

docs/data-sources/rediscloud_essentials_database.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: |-
55
Database data source for Essentials Subscriptions in the Redis Cloud Terraform provider.
66
---
77

8-
# Resource: rediscloud_essentials_database
8+
# Data Source: rediscloud_essentials_database
99

1010
This data source allows access to the details of an existing database within your Redis Enterprise Cloud account.
1111

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.23.0
55
toolchain go1.24.1
66

77
require (
8-
github.com/RedisLabs/rediscloud-go-api v0.33.1
8+
github.com/RedisLabs/rediscloud-go-api v0.34.0
99
github.com/bflad/tfproviderlint v0.31.0
1010
github.com/hashicorp/go-cty v1.5.0
1111
github.com/hashicorp/terraform-plugin-sdk/v2 v2.37.0
@@ -68,3 +68,6 @@ require (
6868
google.golang.org/protobuf v1.36.6 // indirect
6969
gopkg.in/yaml.v3 v3.0.1 // indirect
7070
)
71+
72+
// for local development, uncomment this
73+
//replace github.com/RedisLabs/rediscloud-go-api => ../rediscloud-go-api

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERo
44
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
55
github.com/ProtonMail/go-crypto v1.1.6 h1:ZcV+Ropw6Qn0AX9brlQLAUXfqLBc7Bl+f/DmNxpLfdw=
66
github.com/ProtonMail/go-crypto v1.1.6/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE=
7-
github.com/RedisLabs/rediscloud-go-api v0.33.1 h1:sOCGvkvgY4jnH/mMQcA6XO8p1YQ2HfFvtbiblkA1Z/c=
8-
github.com/RedisLabs/rediscloud-go-api v0.33.1/go.mod h1:3/oVb71rv2OstFRYEc65QCIbfwnJTgZeQhtPCcdHook=
7+
github.com/RedisLabs/rediscloud-go-api v0.34.0 h1:TjiABMGCa7SXfwdlqAEj53GX0ipC/b6MOagQc7wIo7g=
8+
github.com/RedisLabs/rediscloud-go-api v0.34.0/go.mod h1:3/oVb71rv2OstFRYEc65QCIbfwnJTgZeQhtPCcdHook=
99
github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE=
1010
github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
1111
github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec=

provider/datasource_rediscloud_active_active_database.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ func dataSourceRedisCloudActiveActiveDatabase() *schema.Resource {
4343
Type: schema.TypeFloat,
4444
Computed: true,
4545
},
46+
"redis_version": {
47+
Description: "The redis version of the database",
48+
Type: schema.TypeString,
49+
Computed: true,
50+
},
4651
"support_oss_cluster_api": {
4752
Description: "Support Redis open-source (OSS) Cluster API",
4853
Type: schema.TypeBool,
@@ -298,6 +303,11 @@ func dataSourceRedisCloudActiveActiveDatabaseRead(ctx context.Context, d *schema
298303
if err := d.Set("dataset_size_in_gb", redis.Float64(*db.CrdbDatabases[0].DatasetSizeInGB)); err != nil {
299304
return diag.FromErr(err)
300305
}
306+
307+
if err := d.Set("redis_version", redis.String(*db.RedisVersion)); err != nil {
308+
return diag.FromErr(err)
309+
}
310+
301311
if err := d.Set("support_oss_cluster_api", redis.BoolValue(db.SupportOSSClusterAPI)); err != nil {
302312
return diag.FromErr(err)
303313
}

provider/datasource_rediscloud_pro_database.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ func dataSourceRedisCloudProDatabase() *schema.Resource {
5959
Type: schema.TypeFloat,
6060
Computed: true,
6161
},
62+
"redis_version": {
63+
Description: "The redis version of the database",
64+
Type: schema.TypeString,
65+
Computed: true,
66+
},
6267
"query_performance_factor": {
6368
Description: "Query performance factor for this specific database",
6469
Type: schema.TypeString,
@@ -485,6 +490,10 @@ func dataSourceRedisCloudProDatabaseRead(ctx context.Context, d *schema.Resource
485490
return diag.FromErr(err)
486491
}
487492

493+
if err := d.Set("redis_version", redis.String(*db.RedisVersion)); err != nil {
494+
return diag.FromErr(err)
495+
}
496+
488497
return diags
489498
}
490499

provider/datasource_rediscloud_pro_database_test.go

Lines changed: 13 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,19 @@ func TestAccDataSourceRedisCloudProDatabase_basic(t *testing.T) {
1313

1414
testAccRequiresEnvVar(t, "EXECUTE_TESTS")
1515

16-
name := acctest.RandomWithPrefix(testResourcePrefix)
17-
password := acctest.RandString(20)
18-
testCloudAccountName := os.Getenv("AWS_TEST_CLOUD_ACCOUNT_NAME")
19-
2016
const dataSourceById = "data.rediscloud_database.example-by-id"
2117
const dataSourceByName = "data.rediscloud_database.example-by-name"
18+
password := acctest.RandString(20)
19+
20+
config := getRedisProDbDatasourceConfig(t, password)
2221

2322
resource.ParallelTest(t, resource.TestCase{
2423
PreCheck: func() { testAccPreCheck(t); testAccAwsPreExistingCloudAccountPreCheck(t) },
2524
ProviderFactories: providerFactories,
2625
CheckDestroy: testAccCheckProSubscriptionDestroy,
2726
Steps: []resource.TestStep{
2827
{
29-
Config: fmt.Sprintf(testAccDatasourceRedisCloudProDatabase, testCloudAccountName, name, password),
28+
Config: config,
3029
Check: resource.ComposeAggregateTestCheckFunc(
3130
resource.TestCheckResourceAttr(dataSourceById, "name", "tf-database"),
3231
resource.TestCheckResourceAttr(dataSourceById, "protocol", "redis"),
@@ -61,74 +60,22 @@ func TestAccDataSourceRedisCloudProDatabase_basic(t *testing.T) {
6160
resource.TestCheckResourceAttrSet(dataSourceByName, "private_endpoint"),
6261
resource.TestCheckResourceAttr(dataSourceByName, "enable_default_user", "true"),
6362
resource.TestCheckResourceAttr(dataSourceByName, "query_performance_factor", "2x"),
63+
resource.TestCheckResourceAttr(dataSourceByName, "redis_version", "7.2"),
6464
),
6565
},
6666
},
6767
})
68-
}
6968

70-
const testAccDatasourceRedisCloudProDatabase = `
71-
data "rediscloud_payment_method" "card" {
72-
card_type = "Visa"
73-
last_four_numbers = "5556"
7469
}
7570

76-
data "rediscloud_cloud_account" "account" {
77-
exclude_internal_account = true
78-
provider_type = "AWS"
79-
name = "%s"
80-
}
81-
resource "rediscloud_subscription" "example" {
82-
name = "%s"
83-
payment_method_id = data.rediscloud_payment_method.card.id
84-
memory_storage = "ram"
85-
cloud_provider {
86-
provider = data.rediscloud_cloud_account.account.provider_type
87-
cloud_account_id = data.rediscloud_cloud_account.account.id
88-
region {
89-
region = "eu-west-1"
90-
networking_deployment_cidr = "10.0.0.0/24"
91-
preferred_availability_zones = ["eu-west-1a"]
92-
}
93-
}
94-
creation_plan {
95-
memory_limit_in_gb = 1
96-
quantity = 1
97-
replication=false
98-
support_oss_cluster_api=true
99-
throughput_measurement_by = "operations-per-second"
100-
throughput_measurement_value = 1000
101-
query_performance_factor = "2x"
102-
modules = ["RediSearch"]
103-
}
104-
}
105-
resource "rediscloud_subscription_database" "example" {
106-
subscription_id = rediscloud_subscription.example.id
107-
name = "tf-database"
108-
protocol = "redis"
109-
memory_limit_in_gb = 1
110-
data_persistence = "none"
111-
throughput_measurement_by = "operations-per-second"
112-
throughput_measurement_value = 1000
113-
password = "%s"
114-
support_oss_cluster_api = true
115-
replication = false
116-
enable_default_user = true
117-
query_performance_factor = "2x"
118-
modules = [
119-
{
120-
name: "RediSearch"
121-
}
122-
]
123-
}
71+
func getRedisProDbDatasourceConfig(t *testing.T, password string) string {
72+
testCloudAccountName := os.Getenv("AWS_TEST_CLOUD_ACCOUNT_NAME")
73+
subscriptionName := acctest.RandomWithPrefix(testResourcePrefix)
12474

125-
data "rediscloud_database" "example-by-id" {
126-
subscription_id = rediscloud_subscription.example.id
127-
db_id = rediscloud_subscription_database.example.db_id
128-
}
75+
content, err := os.ReadFile("./testdata/testAccDatasourceRedisCloudProDatabase.tf")
76+
if err != nil {
77+
t.Fatalf("failed to read file: %v", err)
78+
}
12979

130-
data "rediscloud_database" "example-by-name" {
131-
subscription_id = rediscloud_subscription.example.id
132-
name = rediscloud_subscription_database.example.name
80+
return fmt.Sprintf(string(content), testCloudAccountName, subscriptionName, password)
13381
}
134-
`

provider/rediscloud_active_active_database_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ func TestAccResourceRedisCloudActiveActiveDatabase_CRUDI(t *testing.T) {
161161
// Test datasource
162162
resource.TestCheckResourceAttr(datasourceName, "dataset_size_in_gb", "1"),
163163
resource.TestCheckResourceAttr(datasourceName, "support_oss_cluster_api", "true"),
164+
resource.TestCheckResourceAttr(datasourceName, "redis_version", "7.4"),
164165
resource.TestCheckResourceAttr(datasourceName, "external_endpoint_for_oss_cluster_api", "true"),
165166
),
166167
},
@@ -327,8 +328,8 @@ resource "rediscloud_active_active_subscription_database" "example" {
327328
"priority" = "code-2"
328329
}
329330
330-
}
331-
//
331+
}
332+
332333
data "rediscloud_active_active_subscription_database" "example" {
333334
subscription_id = rediscloud_active_active_subscription.example.id
334335
name = rediscloud_active_active_subscription_database.example.name

0 commit comments

Comments
 (0)