@@ -119,10 +119,18 @@ Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.`,
119119 Elem : & schema.Schema {Type : schema .TypeString },
120120 },
121121 "num_nodes" : {
122- Type : schema .TypeInt ,
123- Optional : true ,
124- Description : `The number of nodes allocated to this instance.` ,
125- Default : 1 ,
122+ Type : schema .TypeInt ,
123+ Computed : true ,
124+ Optional : true ,
125+ Description : `The number of nodes allocated to this instance. At most one of either node_count or processing_units
126+ can be present in terraform.` ,
127+ },
128+ "processing_units" : {
129+ Type : schema .TypeInt ,
130+ Computed : true ,
131+ Optional : true ,
132+ Description : `The number of processing units allocated to this instance. At most one of processing_units
133+ or node_count can be present in terraform.` ,
126134 },
127135 "state" : {
128136 Type : schema .TypeString ,
@@ -177,6 +185,12 @@ func resourceSpannerInstanceCreate(d *schema.ResourceData, meta interface{}) err
177185 } else if v , ok := d .GetOkExists ("num_nodes" ); ! isEmptyValue (reflect .ValueOf (nodeCountProp )) && (ok || ! reflect .DeepEqual (v , nodeCountProp )) {
178186 obj ["nodeCount" ] = nodeCountProp
179187 }
188+ processingUnitsProp , err := expandSpannerInstanceProcessingUnits (d .Get ("processing_units" ), d , config )
189+ if err != nil {
190+ return err
191+ } else if v , ok := d .GetOkExists ("processing_units" ); ! isEmptyValue (reflect .ValueOf (processingUnitsProp )) && (ok || ! reflect .DeepEqual (v , processingUnitsProp )) {
192+ obj ["processingUnits" ] = processingUnitsProp
193+ }
180194 labelsProp , err := expandSpannerInstanceLabels (d .Get ("labels" ), d , config )
181195 if err != nil {
182196 return err
@@ -325,6 +339,9 @@ func resourceSpannerInstanceRead(d *schema.ResourceData, meta interface{}) error
325339 if err := d .Set ("num_nodes" , flattenSpannerInstanceNumNodes (res ["nodeCount" ], d , config )); err != nil {
326340 return fmt .Errorf ("Error reading Instance: %s" , err )
327341 }
342+ if err := d .Set ("processing_units" , flattenSpannerInstanceProcessingUnits (res ["processingUnits" ], d , config )); err != nil {
343+ return fmt .Errorf ("Error reading Instance: %s" , err )
344+ }
328345 if err := d .Set ("labels" , flattenSpannerInstanceLabels (res ["labels" ], d , config )); err != nil {
329346 return fmt .Errorf ("Error reading Instance: %s" , err )
330347 }
@@ -363,6 +380,12 @@ func resourceSpannerInstanceUpdate(d *schema.ResourceData, meta interface{}) err
363380 } else if v , ok := d .GetOkExists ("num_nodes" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , nodeCountProp )) {
364381 obj ["nodeCount" ] = nodeCountProp
365382 }
383+ processingUnitsProp , err := expandSpannerInstanceProcessingUnits (d .Get ("processing_units" ), d , config )
384+ if err != nil {
385+ return err
386+ } else if v , ok := d .GetOkExists ("processing_units" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , processingUnitsProp )) {
387+ obj ["processingUnits" ] = processingUnitsProp
388+ }
366389 labelsProp , err := expandSpannerInstanceLabels (d .Get ("labels" ), d , config )
367390 if err != nil {
368391 return err
@@ -521,6 +544,23 @@ func flattenSpannerInstanceNumNodes(v interface{}, d *schema.ResourceData, confi
521544 return v // let terraform core handle it otherwise
522545}
523546
547+ func flattenSpannerInstanceProcessingUnits (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
548+ // Handles the string fixed64 format
549+ if strVal , ok := v .(string ); ok {
550+ if intVal , err := strconv .ParseInt (strVal , 10 , 64 ); err == nil {
551+ return intVal
552+ }
553+ }
554+
555+ // number values are represented as float64
556+ if floatVal , ok := v .(float64 ); ok {
557+ intVal := int (floatVal )
558+ return intVal
559+ }
560+
561+ return v // let terraform core handle it otherwise
562+ }
563+
524564func flattenSpannerInstanceLabels (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
525565 return v
526566}
@@ -555,6 +595,10 @@ func expandSpannerInstanceNumNodes(v interface{}, d TerraformResourceData, confi
555595 return v , nil
556596}
557597
598+ func expandSpannerInstanceProcessingUnits (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
599+ return v , nil
600+ }
601+
558602func expandSpannerInstanceLabels (v interface {}, d TerraformResourceData , config * Config ) (map [string ]string , error ) {
559603 if v == nil {
560604 return map [string ]string {}, nil
@@ -567,6 +611,10 @@ func expandSpannerInstanceLabels(v interface{}, d TerraformResourceData, config
567611}
568612
569613func resourceSpannerInstanceEncoder (d * schema.ResourceData , meta interface {}, obj map [string ]interface {}) (map [string ]interface {}, error ) {
614+ // Temp Logic to accomodate processing_units and num_nodes
615+ if obj ["processingUnits" ] == nil && obj ["nodeCount" ] == nil {
616+ obj ["nodeCount" ] = 1
617+ }
570618 newObj := make (map [string ]interface {})
571619 newObj ["instance" ] = obj
572620 if obj ["name" ] == nil {
0 commit comments