Skip to content

Commit 87011a7

Browse files
authored
Add support_oss_cluster_api and others optional (#369)
This adds the `support_oss_cluster_api` attribute to the `rediscloud_active_active_subscription` resource, as well as making a number of other attributes optional: * `rediscloud_subscription.preferred_availability_zones` * `rediscloud_subscription.modules` * `rediscloud_subscription_database.protocol` * Remove `support_oss_cluster_api` from `rediscloud_subscription` example as it is optional.
1 parent 7207724 commit 87011a7

9 files changed

+146
-48
lines changed

.github/workflows/terraform_provider.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ jobs:
150150
code-changes:
151151
- 'go.mod'
152152
- 'go.sum'
153-
- 'internal/**'
153+
- 'provider/**'
154154
- '*.go'
155155
- '.github/workflows/**'
156156
- run: make testacc

docs/resources/rediscloud_active_active_subscription.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ The `creation_plan` block supports:
6262

6363
* `memory_limit_in_gb` - (Required) Maximum memory usage that will be used for your largest planned database, including replication and other overhead
6464
* `quantity` - (Required) The planned number of databases in the subscription.
65+
* `support_oss_cluster_api` - (Optional) Support Redis open-source (OSS) Cluster API. Default: ‘false’
6566

6667
The creation_plan `region` block supports:
6768

docs/resources/rediscloud_subscription.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ resource "rediscloud_subscription" "subscription-resource" {
4747
memory_limit_in_gb = 2
4848
quantity = 1
4949
replication= false
50-
support_oss_cluster_api= false
5150
throughput_measurement_by = "operations-per-second"
5251
throughput_measurement_value = 10000
5352
modules = ["RediSearch", "RedisBloom"]
@@ -85,7 +84,7 @@ only with Redis Labs internal cloud account
8584
The `creation_plan` block supports:
8685

8786
* `memory_limit_in_gb` - (Required) Maximum memory usage that will be used for your largest planned database.
88-
* `modules` - (Required) a list of modules that will be used by the databases in this subscription. Not currently compatible with ‘ram-and-flash’ memory storage.
87+
* `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.
8988
Example: `modules = ["RedisJSON", RedisBloom"]`
9089
* `support_oss_cluster_api` - (Optional) Support Redis open-source (OSS) Cluster API. Default: ‘false’
9190
* `replication` - (Required) Databases replication. Set to `true` if any of your databases will use replication
@@ -108,7 +107,7 @@ The cloud_provider `region` block supports:
108107
* `networking_vpc_id` - (Optional) Either an existing VPC Id (already exists in the specific region) or create a new VPC
109108
(if no VPC is specified). VPC Identifier must be in a valid format (for example: ‘vpc-0125be68a4986384ad’) and existing
110109
within the hosting account.
111-
* `preferred_availability_zones` - (Required) Availability zones deployment preferences (for the selected provider & region). If multiple_availability_zones is set to 'true', select three availability zones from the list. If you don't want to specify preferred avaialbility zones, set this attribute to an empty list ('[]').
110+
* `preferred_availability_zones` - (Optional) Availability zones deployment preferences (for the selected provider & region). If multiple_availability_zones is set to 'true', select three availability zones from the list. If you don't want to specify preferred availability zones, set this attribute to an empty list ('[]').
112111

113112
~> **Note:** The preferred_availability_zones parameter is required for Terraform, but is optional within the Redis Enterprise Cloud UI.
114113
This difference in behaviour is to guarantee that a plan after an apply does not generate differences. In AWS Redis internal cloud account, please set the zone IDs (for example: `["use-az2", "use-az3", "use-az5"]`).

provider/resource_rediscloud_active_active_subscription.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ func resourceRedisCloudActiveActiveSubscription() *schema.Resource {
104104
Required: true,
105105
ValidateFunc: validation.IntAtLeast(1),
106106
},
107+
"support_oss_cluster_api": {
108+
Description: "Support Redis open-source (OSS) Cluster API",
109+
Type: schema.TypeBool,
110+
Optional: true,
111+
Default: false,
112+
},
107113
"region": {
108114
Description: "Cloud networking details, per region (multiple regions for Active-Active cluster)",
109115
Type: schema.TypeSet,
@@ -410,6 +416,7 @@ func buildSubscriptionCreatePlanAADatabases(planMap map[string]interface{}) []*s
410416
numDatabases := planMap["quantity"].(int)
411417
memoryLimitInGB := planMap["memory_limit_in_gb"].(float64)
412418
regions := planMap["region"]
419+
supportOSSClusterAPI := planMap["support_oss_cluster_api"].(bool)
413420
var localThroughputs []*subscriptions.CreateLocalThroughput
414421
for _, v := range regions.(*schema.Set).List() {
415422
region := v.(map[string]interface{})
@@ -420,13 +427,13 @@ func buildSubscriptionCreatePlanAADatabases(planMap map[string]interface{}) []*s
420427
})
421428
}
422429
// create the remaining DBs with all other modules
423-
createDatabases = append(createDatabases, createAADatabase(dbName, &idx, localThroughputs, numDatabases, memoryLimitInGB)...)
430+
createDatabases = append(createDatabases, createAADatabase(dbName, &idx, localThroughputs, numDatabases, memoryLimitInGB, supportOSSClusterAPI)...)
424431

425432
return createDatabases
426433
}
427434

428435
// createDatabase returns a CreateDatabase struct with the given parameters
429-
func createAADatabase(dbName string, idx *int, localThroughputs []*subscriptions.CreateLocalThroughput, numDatabases int, memoryLimitInGB float64) []*subscriptions.CreateDatabase {
436+
func createAADatabase(dbName string, idx *int, localThroughputs []*subscriptions.CreateLocalThroughput, numDatabases int, memoryLimitInGB float64, supportOSSClusterAPI bool) []*subscriptions.CreateDatabase {
430437
var databases []*subscriptions.CreateDatabase
431438
for i := 0; i < numDatabases; i++ {
432439
createDatabase := subscriptions.CreateDatabase{
@@ -435,6 +442,7 @@ func createAADatabase(dbName string, idx *int, localThroughputs []*subscriptions
435442
MemoryLimitInGB: redis.Float64(memoryLimitInGB),
436443
LocalThroughputMeasurement: localThroughputs,
437444
Quantity: redis.Int(1),
445+
SupportOSSClusterAPI: redis.Bool(supportOSSClusterAPI),
438446
}
439447
*idx++
440448
databases = append(databases, &createDatabase)

provider/resource_rediscloud_active_active_subscription_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ func TestAccResourceRedisCloudActiveActiveSubscription_createUpdateMarketplacePa
165165
Check: resource.ComposeTestCheckFunc(
166166
resource.TestCheckResourceAttr(resourceName, "name", name),
167167
resource.TestCheckResourceAttr(resourceName, "cloud_provider.0.provider", "AWS"),
168+
resource.TestCheckResourceAttr(resourceName, "creation_plan.0.support_oss_cluster_api", "true"),
168169
resource.TestCheckResourceAttrSet(resourceName, "payment_method_id"),
169170
resource.TestCheckResourceAttr(resourceName, "creation_plan.0.region.#", "2"),
170171
resource.TestCheckResourceAttr(resourceName, "creation_plan.0.region.0.write_operations_per_second", "1000"),
@@ -225,6 +226,7 @@ resource "rediscloud_active_active_subscription" "example" {
225226
creation_plan {
226227
memory_limit_in_gb = 1
227228
quantity = 1
229+
support_oss_cluster_api = true
228230
region {
229231
region = "us-east-1"
230232
networking_deployment_cidr = "192.168.0.0/24"

provider/resource_rediscloud_subscription.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@ func resourceRedisCloudSubscription() *schema.Resource {
167167
"preferred_availability_zones": {
168168
Description: "List of availability zones used",
169169
Type: schema.TypeList,
170-
Required: true,
170+
Optional: true,
171171
ForceNew: true,
172+
Computed: true,
172173
Elem: &schema.Schema{
173174
Type: schema.TypeString,
174175
},
@@ -278,7 +279,8 @@ func resourceRedisCloudSubscription() *schema.Resource {
278279
"modules": {
279280
Description: "Modules that will be used by the databases in this subscription.",
280281
Type: schema.TypeList,
281-
Required: true,
282+
Optional: true,
283+
Computed: true,
282284
Elem: &schema.Schema{
283285
Type: schema.TypeString,
284286
},
@@ -932,19 +934,6 @@ func flattenRegexRules(rules []*databases.RegexRule) []string {
932934
return ret
933935
}
934936

935-
func getDatabaseNameIdMap(ctx context.Context, subId int, client *apiClient) (map[string]int, error) {
936-
ret := map[string]int{}
937-
list := client.client.Database.List(ctx, subId)
938-
for list.Next() {
939-
db := list.Value()
940-
ret[redis.StringValue(db.Name)] = redis.IntValue(db.ID)
941-
}
942-
if list.Err() != nil {
943-
return nil, list.Err()
944-
}
945-
return ret, nil
946-
}
947-
948937
func readPaymentMethodID(d *schema.ResourceData) (*int, error) {
949938
pmID := d.Get("payment_method_id").(string)
950939
if pmID != "" {

provider/resource_rediscloud_subscription_database.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ func resourceRedisCloudSubscriptionDatabase() *schema.Resource {
6767
"protocol": {
6868
Description: "The protocol that will be used to access the database, (either ‘redis’ or 'memcached’) ",
6969
Type: schema.TypeString,
70-
Required: true,
7170
ValidateDiagFunc: validateDiagFunc(validation.StringInSlice(databases.ProtocolValues(), false)),
71+
Optional: true,
7272
ForceNew: true,
73+
Computed: true,
7374
},
7475
"memory_limit_in_gb": {
7576
Description: "Maximum memory usage for this specific database",
@@ -241,7 +242,6 @@ func resourceRedisCloudSubscriptionDatabaseCreate(ctx context.Context, d *schema
241242
subscriptionMutex.Lock(subId)
242243

243244
name := d.Get("name").(string)
244-
protocol := d.Get("protocol").(string)
245245
memoryLimitInGB := d.Get("memory_limit_in_gb").(float64)
246246
supportOSSClusterAPI := d.Get("support_oss_cluster_api").(bool)
247247
dataPersistence := d.Get("data_persistence").(string)
@@ -284,7 +284,6 @@ func resourceRedisCloudSubscriptionDatabaseCreate(ctx context.Context, d *schema
284284

285285
createDatabase := databases.CreateDatabase{
286286
Name: redis.String(name),
287-
Protocol: redis.String(protocol),
288287
MemoryLimitInGB: redis.Float64(memoryLimitInGB),
289288
SupportOSSClusterAPI: redis.Bool(supportOSSClusterAPI),
290289
DataPersistence: redis.String(dataPersistence),
@@ -305,6 +304,10 @@ func resourceRedisCloudSubscriptionDatabaseCreate(ctx context.Context, d *schema
305304
createDatabase.AverageItemSizeInBytes = &averageItemSizeInBytes
306305
}
307306

307+
if v, ok := d.GetOk("protocol"); ok {
308+
createDatabase.Protocol = redis.String(v.(string))
309+
}
310+
308311
dbId, err := api.client.Database.Create(ctx, subId, createDatabase)
309312
if err != nil {
310313
return diag.FromErr(err)

provider/resource_rediscloud_subscription_database_test.go

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,27 @@ func TestAccResourceRedisCloudSubscriptionDatabase_CRUDI(t *testing.T) {
133133
})
134134
}
135135

136+
func TestAccResourceRedisCloudSubscriptionDatabase_optionalAttributes(t *testing.T) {
137+
// Test that attributes can be optional, either by setting them or not having them set when compared to CRUDI test
138+
name := acctest.RandomWithPrefix(testResourcePrefix)
139+
resourceName := "rediscloud_subscription_database.example"
140+
testCloudAccountName := os.Getenv("AWS_TEST_CLOUD_ACCOUNT_NAME")
141+
142+
resource.Test(t, resource.TestCase{
143+
PreCheck: func() { testAccPreCheck(t); testAccAwsPreExistingCloudAccountPreCheck(t) },
144+
ProviderFactories: providerFactories,
145+
CheckDestroy: testAccCheckSubscriptionDestroy,
146+
Steps: []resource.TestStep{
147+
{
148+
Config: fmt.Sprintf(testAccResourceRedisCloudSubscriptionDatabaseOptionalAttributes, testCloudAccountName, name),
149+
Check: resource.ComposeTestCheckFunc(
150+
resource.TestCheckResourceAttr(resourceName, "protocol", "redis"),
151+
),
152+
},
153+
},
154+
})
155+
}
156+
136157
// Tests the multi-modules feature in a database resource.
137158
func TestAccResourceRedisCloudSubscriptionDatabase_MultiModules(t *testing.T) {
138159
name := acctest.RandomWithPrefix(testResourcePrefix)
@@ -182,7 +203,7 @@ resource "rediscloud_subscription" "example" {
182203
183204
allowlist {
184205
cidrs = ["192.168.0.0/16"]
185-
security_group_ids = []
206+
security_group_ids = []
186207
}
187208
188209
cloud_provider {
@@ -203,7 +224,7 @@ resource "rediscloud_subscription" "example" {
203224
quantity = 1
204225
replication=false
205226
support_oss_cluster_api=false
206-
modules = []
227+
modules = []
207228
}
208229
}
209230
`
@@ -217,30 +238,41 @@ resource "rediscloud_subscription_database" "example" {
217238
protocol = "redis"
218239
memory_limit_in_gb = 3
219240
data_persistence = "none"
220-
data_eviction = "allkeys-random"
241+
data_eviction = "allkeys-random"
221242
throughput_measurement_by = "operations-per-second"
222243
throughput_measurement_value = 1000
223-
password = "%s"
224-
support_oss_cluster_api = false
225-
external_endpoint_for_oss_cluster_api = false
226-
replication = false
227-
average_item_size_in_bytes = 0
228-
client_ssl_certificate = ""
229-
periodic_backup_path = ""
244+
password = "%s"
245+
support_oss_cluster_api = false
246+
external_endpoint_for_oss_cluster_api = false
247+
replication = false
248+
average_item_size_in_bytes = 0
249+
client_ssl_certificate = ""
250+
periodic_backup_path = ""
230251
231-
alert {
232-
name = "dataset-size"
233-
value = 40
234-
}
235-
236-
modules = [
252+
alert {
253+
name = "dataset-size"
254+
value = 40
255+
}
256+
257+
modules = [
237258
{
238259
name = "RedisBloom"
239260
}
240261
]
241262
}
242263
`
243264

265+
const testAccResourceRedisCloudSubscriptionDatabaseOptionalAttributes = subscriptionBoilerplate + `
266+
resource "rediscloud_subscription_database" "example" {
267+
subscription_id = rediscloud_subscription.example.id
268+
name = "example-no-protocol"
269+
memory_limit_in_gb = 1
270+
data_persistence = "none"
271+
throughput_measurement_by = "operations-per-second"
272+
throughput_measurement_value = 1000
273+
}
274+
`
275+
244276
// TF config for provisioning a database where the password is not specified
245277
const testAccResourceRedisCloudSubscriptionDatabaseNoPassword = subscriptionBoilerplate + `
246278
resource "rediscloud_subscription_database" "no_password_database" {
@@ -338,7 +370,7 @@ resource "rediscloud_subscription" "example" {
338370
const testAccResourceRedisCloudSubscriptionDatabaseMultiModules = multiModulesSubscriptionBoilerplate + `
339371
resource "rediscloud_subscription_database" "example" {
340372
subscription_id = rediscloud_subscription.example.id
341-
name = "%s"
373+
name = "%s"
342374
protocol = "redis"
343375
memory_limit_in_gb = 1
344376
data_persistence = "none"

0 commit comments

Comments
 (0)