Skip to content

Commit a597d14

Browse files
committed
feat: adding redis_version support to the pro database datasource
1 parent c32e56f commit a597d14

File tree

3 files changed

+92
-66
lines changed

3 files changed

+92
-66
lines changed

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-
`
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
locals {
2+
rediscloud_cloud_account = "%s"
3+
rediscloud_subscription_name = "%s"
4+
rediscloud_password = "%s"
5+
}
6+
7+
data "rediscloud_payment_method" "card" {
8+
card_type = "Visa"
9+
last_four_numbers = "5556"
10+
}
11+
12+
data "rediscloud_cloud_account" "account" {
13+
exclude_internal_account = true
14+
provider_type = "AWS"
15+
name = local.rediscloud_cloud_account
16+
}
17+
resource "rediscloud_subscription" "example" {
18+
name = local.rediscloud_subscription_name
19+
payment_method_id = data.rediscloud_payment_method.card.id
20+
memory_storage = "ram"
21+
cloud_provider {
22+
provider = data.rediscloud_cloud_account.account.provider_type
23+
cloud_account_id = data.rediscloud_cloud_account.account.id
24+
region {
25+
region = "eu-west-1"
26+
networking_deployment_cidr = "10.0.0.0/24"
27+
preferred_availability_zones = ["eu-west-1a"]
28+
}
29+
}
30+
creation_plan {
31+
memory_limit_in_gb = 1
32+
quantity = 1
33+
replication=false
34+
support_oss_cluster_api=true
35+
throughput_measurement_by = "operations-per-second"
36+
throughput_measurement_value = 1000
37+
query_performance_factor = "2x"
38+
modules = ["RediSearch"]
39+
}
40+
}
41+
resource "rediscloud_subscription_database" "example" {
42+
subscription_id = rediscloud_subscription.example.id
43+
name = "tf-database"
44+
protocol = "redis"
45+
memory_limit_in_gb = 1
46+
data_persistence = "none"
47+
throughput_measurement_by = "operations-per-second"
48+
throughput_measurement_value = 1000
49+
password = local.rediscloud_password
50+
support_oss_cluster_api = true
51+
replication = false
52+
enable_default_user = true
53+
query_performance_factor = "2x"
54+
redis_version = "7.2"
55+
modules = [
56+
{
57+
name: "RediSearch"
58+
}
59+
]
60+
}
61+
62+
data "rediscloud_database" "example-by-id" {
63+
subscription_id = rediscloud_subscription.example.id
64+
db_id = rediscloud_subscription_database.example.db_id
65+
}
66+
67+
data "rediscloud_database" "example-by-name" {
68+
subscription_id = rediscloud_subscription.example.id
69+
name = rediscloud_subscription_database.example.name
70+
}

0 commit comments

Comments
 (0)