Skip to content

Commit

Permalink
Make machine type updatable on Google managed notebooks (#9690) (#16993)
Browse files Browse the repository at this point in the history
* ignore output only fields in update test to fix TestAccNotebooksInstance_update test

* switch machine type for GmN

* Add a pre_update to ignore vm config updates in updateMask

* added pre_update

* added pre_update

* added pre_update

* added pre_update

* added pre_update

* added pre_update

* added pre_update

* added pre_update

* added pre_update

* getok for accelerator intead of get

* Update mmv1/templates/terraform/pre_update/notebooks_runtime.go.erb



* Update mmv1/templates/terraform/pre_update/notebooks_runtime.go.erb



* Update mmv1/templates/terraform/pre_update/notebooks_runtime.go.erb



* format

* format

---------


[upstream:07becb38281f9bbca298082242def0729289cd99]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Jan 12, 2024
1 parent fcd7fab commit 433769c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
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

0 comments on commit 433769c

Please sign in to comment.