Skip to content

Commit 9d0f01a

Browse files
Auto-upgrade for colab runtimes (#12931)
[upstream:b79356dcaaa3925403eade2599558778d385097f] Signed-off-by: Modular Magician <[email protected]>
1 parent 105b7e5 commit 9d0f01a

6 files changed

+106
-5
lines changed

.changelog/12931.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
colab: Auto-upgrade for colab runtimes
3+
```

google-beta/services/colab/resource_colab_runtime.go

+62
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,21 @@ func ResourceColabRuntime() *schema.Resource {
140140
},
141141
},
142142
},
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+
},
143158
"state": {
144159
Type: schema.TypeString,
145160
Computed: true,
@@ -151,6 +166,11 @@ func ResourceColabRuntime() *schema.Resource {
151166
Description: `Desired state of the Colab Runtime. Set this field to 'RUNNING' to start the runtime, and 'STOPPED' to stop it.`,
152167
Default: "RUNNING",
153168
},
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+
},
154174
"project": {
155175
Type: schema.TypeString,
156176
Optional: true,
@@ -325,6 +345,15 @@ func resourceColabRuntimeRead(d *schema.ResourceData, meta interface{}) error {
325345
if err := d.Set("state", flattenColabRuntimeState(res["state"], d, config)); err != nil {
326346
return fmt.Errorf("Error reading Runtime: %s", err)
327347
}
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+
}
328357

329358
return nil
330359
}
@@ -370,6 +399,27 @@ func resourceColabRuntimeUpdate(d *schema.ResourceData, meta interface{}) error
370399
log.Printf("[DEBUG] Colab runtime %q has state %q.", name, state)
371400
}
372401

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+
373423
return nil
374424
}
375425

@@ -487,6 +537,18 @@ func flattenColabRuntimeState(v interface{}, d *schema.ResourceData, config *tra
487537
return v
488538
}
489539

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+
490552
func expandColabRuntimeNotebookRuntimeTemplateRef(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
491553
l := v.([]interface{})
492554
if len(l) == 0 || l[0] == nil {

google-beta/services/colab/resource_colab_runtime_generated_meta.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@ api_service_name: 'aiplatform.googleapis.com'
55
api_version: 'v1beta1'
66
api_resource_type_kind: 'NotebookRuntime'
77
fields:
8+
- field: 'auto_upgrade'
9+
provider_only: true
810
- field: 'description'
911
- field: 'desired_state'
1012
provider_only: true
1113
- field: 'display_name'
14+
- field: 'expiration_time'
15+
- field: 'is_upgradable'
1216
- field: 'location'
1317
provider_only: true
1418
- field: 'name'
1519
provider_only: true
1620
- field: 'notebook_runtime_template_ref.notebook_runtime_template'
21+
- field: 'notebook_runtime_type'
1722
- field: 'runtime_user'
1823
- field: 'state'

google-beta/services/colab/resource_colab_runtime_generated_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func TestAccColabRuntime_colabRuntimeFullExample(t *testing.T) {
170170
ResourceName: "google_colab_runtime.runtime",
171171
ImportState: true,
172172
ImportStateVerify: true,
173-
ImportStateVerifyIgnore: []string{"desired_state", "location", "name"},
173+
ImportStateVerifyIgnore: []string{"auto_upgrade", "desired_state", "location", "name"},
174174
},
175175
},
176176
})
@@ -235,6 +235,8 @@ resource "google_colab_runtime" "runtime" {
235235
236236
desired_state = "ACTIVE"
237237
238+
auto_upgrade = true
239+
238240
depends_on = [
239241
google_colab_runtime_template.my_template
240242
]

google-beta/services/colab/resource_colab_runtime_test.go

+20-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestAccColabRuntime_update(t *testing.T) {
3131
ResourceName: "google_colab_runtime.runtime",
3232
ImportState: true,
3333
ImportStateVerify: true,
34-
ImportStateVerifyIgnore: []string{"desired_state", "location", "name"},
34+
ImportStateVerifyIgnore: []string{"desired_state", "location", "name", "auto_upgrade"},
3535
},
3636
{
3737
Config: testAccColabRuntime_no_state(context),
@@ -40,7 +40,7 @@ func TestAccColabRuntime_update(t *testing.T) {
4040
ResourceName: "google_colab_runtime.runtime",
4141
ImportState: true,
4242
ImportStateVerify: true,
43-
ImportStateVerifyIgnore: []string{"desired_state", "location", "name"},
43+
ImportStateVerifyIgnore: []string{"desired_state", "location", "name", "auto_upgrade"},
4444
},
4545
{
4646
Config: testAccColabRuntime_stopped(context),
@@ -54,7 +54,21 @@ func TestAccColabRuntime_update(t *testing.T) {
5454
ResourceName: "google_colab_runtime.runtime",
5555
ImportState: true,
5656
ImportStateVerify: true,
57-
ImportStateVerifyIgnore: []string{"desired_state", "location", "name"},
57+
ImportStateVerifyIgnore: []string{"desired_state", "location", "name", "auto_upgrade"},
58+
},
59+
{
60+
Config: testAccColabRuntime_full(context),
61+
ConfigPlanChecks: resource.ConfigPlanChecks{
62+
PreApply: []plancheck.PlanCheck{
63+
plancheck.ExpectResourceAction("google_colab_runtime.runtime", plancheck.ResourceActionUpdate),
64+
},
65+
},
66+
},
67+
{
68+
ResourceName: "google_colab_runtime.runtime",
69+
ImportState: true,
70+
ImportStateVerify: true,
71+
ImportStateVerifyIgnore: []string{"desired_state", "location", "name", "auto_upgrade"},
5872
},
5973
},
6074
})
@@ -117,7 +131,9 @@ resource "google_colab_runtime" "runtime" {
117131
runtime_user = "[email protected]"
118132
description = "Full runtime"
119133
120-
desired_state = "ACTIVE"
134+
desired_state = "RUNNING"
135+
136+
auto_upgrade = true
121137
122138
depends_on = [
123139
google_colab_runtime_template.my_template

website/docs/r/colab_runtime.html.markdown

+13
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ resource "google_colab_runtime" "runtime" {
174174
175175
desired_state = "ACTIVE"
176176
177+
auto_upgrade = true
178+
177179
depends_on = [
178180
google_colab_runtime_template.my_template
179181
]
@@ -219,6 +221,8 @@ The following arguments are supported:
219221

220222
* `desired_state` - (Optional) Desired state of the Colab Runtime. Set this field to `RUNNING` to start the runtime, and `STOPPED` to stop it.
221223

224+
* `auto_upgrade` - (Optional) Triggers an upgrade anytime the runtime is started if it is upgradable.
225+
222226

223227
<a name="nested_notebook_runtime_template_ref"></a>The `notebook_runtime_template_ref` block supports:
224228

@@ -235,6 +239,15 @@ In addition to the arguments listed above, the following computed attributes are
235239
* `state` -
236240
Output only. The state of the runtime.
237241

242+
* `is_upgradable` -
243+
Output only. Checks if the NotebookRuntime is upgradable.
244+
245+
* `expiration_time` -
246+
Output only. Timestamp when this NotebookRuntime will be expired.
247+
248+
* `notebook_runtime_type` -
249+
Output only. The type of the notebook runtime.
250+
238251

239252
## Timeouts
240253

0 commit comments

Comments
 (0)