@@ -3,6 +3,7 @@ package provider
33import (
44 "context"
55 "fmt"
6+ "github.com/RedisLabs/terraform-provider-rediscloud/provider/utils"
67 "regexp"
78 "strconv"
89 "strings"
@@ -235,6 +236,11 @@ func resourceRedisCloudProDatabase() *schema.Resource {
235236 return
236237 },
237238 },
239+ "redis_version" : {
240+ Description : "Defines the Redis database version. If omitted, the Redis version will be set to the default version" ,
241+ Type : schema .TypeString ,
242+ Optional : true ,
243+ },
238244 "modules" : {
239245 Description : "Modules to be provisioned in the database" ,
240246 Type : schema .TypeSet ,
@@ -346,23 +352,9 @@ func resourceRedisCloudProDatabase() *schema.Resource {
346352func resourceRedisCloudProDatabaseCreate (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
347353 api := meta .(* apiClient )
348354
349- subId := d .Get ("subscription_id" ).(int )
350-
355+ subId := * utils .GetInt (d , "subscription_id" )
351356 subscriptionMutex .Lock (subId )
352357
353- name := d .Get ("name" ).(string )
354- protocol := d .Get ("protocol" ).(string )
355- supportOSSClusterAPI := d .Get ("support_oss_cluster_api" ).(bool )
356- respVersion := d .Get ("resp_version" ).(string )
357- dataPersistence := d .Get ("data_persistence" ).(string )
358- dataEviction := d .Get ("data_eviction" ).(string )
359- password := d .Get ("password" ).(string )
360- replication := d .Get ("replication" ).(bool )
361- throughputMeasurementBy := d .Get ("throughput_measurement_by" ).(string )
362- throughputMeasurementValue := d .Get ("throughput_measurement_value" ).(int )
363- averageItemSizeInBytes := d .Get ("average_item_size_in_bytes" ).(int )
364- queryPerformanceFactor := d .Get ("query_performance_factor" ).(string )
365-
366358 createModules := make ([]* databases.Module , 0 )
367359 modules := d .Get ("modules" ).(* schema.Set )
368360 for _ , module := range modules .List () {
@@ -394,48 +386,52 @@ func resourceRedisCloudProDatabaseCreate(ctx context.Context, d *schema.Resource
394386 }
395387
396388 createDatabase := databases.CreateDatabase {
397- Name : redis . String ( name ),
398- Protocol : redis . String ( protocol ),
399- SupportOSSClusterAPI : redis . Bool ( supportOSSClusterAPI ),
400- DataPersistence : redis . String ( dataPersistence ),
401- DataEvictionPolicy : redis . String ( dataEviction ),
402- Replication : redis . Bool ( replication ),
389+ Name : utils . GetString ( d , " name" ),
390+ Protocol : utils . GetString ( d , " protocol" ),
391+ SupportOSSClusterAPI : utils . GetBool ( d , "support_oss_cluster_api" ),
392+ DataPersistence : utils . GetString ( d , "data_persistence" ),
393+ DataEvictionPolicy : utils . GetString ( d , "data_eviction" ),
394+ Replication : utils . GetBool ( d , " replication" ),
403395 ThroughputMeasurement : & databases.CreateThroughputMeasurement {
404- By : redis . String ( throughputMeasurementBy ),
405- Value : redis . Int ( throughputMeasurementValue ),
396+ By : utils . GetString ( d , "throughput_measurement_by" ),
397+ Value : utils . GetInt ( d , "throughput_measurement_value" ),
406398 },
407399 Modules : createModules ,
408400 Alerts : createAlerts ,
409401 RemoteBackup : buildBackupPlan (d .Get ("remote_backup" ).([]interface {}), d .Get ("periodic_backup_path" )),
410402 }
411403
412- if queryPerformanceFactor != "" {
413- createDatabase .QueryPerformanceFactor = redis . String ( queryPerformanceFactor )
414- }
404+ utils . SetStringIfNotEmpty ( d , "query_performance_factor" , func ( s * string ) {
405+ createDatabase .QueryPerformanceFactor = s
406+ })
415407
416- if password != "" {
417- createDatabase .Password = redis . String ( password )
418- }
408+ utils . SetStringIfNotEmpty ( d , "redis_version" , func ( s * string ) {
409+ createDatabase .RedisVersion = s
410+ })
419411
420- if averageItemSizeInBytes > 0 {
421- createDatabase .AverageItemSizeInBytes = & averageItemSizeInBytes
422- }
412+ utils . SetStringIfNotEmpty ( d , "password" , func ( s * string ) {
413+ createDatabase .Password = s
414+ })
423415
424- if v , ok := d . GetOk ( "dataset_size_in_gb" ); ok {
425- createDatabase .DatasetSizeInGB = redis . Float64 ( v .( float64 ))
426- }
416+ utils . SetIntIfPositive ( d , "average_item_size_in_bytes" , func ( i * int ) {
417+ createDatabase .AverageItemSizeInBytes = i
418+ })
427419
428- if v , ok := d . GetOk ( "memory_limit_in_gb" ); ok {
429- createDatabase .MemoryLimitInGB = redis . Float64 ( v .( float64 ))
430- }
420+ utils . SetFloat64 ( d , "dataset_size_in_gb" , func ( f * float64 ) {
421+ createDatabase .DatasetSizeInGB = f
422+ })
431423
432- if v , ok := d . GetOk ( "port" ); ok {
433- createDatabase .PortNumber = redis . Int ( v .( int ))
434- }
424+ utils . SetFloat64 ( d , "memory_limit_in_gb" , func ( f * float64 ) {
425+ createDatabase .MemoryLimitInGB = f
426+ })
435427
436- if respVersion != "" {
437- createDatabase .RespVersion = redis .String (respVersion )
438- }
428+ utils .SetInt (d , "port" , func (i * int ) {
429+ createDatabase .PortNumber = i
430+ })
431+
432+ utils .SetStringIfNotEmpty (d , "resp_version" , func (s * string ) {
433+ createDatabase .RespVersion = s
434+ })
439435
440436 // Confirm sub is ready to accept a db request
441437 if err := waitForSubscriptionToBeActive (ctx , subId , api ); err != nil {
0 commit comments