@@ -159,22 +159,44 @@ the instance.`,
159159 Type : schema .TypeList ,
160160 Optional : true ,
161161 Description : `Defines scale in controls to reduce the risk of response latency
162- and outages due to abrupt scale-in events` ,
162+ and outages due to abrupt scale-in events. Users can define the minimum and
163+ maximum compute capacity allocated to the instance, and the autoscaler will
164+ only scale within that range. Users can either use nodes or processing
165+ units to specify the limits, but should use the same unit to set both the
166+ min_limit and max_limit.` ,
163167 MaxItems : 1 ,
164168 Elem : & schema.Resource {
165169 Schema : map [string ]* schema.Schema {
170+ "max_nodes" : {
171+ Type : schema .TypeInt ,
172+ Optional : true ,
173+ Description : `Specifies maximum number of nodes allocated to the instance. If set, this number
174+ should be greater than or equal to min_nodes.` ,
175+ ExactlyOneOf : []string {},
176+ RequiredWith : []string {},
177+ },
166178 "max_processing_units" : {
167179 Type : schema .TypeInt ,
168180 Optional : true ,
169181 Description : `Specifies maximum number of processing units allocated to the instance.
170182If set, this number should be multiples of 1000 and be greater than or equal to
171183min_processing_units.` ,
184+ ExactlyOneOf : []string {},
185+ },
186+ "min_nodes" : {
187+ Type : schema .TypeInt ,
188+ Optional : true ,
189+ Description : `Specifies number of nodes allocated to the instance. If set, this number
190+ should be greater than or equal to 1.` ,
191+ ExactlyOneOf : []string {},
192+ RequiredWith : []string {},
172193 },
173194 "min_processing_units" : {
174195 Type : schema .TypeInt ,
175196 Optional : true ,
176197 Description : `Specifies minimum number of processing units allocated to the instance.
177198If set, this number should be multiples of 1000.` ,
199+ ExactlyOneOf : []string {},
178200 },
179201 },
180202 },
@@ -792,6 +814,10 @@ func flattenSpannerInstanceAutoscalingConfigAutoscalingLimits(v interface{}, d *
792814 flattenSpannerInstanceAutoscalingConfigAutoscalingLimitsMinProcessingUnits (original ["minProcessingUnits" ], d , config )
793815 transformed ["max_processing_units" ] =
794816 flattenSpannerInstanceAutoscalingConfigAutoscalingLimitsMaxProcessingUnits (original ["maxProcessingUnits" ], d , config )
817+ transformed ["min_nodes" ] =
818+ flattenSpannerInstanceAutoscalingConfigAutoscalingLimitsMinNodes (original ["minNodes" ], d , config )
819+ transformed ["max_nodes" ] =
820+ flattenSpannerInstanceAutoscalingConfigAutoscalingLimitsMaxNodes (original ["maxNodes" ], d , config )
795821 return []interface {}{transformed }
796822}
797823func flattenSpannerInstanceAutoscalingConfigAutoscalingLimitsMinProcessingUnits (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
@@ -828,6 +854,40 @@ func flattenSpannerInstanceAutoscalingConfigAutoscalingLimitsMaxProcessingUnits(
828854 return v // let terraform core handle it otherwise
829855}
830856
857+ func flattenSpannerInstanceAutoscalingConfigAutoscalingLimitsMinNodes (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
858+ // Handles the string fixed64 format
859+ if strVal , ok := v .(string ); ok {
860+ if intVal , err := tpgresource .StringToFixed64 (strVal ); err == nil {
861+ return intVal
862+ }
863+ }
864+
865+ // number values are represented as float64
866+ if floatVal , ok := v .(float64 ); ok {
867+ intVal := int (floatVal )
868+ return intVal
869+ }
870+
871+ return v // let terraform core handle it otherwise
872+ }
873+
874+ func flattenSpannerInstanceAutoscalingConfigAutoscalingLimitsMaxNodes (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
875+ // Handles the string fixed64 format
876+ if strVal , ok := v .(string ); ok {
877+ if intVal , err := tpgresource .StringToFixed64 (strVal ); err == nil {
878+ return intVal
879+ }
880+ }
881+
882+ // number values are represented as float64
883+ if floatVal , ok := v .(float64 ); ok {
884+ intVal := int (floatVal )
885+ return intVal
886+ }
887+
888+ return v // let terraform core handle it otherwise
889+ }
890+
831891func flattenSpannerInstanceAutoscalingConfigAutoscalingTargets (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
832892 if v == nil {
833893 return nil
@@ -975,6 +1035,20 @@ func expandSpannerInstanceAutoscalingConfigAutoscalingLimits(v interface{}, d tp
9751035 transformed ["maxProcessingUnits" ] = transformedMaxProcessingUnits
9761036 }
9771037
1038+ transformedMinNodes , err := expandSpannerInstanceAutoscalingConfigAutoscalingLimitsMinNodes (original ["min_nodes" ], d , config )
1039+ if err != nil {
1040+ return nil , err
1041+ } else if val := reflect .ValueOf (transformedMinNodes ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
1042+ transformed ["minNodes" ] = transformedMinNodes
1043+ }
1044+
1045+ transformedMaxNodes , err := expandSpannerInstanceAutoscalingConfigAutoscalingLimitsMaxNodes (original ["max_nodes" ], d , config )
1046+ if err != nil {
1047+ return nil , err
1048+ } else if val := reflect .ValueOf (transformedMaxNodes ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
1049+ transformed ["maxNodes" ] = transformedMaxNodes
1050+ }
1051+
9781052 return transformed , nil
9791053}
9801054
@@ -986,6 +1060,14 @@ func expandSpannerInstanceAutoscalingConfigAutoscalingLimitsMaxProcessingUnits(v
9861060 return v , nil
9871061}
9881062
1063+ func expandSpannerInstanceAutoscalingConfigAutoscalingLimitsMinNodes (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
1064+ return v , nil
1065+ }
1066+
1067+ func expandSpannerInstanceAutoscalingConfigAutoscalingLimitsMaxNodes (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
1068+ return v , nil
1069+ }
1070+
9891071func expandSpannerInstanceAutoscalingConfigAutoscalingTargets (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
9901072 l := v .([]interface {})
9911073 if len (l ) == 0 || l [0 ] == nil {
@@ -1077,6 +1159,12 @@ func resourceSpannerInstanceUpdateEncoder(d *schema.ResourceData, meta interface
10771159 if d .HasChange ("autoscaling_config.0.autoscaling_limits.0.min_processing_units" ) {
10781160 updateMask = append (updateMask , "autoscalingConfig.autoscalingLimits.minProcessingUnits" )
10791161 }
1162+ if d .HasChange ("autoscaling_config.0.autoscaling_limits.0.max_nodes" ) {
1163+ updateMask = append (updateMask , "autoscalingConfig.autoscalingLimits.maxNodes" )
1164+ }
1165+ if d .HasChange ("autoscaling_config.0.autoscaling_limits.0.min_nodes" ) {
1166+ updateMask = append (updateMask , "autoscalingConfig.autoscalingLimits.minNodes" )
1167+ }
10801168 if d .HasChange ("autoscaling_config.0.autoscaling_targets.0.high_priority_cpu_utilization_percent" ) {
10811169 updateMask = append (updateMask , "autoscalingConfig.autoscalingTargets.highPriorityCpuUtilizationPercent" )
10821170 }
0 commit comments