Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make machine type updatable on Google managed notebooks #16993

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/9690.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
notebooks: allowed `machine_type` and `accelerator_config` to be updatable on `google_notebooks_runtime`
```
66 changes: 66 additions & 0 deletions google/services/notebooks/resource_notebooks_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,72 @@ func resourceNotebooksRuntimeUpdate(d *schema.ResourceData, meta interface{}) er
if err != nil {
return err
}
// remove virtualMachine from updateMask
callSwitch := false
for i, field := range updateMask {
if field == "virtualMachine" {
callSwitch = true
updateMask = append(updateMask[:i], updateMask[i+1:]...)
break
}
}

if callSwitch {
// reconstruct url
url, err = tpgresource.ReplaceVars(d, config, "{{NotebooksBasePath}}projects/{{project}}/locations/{{location}}/runtimes/{{name}}")
if err != nil {
return err
}
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
if err != nil {
return err
}

state := d.Get("state").(string)
if state == "INITIALIZING" {
time.Sleep(300 * time.Second)
}

switchURL, err := tpgresource.ReplaceVars(d, config, "{{NotebooksBasePath}}projects/{{project}}/locations/{{location}}/runtimes/{{name}}:switch")
if err != nil {
return err
}
log.Printf("[DEBUG] Switching Runtime: %q", d.Id())

switchObj := make(map[string]interface{})
machineType := d.Get("virtual_machine.0.virtual_machine_config.0.machine_type")
switchObj["machineType"] = machineType

acceleratorConfigInterface := make(map[string]interface{})
_, ok := d.GetOk("virtual_machine.0.virtual_machine_config.0.accelerator_config")
if ok {
acceleratorConfigInterface["coreCount"] = d.Get("virtual_machine.0.virtual_machine_config.0.accelerator_config.0.core_count")
acceleratorConfigInterface["type"] = d.Get("virtual_machine.0.virtual_machine_config.0.accelerator_config.0.type")
}
switchObj["acceleratorConfig"] = acceleratorConfigInterface

dRes, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "POST",
RawURL: switchURL,
UserAgent: userAgent,
Body: switchObj,
Timeout: d.Timeout(schema.TimeoutUpdate),
})

if err != nil {
return fmt.Errorf("Error switching Runtime: %s", err)
}

var opRes map[string]interface{}
err = NotebooksOperationWaitTimeWithResponse(
config, dRes, &opRes, project, "Switching runtime", userAgent,
d.Timeout(schema.TimeoutUpdate))
if err != nil {
return fmt.Errorf("Error switching runtime: %s", err)
}

}

// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
Expand Down
6 changes: 5 additions & 1 deletion google/services/notebooks/resource_notebooks_runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,17 @@ resource "google_notebooks_runtime" "runtime" {
}
virtual_machine {
virtual_machine_config {
machine_type = "n1-standard-4"
machine_type = "n1-standard-8"
data_disk {
initialize_params {
disk_size_gb = "100"
disk_type = "PD_STANDARD"
}
}
accelerator_config {
core_count = "1"
type = "NVIDIA_TESLA_V100"
}
reserved_ip_range = "192.168.255.0/24"
}
}
Expand Down