@@ -140,6 +140,21 @@ func ResourceColabRuntime() *schema.Resource {
140
140
},
141
141
},
142
142
},
143
+ "expiration_time" : {
144
+ Type : schema .TypeString ,
145
+ Computed : true ,
146
+ Description : `Output only. Timestamp when this NotebookRuntime will be expired.` ,
147
+ },
148
+ "is_upgradable" : {
149
+ Type : schema .TypeBool ,
150
+ Computed : true ,
151
+ Description : `Output only. Checks if the NotebookRuntime is upgradable.` ,
152
+ },
153
+ "notebook_runtime_type" : {
154
+ Type : schema .TypeString ,
155
+ Computed : true ,
156
+ Description : `Output only. The type of the notebook runtime.` ,
157
+ },
143
158
"state" : {
144
159
Type : schema .TypeString ,
145
160
Computed : true ,
@@ -151,6 +166,11 @@ func ResourceColabRuntime() *schema.Resource {
151
166
Description : `Desired state of the Colab Runtime. Set this field to 'RUNNING' to start the runtime, and 'STOPPED' to stop it.` ,
152
167
Default : "RUNNING" ,
153
168
},
169
+ "auto_upgrade" : {
170
+ Type : schema .TypeBool ,
171
+ Optional : true ,
172
+ Description : `Triggers an upgrade anytime the runtime is started if it is upgradable.` ,
173
+ },
154
174
"project" : {
155
175
Type : schema .TypeString ,
156
176
Optional : true ,
@@ -325,6 +345,15 @@ func resourceColabRuntimeRead(d *schema.ResourceData, meta interface{}) error {
325
345
if err := d .Set ("state" , flattenColabRuntimeState (res ["state" ], d , config )); err != nil {
326
346
return fmt .Errorf ("Error reading Runtime: %s" , err )
327
347
}
348
+ if err := d .Set ("is_upgradable" , flattenColabRuntimeIsUpgradable (res ["isUpgradable" ], d , config )); err != nil {
349
+ return fmt .Errorf ("Error reading Runtime: %s" , err )
350
+ }
351
+ if err := d .Set ("expiration_time" , flattenColabRuntimeExpirationTime (res ["expirationTime" ], d , config )); err != nil {
352
+ return fmt .Errorf ("Error reading Runtime: %s" , err )
353
+ }
354
+ if err := d .Set ("notebook_runtime_type" , flattenColabRuntimeNotebookRuntimeType (res ["notebookRuntimeType" ], d , config )); err != nil {
355
+ return fmt .Errorf ("Error reading Runtime: %s" , err )
356
+ }
328
357
329
358
return nil
330
359
}
@@ -370,6 +399,27 @@ func resourceColabRuntimeUpdate(d *schema.ResourceData, meta interface{}) error
370
399
log .Printf ("[DEBUG] Colab runtime %q has state %q." , name , state )
371
400
}
372
401
402
+ var upgrade_runtime bool
403
+ if d .Get ("auto_upgrade" ).(bool ) && d .Get ("is_upgradable" ).(bool ) {
404
+ upgrade_runtime = true
405
+ }
406
+
407
+ expiration_time_string := d .Get ("expiration_time" ).(string )
408
+ expiration_time , err := time .Parse (time .RFC3339Nano , expiration_time_string )
409
+ if err != nil {
410
+ return err
411
+ }
412
+
413
+ if expiration_time .Before (time .Now ()) && d .Get ("notebook_runtime_type" ).(string ) == "USER_DEFINED" {
414
+ upgrade_runtime = true
415
+ }
416
+
417
+ if upgrade_runtime {
418
+ if err := ModifyColabRuntime (config , d , project , billingProject , userAgent , "upgrade" ); err != nil {
419
+ return err
420
+ }
421
+ }
422
+
373
423
return nil
374
424
}
375
425
@@ -487,6 +537,18 @@ func flattenColabRuntimeState(v interface{}, d *schema.ResourceData, config *tra
487
537
return v
488
538
}
489
539
540
+ func flattenColabRuntimeIsUpgradable (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
541
+ return v
542
+ }
543
+
544
+ func flattenColabRuntimeExpirationTime (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
545
+ return v
546
+ }
547
+
548
+ func flattenColabRuntimeNotebookRuntimeType (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
549
+ return v
550
+ }
551
+
490
552
func expandColabRuntimeNotebookRuntimeTemplateRef (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
491
553
l := v .([]interface {})
492
554
if len (l ) == 0 || l [0 ] == nil {
0 commit comments