Skip to content

Commit 0550462

Browse files
Runtime patch (#6137) (#12113)
Co-authored-by: Shuya Ma <[email protected]> Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Shuya Ma <[email protected]>
1 parent 411e419 commit 0550462

File tree

4 files changed

+166
-3
lines changed

4 files changed

+166
-3
lines changed

.changelog/6137.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
```release-note:enhancement
2+
notebooks: added field `reserved_ip_range` to `google_notebooks_runtime`
3+
```
4+
```release-note:bug
5+
notebooks: fixed a bug where`google_notebooks_runtime` can't be updated
6+
```

google/resource_notebooks_runtime.go

+55-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func resourceNotebooksRuntime() *schema.Resource {
7575
Type: schema.TypeString,
7676
Required: true,
7777
ForceNew: true,
78-
Description: `The name specified for the Notebook instance.`,
78+
Description: `The name specified for the Notebook runtime.`,
7979
},
8080
"access_config": {
8181
Type: schema.TypeList,
@@ -357,6 +357,7 @@ rest/v1/projects.locations.runtimes#AcceleratorType'`,
357357
Type: schema.TypeList,
358358
Computed: true,
359359
Optional: true,
360+
ForceNew: true,
360361
Description: `Use a list of container images to start the notebook instance.`,
361362
Elem: &schema.Resource{
362363
Schema: map[string]*schema.Schema{
@@ -377,6 +378,7 @@ For example: gcr.io/{project_id}/{imageName}`,
377378
"encryption_config": {
378379
Type: schema.TypeList,
379380
Optional: true,
381+
ForceNew: true,
380382
Description: `Encryption settings for virtual machine data disk.`,
381383
MaxItems: 1,
382384
Elem: &schema.Resource{
@@ -396,6 +398,7 @@ It has the following format:
396398
"internal_ip_only": {
397399
Type: schema.TypeBool,
398400
Optional: true,
401+
ForceNew: true,
399402
Description: `If true, runtime will only have internal IP addresses. By default,
400403
runtimes are not restricted to internal IP addresses, and will
401404
have ephemeral external IP addresses assigned to each vm. This
@@ -429,6 +432,7 @@ _metadata)).`,
429432
"network": {
430433
Type: schema.TypeString,
431434
Optional: true,
435+
ForceNew: true,
432436
Description: `The Compute Engine network to be used for machine communications.
433437
Cannot be specified with subnetwork. If neither 'network' nor
434438
'subnet' is specified, the "default" network of the project is
@@ -447,13 +451,22 @@ Runtimes support the following network configurations:
447451
"nic_type": {
448452
Type: schema.TypeString,
449453
Optional: true,
454+
ForceNew: true,
450455
ValidateFunc: validateEnum([]string{"UNSPECIFIED_NIC_TYPE", "VIRTIO_NET", "GVNIC", ""}),
451456
Description: `The type of vNIC to be used on this interface. This may be gVNIC
452457
or VirtioNet. Possible values: ["UNSPECIFIED_NIC_TYPE", "VIRTIO_NET", "GVNIC"]`,
458+
},
459+
"reserved_ip_range": {
460+
Type: schema.TypeString,
461+
Optional: true,
462+
ForceNew: true,
463+
Description: `Reserved IP Range name is used for VPC Peering. The
464+
subnetwork allocation will use the range *name* if it's assigned.`,
453465
},
454466
"shielded_instance_config": {
455467
Type: schema.TypeList,
456468
Optional: true,
469+
ForceNew: true,
457470
Description: `Shielded VM Instance configuration settings.`,
458471
MaxItems: 1,
459472
Elem: &schema.Resource{
@@ -489,6 +502,7 @@ default.`,
489502
"subnet": {
490503
Type: schema.TypeString,
491504
Optional: true,
505+
ForceNew: true,
492506
Description: `The Compute Engine subnetwork to be used for machine
493507
communications. Cannot be specified with network. A full URL or
494508
partial URI are valid. Examples:
@@ -756,13 +770,35 @@ func resourceNotebooksRuntimeUpdate(d *schema.ResourceData, meta interface{}) er
756770
}
757771

758772
log.Printf("[DEBUG] Updating Runtime %q: %#v", d.Id(), obj)
773+
updateMask := []string{}
774+
775+
if d.HasChange("virtual_machine") {
776+
updateMask = append(updateMask, "virtualMachine")
777+
}
778+
779+
if d.HasChange("access_config") {
780+
updateMask = append(updateMask, "accessConfig")
781+
}
782+
783+
if d.HasChange("software_config") {
784+
updateMask = append(updateMask, "softwareConfig.idleShutdown",
785+
"softwareConfig.idleShutdownTimeout",
786+
"softwareConfig.customGpuDriverPath",
787+
"softwareConfig.postStartupScript")
788+
}
789+
// updateMask is a URL parameter but not present in the schema, so replaceVars
790+
// won't set it
791+
url, err = addQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
792+
if err != nil {
793+
return err
794+
}
759795

760796
// err == nil indicates that the billing_project value was found
761797
if bp, err := getBillingProject(d, config); err == nil {
762798
billingProject = bp
763799
}
764800

765-
res, err := sendRequestWithTimeout(config, "PUT", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutUpdate))
801+
res, err := sendRequestWithTimeout(config, "PATCH", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutUpdate))
766802

767803
if err != nil {
768804
return fmt.Errorf("Error updating Runtime %q: %s", d.Id(), err)
@@ -910,6 +946,8 @@ func flattenNotebooksRuntimeVirtualMachineVirtualMachineConfig(v interface{}, d
910946
flattenNotebooksRuntimeVirtualMachineVirtualMachineConfigLabels(original["labels"], d, config)
911947
transformed["nic_type"] =
912948
flattenNotebooksRuntimeVirtualMachineVirtualMachineConfigNicType(original["nicType"], d, config)
949+
transformed["reserved_ip_range"] =
950+
flattenNotebooksRuntimeVirtualMachineVirtualMachineConfigReservedIpRange(original["reservedIpRange"], d, config)
913951
return []interface{}{transformed}
914952
}
915953
func flattenNotebooksRuntimeVirtualMachineVirtualMachineConfigZone(v interface{}, d *schema.ResourceData, config *Config) interface{} {
@@ -1207,6 +1245,10 @@ func flattenNotebooksRuntimeVirtualMachineVirtualMachineConfigNicType(v interfac
12071245
return v
12081246
}
12091247

1248+
func flattenNotebooksRuntimeVirtualMachineVirtualMachineConfigReservedIpRange(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1249+
return v
1250+
}
1251+
12101252
func flattenNotebooksRuntimeState(v interface{}, d *schema.ResourceData, config *Config) interface{} {
12111253
return v
12121254
}
@@ -1482,6 +1524,13 @@ func expandNotebooksRuntimeVirtualMachineVirtualMachineConfig(v interface{}, d T
14821524
transformed["nicType"] = transformedNicType
14831525
}
14841526

1527+
transformedReservedIpRange, err := expandNotebooksRuntimeVirtualMachineVirtualMachineConfigReservedIpRange(original["reserved_ip_range"], d, config)
1528+
if err != nil {
1529+
return nil, err
1530+
} else if val := reflect.ValueOf(transformedReservedIpRange); val.IsValid() && !isEmptyValue(val) {
1531+
transformed["reservedIpRange"] = transformedReservedIpRange
1532+
}
1533+
14851534
return transformed, nil
14861535
}
14871536

@@ -1899,6 +1948,10 @@ func expandNotebooksRuntimeVirtualMachineVirtualMachineConfigNicType(v interface
18991948
return v, nil
19001949
}
19011950

1951+
func expandNotebooksRuntimeVirtualMachineVirtualMachineConfigReservedIpRange(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
1952+
return v, nil
1953+
}
1954+
19021955
func expandNotebooksRuntimeAccessConfig(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
19031956
l := v.([]interface{})
19041957
if len(l) == 0 || l[0] == nil {
+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package google
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccNotebooksRuntime_update(t *testing.T) {
10+
context := map[string]interface{}{
11+
"random_suffix": randString(t, 10),
12+
}
13+
14+
vcrTest(t, resource.TestCase{
15+
PreCheck: func() { testAccPreCheck(t) },
16+
Providers: testAccProviders,
17+
CheckDestroy: testAccCheckNotebooksRuntimeDestroyProducer(t),
18+
Steps: []resource.TestStep{
19+
{
20+
Config: testAccNotebooksRuntime_basic(context),
21+
},
22+
{
23+
ResourceName: "google_notebooks_runtime.runtime",
24+
ImportState: true,
25+
ImportStateVerify: true,
26+
},
27+
{
28+
Config: testAccNotebooksRuntime_update(context),
29+
},
30+
{
31+
ResourceName: "google_notebooks_runtime.runtime",
32+
ImportState: true,
33+
ImportStateVerify: true,
34+
},
35+
{
36+
Config: testAccNotebooksRuntime_basic(context),
37+
},
38+
{
39+
ResourceName: "google_notebooks_runtime.runtime",
40+
ImportState: true,
41+
ImportStateVerify: true,
42+
},
43+
},
44+
})
45+
}
46+
47+
func testAccNotebooksRuntime_basic(context map[string]interface{}) string {
48+
return Nprintf(`
49+
resource "google_notebooks_runtime" "runtime" {
50+
name = "tf-test-notebooks-runtime%{random_suffix}"
51+
location = "us-central1"
52+
access_config {
53+
access_type = "SINGLE_USER"
54+
runtime_owner = "[email protected]"
55+
}
56+
software_config {}
57+
virtual_machine {
58+
virtual_machine_config {
59+
machine_type = "n1-standard-4"
60+
data_disk {
61+
initialize_params {
62+
disk_size_gb = "100"
63+
disk_type = "PD_STANDARD"
64+
}
65+
}
66+
reserved_ip_range = "192.168.255.0/24"
67+
}
68+
}
69+
}
70+
`, context)
71+
}
72+
73+
func testAccNotebooksRuntime_update(context map[string]interface{}) string {
74+
return Nprintf(`
75+
resource "google_notebooks_runtime" "runtime" {
76+
name = "tf-test-notebooks-runtime%{random_suffix}"
77+
location = "us-central1"
78+
access_config {
79+
access_type = "SINGLE_USER"
80+
runtime_owner = "[email protected]"
81+
}
82+
software_config {
83+
idle_shutdown_timeout = "80"
84+
}
85+
virtual_machine {
86+
virtual_machine_config {
87+
machine_type = "n1-standard-4"
88+
data_disk {
89+
initialize_params {
90+
disk_size_gb = "100"
91+
disk_type = "PD_STANDARD"
92+
}
93+
}
94+
reserved_ip_range = "192.168.255.0/24"
95+
}
96+
}
97+
}
98+
`, context)
99+
}

website/docs/r/notebooks_runtime.html.markdown

+6-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ The following arguments are supported:
146146

147147
* `name` -
148148
(Required)
149-
The name specified for the Notebook instance.
149+
The name specified for the Notebook runtime.
150150

151151
* `location` -
152152
(Required)
@@ -291,6 +291,11 @@ The following arguments are supported:
291291
or VirtioNet.
292292
Possible values are `UNSPECIFIED_NIC_TYPE`, `VIRTIO_NET`, and `GVNIC`.
293293

294+
* `reserved_ip_range` -
295+
(Optional)
296+
Reserved IP Range name is used for VPC Peering. The
297+
subnetwork allocation will use the range *name* if it's assigned.
298+
294299

295300
<a name="nested_data_disk"></a>The `data_disk` block supports:
296301

0 commit comments

Comments
 (0)