@@ -25,16 +25,18 @@ const (
2525 minApplyThresholdValue = 0.01
2626 maxApplyThresholdValue = 2.5
2727 defaultApplyThresholdPercentage = 0.1
28+ defaultConfidenceThreshold = 0.9
2829 minNumeratorValue = 0.0
2930 maxExponentValue = 1.
3031 minExponentValue = 0.
3132)
3233
3334const (
34- FieldLimitStrategy = "limit"
35- FieldLimitStrategyType = "type"
36- FieldLimitStrategyMultiplier = "multiplier"
37-
35+ FieldLimitStrategy = "limit"
36+ FieldLimitStrategyType = "type"
37+ FieldLimitStrategyMultiplier = "multiplier"
38+ FieldConfidence = "confidence"
39+ FieldConfidenceThreshold = "threshold"
3840 DeprecatedFieldApplyThreshold = "apply_threshold"
3941 FieldApplyThresholdStrategy = "apply_threshold_strategy"
4042 FieldApplyThresholdStrategyType = "type"
@@ -119,6 +121,26 @@ func resourceWorkloadScalingPolicy() *schema.Resource {
119121 },
120122 },
121123 },
124+ FieldConfidence : {
125+ Type : schema .TypeList ,
126+ Optional : true ,
127+ MaxItems : 1 ,
128+ Description : "Defines the confidence settings for applying recommendations." ,
129+ DiffSuppressFunc : func (k , old , new string , d * schema.ResourceData ) bool {
130+ return suppressConfidenceThresholdDefaultValueDiff (FieldConfidence , old , new , d )
131+ },
132+ Elem : & schema.Resource {
133+ Schema : map [string ]* schema.Schema {
134+ FieldConfidenceThreshold : {
135+ Type : schema .TypeFloat ,
136+ Optional : true ,
137+ Default : 0.9 ,
138+ Description : "Defines the confidence threshold for applying recommendations. The smaller number indicates that we require fewer metrics data points to apply recommendations." ,
139+ ValidateDiagFunc : validation .ToDiagFunc (validation .FloatBetween (0 , 1 )),
140+ },
141+ },
142+ },
143+ },
122144 "downscaling" : {
123145 Type : schema .TypeList ,
124146 Optional : true ,
@@ -381,6 +403,8 @@ func resourceWorkloadScalingPolicyCreate(ctx context.Context, d *schema.Resource
381403 }
382404 req .RecommendationPolicies .Memory = memory
383405 }
406+
407+ req .RecommendationPolicies .Confidence = toConfidence (toSection (d , FieldConfidence ))
384408
385409 req .RecommendationPolicies .Startup = toStartup (toSection (d , "startup" ))
386410
@@ -452,6 +476,9 @@ func resourceWorkloadScalingPolicyRead(ctx context.Context, d *schema.ResourceDa
452476 if err := d .Set ("startup" , toStartupMap (sp .RecommendationPolicies .Startup )); err != nil {
453477 return diag .FromErr (fmt .Errorf ("setting startup: %w" , err ))
454478 }
479+ if err := d .Set (FieldConfidence , toConfidenceMap (sp .RecommendationPolicies .Confidence )); err != nil {
480+ return diag .FromErr (fmt .Errorf ("setting confidence: %w" , err ))
481+ }
455482 if err := d .Set ("downscaling" , toDownscalingMap (sp .RecommendationPolicies .Downscaling )); err != nil {
456483 return diag .FromErr (fmt .Errorf ("setting downscaling: %w" , err ))
457484 }
@@ -483,6 +510,7 @@ func resourceWorkloadScalingPolicyUpdate(ctx context.Context, d *schema.Resource
483510 "downscaling" ,
484511 "memory_event" ,
485512 "anti_affinity" ,
513+ FieldConfidence ,
486514 ) {
487515 tflog .Info (ctx , "scaling policy up to date" )
488516 return nil
@@ -509,6 +537,7 @@ func resourceWorkloadScalingPolicyUpdate(ctx context.Context, d *schema.Resource
509537 Downscaling : toDownscaling (toSection (d , "downscaling" )),
510538 MemoryEvent : toMemoryEvent (toSection (d , "memory_event" )),
511539 AntiAffinity : toAntiAffinity (toSection (d , "anti_affinity" )),
540+ Confidence : toConfidence (toSection (d , FieldConfidence )),
512541 },
513542 }
514543
@@ -740,6 +769,17 @@ func suppressThresholdStrategyDefaultValueDiff(resource, oldValue, newValue stri
740769 return oldValue == newValue
741770}
742771
772+ func suppressConfidenceThresholdDefaultValueDiff (resource , oldValue , newValue string , d * schema.ResourceData ) bool {
773+ isConfidenceUnset := newValue == "0" || newValue == ""
774+ if isConfidenceUnset {
775+ confidenceThreshold := d .Get (fmt .Sprintf ("%s.0.%s" , resource , FieldConfidenceThreshold ))
776+ // Suppress diff if configuration saved from API equals to default
777+ return confidenceThreshold == defaultConfidenceThreshold
778+ }
779+
780+ return oldValue == newValue
781+ }
782+
743783func toWorkloadResourceLimit (obj map [string ]any ) (* sdk.WorkloadoptimizationV1ResourceLimitStrategy , error ) {
744784 if len (obj ) == 0 {
745785 return nil , nil
@@ -852,6 +892,32 @@ func applyThresholdStrategyToMap(s *sdk.WorkloadoptimizationV1ApplyThresholdStra
852892 return []map [string ]any {m }
853893}
854894
895+ func toConfidence (confidence map [string ]any ) * sdk.WorkloadoptimizationV1ConfidenceSettings {
896+ if len (confidence ) == 0 {
897+ return nil
898+ }
899+
900+ result := & sdk.WorkloadoptimizationV1ConfidenceSettings {}
901+
902+ if v , ok := confidence [FieldConfidenceThreshold ].(float64 ); ok {
903+ result .Threshold = & v
904+ }
905+
906+ return result
907+ }
908+
909+ func toConfidenceMap (s * sdk.WorkloadoptimizationV1ConfidenceSettings ) []map [string ]any {
910+ if s == nil {
911+ return nil
912+ }
913+
914+ m := map [string ]any {
915+ FieldConfidenceThreshold : s .Threshold ,
916+ }
917+
918+ return []map [string ]any {m }
919+ }
920+
855921func toStartup (startup map [string ]any ) * sdk.WorkloadoptimizationV1StartupSettings {
856922 if len (startup ) == 0 {
857923 return nil
0 commit comments