@@ -49,7 +49,7 @@ func resourceRedisCloudProDatabase() *schema.Resource {
4949 Delete : schema .DefaultTimeout (10 * time .Minute ),
5050 },
5151
52- CustomizeDiff : remoteBackupIntervalSetCorrectly ( "remote_backup" ),
52+ CustomizeDiff : customizeDiff ( ),
5353
5454 Schema : map [string ]* schema.Schema {
5555 "subscription_id" : {
@@ -91,12 +91,6 @@ func resourceRedisCloudProDatabase() *schema.Resource {
9191 Computed : true ,
9292 ExactlyOneOf : []string {"memory_limit_in_gb" , "dataset_size_in_gb" },
9393 },
94- "query_performance_factor" : {
95- Description : "Query performance factor for this specific database" ,
96- Type : schema .TypeString ,
97- Optional : true ,
98- Computed : true ,
99- },
10094 "support_oss_cluster_api" : {
10195 Description : "Support Redis open-source (OSS) Cluster API" ,
10296 Type : schema .TypeBool ,
@@ -221,6 +215,13 @@ func resourceRedisCloudProDatabase() *schema.Resource {
221215 },
222216 },
223217 },
218+ "query_performance_factor" : {
219+ Description : "Query performance factor for this specific database" ,
220+ Type : schema .TypeString ,
221+ Optional : true ,
222+ Computed : true ,
223+ ForceNew : true ,
224+ },
224225 "modules" : {
225226 Description : "Modules to be provisioned in the database" ,
226227 Type : schema .TypeSet ,
@@ -521,6 +522,10 @@ func resourceRedisCloudProDatabaseRead(ctx context.Context, d *schema.ResourceDa
521522 return diag .FromErr (err )
522523 }
523524
525+ if err := d .Set ("query_performance_factor" , redis .StringValue (db .QueryPerformanceFactor )); err != nil {
526+ return diag .FromErr (err )
527+ }
528+
524529 if err := d .Set ("modules" , flattenModules (db .Modules )); err != nil {
525530 return diag .FromErr (err )
526531 }
@@ -593,6 +598,11 @@ func resourceRedisCloudProDatabaseRead(ctx context.Context, d *schema.ResourceDa
593598 return diag .FromErr (err )
594599 }
595600
601+ ////query_performance_factor
602+ //if err := d.Set("query_performance_factor", redis.String(*db.)); err != nil {
603+ // return diag.FromErr(err)
604+ //}
605+
596606 if err := readTags (ctx , api , subId , dbId , d ); err != nil {
597607 return diag .FromErr (err )
598608 }
@@ -882,6 +892,61 @@ func skipDiffIfIntervalIs12And12HourTimeDiff(k, oldValue, newValue string, d *sc
882892 return oldTime .Minute () == newTime .Minute () && oldTime .Add (12 * time .Hour ).Hour () == newTime .Hour ()
883893}
884894
895+ func customizeDiff () schema.CustomizeDiffFunc {
896+ return func (ctx context.Context , diff * schema.ResourceDiff , meta interface {}) error {
897+ if err := validateQueryPerformanceFactor ()(ctx , diff , meta ); err != nil {
898+ return err
899+ }
900+ if err := remoteBackupIntervalSetCorrectly ("remote_backup" )(ctx , diff , meta ); err != nil {
901+ return err
902+ }
903+ return nil
904+ }
905+ }
906+
907+ func validateQueryPerformanceFactor () schema.CustomizeDiffFunc {
908+ return func (ctx context.Context , diff * schema.ResourceDiff , meta interface {}) error {
909+ // Check if "query_performance_factor" is set
910+ qpf , qpfExists := diff .GetOk ("query_performance_factor" )
911+
912+ // Ensure "modules" is explicitly defined in the HCL
913+ _ , modulesExists := diff .GetOkExists ("modules" )
914+
915+ if qpfExists && qpf .(string ) != "" {
916+ if ! modulesExists {
917+ return fmt .Errorf (`"query_performance_factor" requires the "modules" key to be explicitly defined in HCL` )
918+ }
919+
920+ // Retrieve modules as a slice of interfaces
921+ rawModules := diff .Get ("modules" ).(* schema.Set ).List ()
922+
923+ // Convert modules to []map[string]interface{}
924+ var modules []map [string ]interface {}
925+ for _ , rawModule := range rawModules {
926+ if moduleMap , ok := rawModule .(map [string ]interface {}); ok {
927+ modules = append (modules , moduleMap )
928+ }
929+ }
930+
931+ // Check if "RediSearch" exists
932+ if ! containsDBModule (modules , "RediSearch" ) {
933+ return fmt .Errorf (`"query_performance_factor" requires the "modules" list to contain "RediSearch"` )
934+ }
935+ }
936+ return nil
937+ }
938+ }
939+
940+ // Helper function to check if a module exists
941+ func containsDBModule (modules []map [string ]interface {}, moduleName string ) bool {
942+ for _ , module := range modules {
943+ if name , ok := module ["name" ].(string ); ok && name == moduleName {
944+ return true
945+ }
946+ }
947+ return false
948+ }
949+
885950func remoteBackupIntervalSetCorrectly (key string ) schema.CustomizeDiffFunc {
886951 // Validate multiple attributes - https://github.com/hashicorp/terraform-plugin-sdk/issues/233
887952
0 commit comments