@@ -2,6 +2,7 @@ package provider
22
33import (
44 "context"
5+ "github.com/RedisLabs/terraform-provider-rediscloud/provider/utils"
56 "log"
67 "regexp"
78 "strings"
@@ -97,6 +98,13 @@ func resourceRedisCloudActiveActiveDatabase() *schema.Resource {
9798 Computed : true ,
9899 ExactlyOneOf : []string {"memory_limit_in_gb" , "dataset_size_in_gb" },
99100 },
101+ "redis_version" : {
102+ Description : "Defines the Redis database version. If omitted, the Redis version will be set to the default version" ,
103+ Type : schema .TypeString ,
104+ Optional : true ,
105+ Computed : true ,
106+ ForceNew : true ,
107+ },
100108 "support_oss_cluster_api" : {
101109 Description : "Support Redis open-source (OSS) Cluster API" ,
102110 Type : schema .TypeBool ,
@@ -339,11 +347,7 @@ func resourceRedisCloudActiveActiveDatabaseCreate(ctx context.Context, d *schema
339347 name := d .Get ("name" ).(string )
340348 supportOSSClusterAPI := d .Get ("support_oss_cluster_api" ).(bool )
341349 useExternalEndpointForOSSClusterAPI := d .Get ("external_endpoint_for_oss_cluster_api" ).(bool )
342- dataEviction := d .Get ("data_eviction" ).(string )
343- globalDataPersistence := d .Get ("global_data_persistence" ).(string )
344- globalPassword := d .Get ("global_password" ).(string )
345350 globalSourceIp := setToStringSlice (d .Get ("global_source_ips" ).(* schema.Set ))
346- respVersion := d .Get ("global_resp_version" ).(string )
347351
348352 createAlerts := make ([]* databases.Alert , 0 )
349353 alerts := d .Get ("global_alert" ).(* schema.Set )
@@ -399,33 +403,37 @@ func resourceRedisCloudActiveActiveDatabaseCreate(ctx context.Context, d *schema
399403 LocalThroughputMeasurement : localThroughputs ,
400404 }
401405
402- if dataEviction != "" {
403- createDatabase .DataEvictionPolicy = redis . String ( dataEviction )
404- }
406+ utils . SetStringIfNotEmpty ( d , "data_eviction" , func ( s * string ) {
407+ createDatabase .DataEvictionPolicy = s
408+ })
405409
406- if globalDataPersistence != "" {
407- createDatabase .GlobalDataPersistence = redis . String ( globalDataPersistence )
408- }
410+ utils . SetStringIfNotEmpty ( d , "global_data_persistence" , func ( s * string ) {
411+ createDatabase .GlobalDataPersistence = s
412+ })
409413
410- if globalPassword != "" {
411- createDatabase .GlobalPassword = redis . String ( globalPassword )
412- }
414+ utils . SetStringIfNotEmpty ( d , "global_password" , func ( s * string ) {
415+ createDatabase .GlobalPassword = s
416+ })
413417
414- if v , ok := d . GetOk ( "dataset_size_in_gb" ); ok {
415- createDatabase .DatasetSizeInGB = redis . Float64 ( v .( float64 ))
416- }
418+ utils . SetFloat64 ( d , "dataset_size_in_gb" , func ( f * float64 ) {
419+ createDatabase .DatasetSizeInGB = f
420+ })
417421
418- if v , ok := d . GetOk ( "memory_limit_in_gb" ); ok {
419- createDatabase .MemoryLimitInGB = redis . Float64 ( v .( float64 ))
420- }
422+ utils . SetFloat64 ( d , "memory_limit_in_gb" , func ( f * float64 ) {
423+ createDatabase .MemoryLimitInGB = f
424+ })
421425
422- if v , ok := d . GetOk ( "port" ); ok {
423- createDatabase .PortNumber = redis . Int ( v .( int ))
424- }
426+ utils . SetIntIfPositive ( d , "port" , func ( i * int ) {
427+ createDatabase .PortNumber = i
428+ })
425429
426- if respVersion != "" {
427- createDatabase .RespVersion = redis .String (respVersion )
428- }
430+ utils .SetStringIfNotEmpty (d , "global_resp_version" , func (s * string ) {
431+ createDatabase .RespVersion = s
432+ })
433+
434+ utils .SetStringIfNotEmpty (d , "redis_version" , func (s * string ) {
435+ createDatabase .RedisVersion = s
436+ })
429437
430438 // Confirm Subscription Active status before creating database
431439 err = waitForSubscriptionToBeActive (ctx , subId , api )
@@ -591,6 +599,10 @@ func resourceRedisCloudActiveActiveDatabaseRead(ctx context.Context, d *schema.R
591599 return diag .FromErr (err )
592600 }
593601
602+ if err := d .Set ("redis_version" , redis .StringValue (db .RedisVersion )); err != nil {
603+ return diag .FromErr (err )
604+ }
605+
594606 tlsAuthEnabled := * db .CrdbDatabases [0 ].Security .TLSClientAuthentication
595607 if err := applyCertificateHints (tlsAuthEnabled , d ); err != nil {
596608 return diag .FromErr (err )
0 commit comments