Skip to content

Commit aa69ddc

Browse files
notebooks - add args + promote some args to GA (#6243) (#4530)
Signed-off-by: Modular Magician <[email protected]>
1 parent 6505c5e commit aa69ddc

File tree

6 files changed

+354
-8
lines changed

6 files changed

+354
-8
lines changed

.changelog/6243.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
```release-note:enhancement
2+
notebooks: promoted `nicType` and `reservationAffinity` in `google_notebooks_instance` to GA
3+
```
4+
```release-note:enhancement
5+
notebooks: added `bootDiskType` support for `PD_EXTREME` in `google_notebooks_instance`
6+
```
7+
```release-note:enhancement
8+
notebooks: added `softwareConfig.upgradeable, `softwareConfig.postStartupScriptBehavior`, `softwareConfig.kernels` in `google_notebooks_runtime`
9+
```

google-beta/resource_notebooks_instance.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ If not specified, this defaults to 100.`,
117117
Type: schema.TypeString,
118118
Optional: true,
119119
ForceNew: true,
120-
ValidateFunc: validateEnum([]string{"DISK_TYPE_UNSPECIFIED", "PD_STANDARD", "PD_SSD", "PD_BALANCED", ""}),
121-
Description: `Possible disk types for notebook instances. Possible values: ["DISK_TYPE_UNSPECIFIED", "PD_STANDARD", "PD_SSD", "PD_BALANCED"]`,
120+
ValidateFunc: validateEnum([]string{"DISK_TYPE_UNSPECIFIED", "PD_STANDARD", "PD_SSD", "PD_BALANCED", "PD_EXTREME", ""}),
121+
Description: `Possible disk types for notebook instances. Possible values: ["DISK_TYPE_UNSPECIFIED", "PD_STANDARD", "PD_SSD", "PD_BALANCED", "PD_EXTREME"]`,
122122
},
123123
"container_image": {
124124
Type: schema.TypeList,
@@ -165,9 +165,9 @@ If not specified, this defaults to 100.`,
165165
Type: schema.TypeString,
166166
Optional: true,
167167
ForceNew: true,
168-
ValidateFunc: validateEnum([]string{"DISK_TYPE_UNSPECIFIED", "PD_STANDARD", "PD_SSD", "PD_BALANCED", ""}),
168+
ValidateFunc: validateEnum([]string{"DISK_TYPE_UNSPECIFIED", "PD_STANDARD", "PD_SSD", "PD_BALANCED", "PD_EXTREME", ""}),
169169
DiffSuppressFunc: emptyOrDefaultStringSuppress("DISK_TYPE_UNSPECIFIED"),
170-
Description: `Possible disk types for notebook instances. Possible values: ["DISK_TYPE_UNSPECIFIED", "PD_STANDARD", "PD_SSD", "PD_BALANCED"]`,
170+
Description: `Possible disk types for notebook instances. Possible values: ["DISK_TYPE_UNSPECIFIED", "PD_STANDARD", "PD_SSD", "PD_BALANCED", "PD_EXTREME"]`,
171171
},
172172
"disk_encryption": {
173173
Type: schema.TypeString,

google-beta/resource_notebooks_runtime.go

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,26 @@ Default: 180 minutes`,
143143
Optional: true,
144144
Description: `Install Nvidia Driver automatically.`,
145145
},
146+
"kernels": {
147+
Type: schema.TypeList,
148+
Optional: true,
149+
Description: `Use a list of container images to use as Kernels in the notebook instance.`,
150+
Elem: &schema.Resource{
151+
Schema: map[string]*schema.Schema{
152+
"repository": {
153+
Type: schema.TypeString,
154+
Required: true,
155+
Description: `The path to the container image repository.
156+
For example: gcr.io/{project_id}/{imageName}`,
157+
},
158+
"tag": {
159+
Type: schema.TypeString,
160+
Optional: true,
161+
Description: `The tag of the container image. If not specified, this defaults to the latest tag.`,
162+
},
163+
},
164+
},
165+
},
146166
"notebook_upgrade_schedule": {
147167
Type: schema.TypeString,
148168
Optional: true,
@@ -156,6 +176,17 @@ Please follow the [cron format](https://en.wikipedia.org/wiki/Cron).`,
156176
fully boots up. The path must be a URL or
157177
Cloud Storage path (gs://path-to-file/file-name).`,
158178
},
179+
"post_startup_script_behavior": {
180+
Type: schema.TypeString,
181+
Optional: true,
182+
ValidateFunc: validateEnum([]string{"POST_STARTUP_SCRIPT_BEHAVIOR_UNSPECIFIED", "RUN_EVERY_START", "DOWNLOAD_AND_RUN_EVERY_START", ""}),
183+
Description: `Behavior for the post startup script. Possible values: ["POST_STARTUP_SCRIPT_BEHAVIOR_UNSPECIFIED", "RUN_EVERY_START", "DOWNLOAD_AND_RUN_EVERY_START"]`,
184+
},
185+
"upgradeable": {
186+
Type: schema.TypeBool,
187+
Computed: true,
188+
Description: `Bool indicating whether an newer image is available in an image family.`,
189+
},
159190
},
160191
},
161192
},
@@ -1305,10 +1336,16 @@ func flattenNotebooksRuntimeSoftwareConfig(v interface{}, d *schema.ResourceData
13051336
flattenNotebooksRuntimeSoftwareConfigIdleShutdownTimeout(original["idleShutdownTimeout"], d, config)
13061337
transformed["install_gpu_driver"] =
13071338
flattenNotebooksRuntimeSoftwareConfigInstallGpuDriver(original["installGpuDriver"], d, config)
1339+
transformed["upgradeable"] =
1340+
flattenNotebooksRuntimeSoftwareConfigUpgradeable(original["upgradeable"], d, config)
13081341
transformed["custom_gpu_driver_path"] =
13091342
flattenNotebooksRuntimeSoftwareConfigCustomGpuDriverPath(original["customGpuDriverPath"], d, config)
13101343
transformed["post_startup_script"] =
13111344
flattenNotebooksRuntimeSoftwareConfigPostStartupScript(original["postStartupScript"], d, config)
1345+
transformed["post_startup_script_behavior"] =
1346+
flattenNotebooksRuntimeSoftwareConfigPostStartupScriptBehavior(original["postStartupScriptBehavior"], d, config)
1347+
transformed["kernels"] =
1348+
flattenNotebooksRuntimeSoftwareConfigKernels(original["kernels"], d, config)
13121349
return []interface{}{transformed}
13131350
}
13141351
func flattenNotebooksRuntimeSoftwareConfigNotebookUpgradeSchedule(v interface{}, d *schema.ResourceData, config *Config) interface{} {
@@ -1344,6 +1381,10 @@ func flattenNotebooksRuntimeSoftwareConfigInstallGpuDriver(v interface{}, d *sch
13441381
return v
13451382
}
13461383

1384+
func flattenNotebooksRuntimeSoftwareConfigUpgradeable(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1385+
return v
1386+
}
1387+
13471388
func flattenNotebooksRuntimeSoftwareConfigCustomGpuDriverPath(v interface{}, d *schema.ResourceData, config *Config) interface{} {
13481389
return v
13491390
}
@@ -1352,6 +1393,37 @@ func flattenNotebooksRuntimeSoftwareConfigPostStartupScript(v interface{}, d *sc
13521393
return v
13531394
}
13541395

1396+
func flattenNotebooksRuntimeSoftwareConfigPostStartupScriptBehavior(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1397+
return v
1398+
}
1399+
1400+
func flattenNotebooksRuntimeSoftwareConfigKernels(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1401+
if v == nil {
1402+
return v
1403+
}
1404+
l := v.([]interface{})
1405+
transformed := make([]interface{}, 0, len(l))
1406+
for _, raw := range l {
1407+
original := raw.(map[string]interface{})
1408+
if len(original) < 1 {
1409+
// Do not include empty json objects coming back from the api
1410+
continue
1411+
}
1412+
transformed = append(transformed, map[string]interface{}{
1413+
"repository": flattenNotebooksRuntimeSoftwareConfigKernelsRepository(original["repository"], d, config),
1414+
"tag": flattenNotebooksRuntimeSoftwareConfigKernelsTag(original["tag"], d, config),
1415+
})
1416+
}
1417+
return transformed
1418+
}
1419+
func flattenNotebooksRuntimeSoftwareConfigKernelsRepository(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1420+
return v
1421+
}
1422+
1423+
func flattenNotebooksRuntimeSoftwareConfigKernelsTag(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1424+
return v
1425+
}
1426+
13551427
func flattenNotebooksRuntimeMetrics(v interface{}, d *schema.ResourceData, config *Config) interface{} {
13561428
if v == nil {
13571429
return nil
@@ -2041,6 +2113,13 @@ func expandNotebooksRuntimeSoftwareConfig(v interface{}, d TerraformResourceData
20412113
transformed["installGpuDriver"] = transformedInstallGpuDriver
20422114
}
20432115

2116+
transformedUpgradeable, err := expandNotebooksRuntimeSoftwareConfigUpgradeable(original["upgradeable"], d, config)
2117+
if err != nil {
2118+
return nil, err
2119+
} else if val := reflect.ValueOf(transformedUpgradeable); val.IsValid() && !isEmptyValue(val) {
2120+
transformed["upgradeable"] = transformedUpgradeable
2121+
}
2122+
20442123
transformedCustomGpuDriverPath, err := expandNotebooksRuntimeSoftwareConfigCustomGpuDriverPath(original["custom_gpu_driver_path"], d, config)
20452124
if err != nil {
20462125
return nil, err
@@ -2055,6 +2134,20 @@ func expandNotebooksRuntimeSoftwareConfig(v interface{}, d TerraformResourceData
20552134
transformed["postStartupScript"] = transformedPostStartupScript
20562135
}
20572136

2137+
transformedPostStartupScriptBehavior, err := expandNotebooksRuntimeSoftwareConfigPostStartupScriptBehavior(original["post_startup_script_behavior"], d, config)
2138+
if err != nil {
2139+
return nil, err
2140+
} else if val := reflect.ValueOf(transformedPostStartupScriptBehavior); val.IsValid() && !isEmptyValue(val) {
2141+
transformed["postStartupScriptBehavior"] = transformedPostStartupScriptBehavior
2142+
}
2143+
2144+
transformedKernels, err := expandNotebooksRuntimeSoftwareConfigKernels(original["kernels"], d, config)
2145+
if err != nil {
2146+
return nil, err
2147+
} else if val := reflect.ValueOf(transformedKernels); val.IsValid() && !isEmptyValue(val) {
2148+
transformed["kernels"] = transformedKernels
2149+
}
2150+
20582151
return transformed, nil
20592152
}
20602153

@@ -2078,10 +2171,55 @@ func expandNotebooksRuntimeSoftwareConfigInstallGpuDriver(v interface{}, d Terra
20782171
return v, nil
20792172
}
20802173

2174+
func expandNotebooksRuntimeSoftwareConfigUpgradeable(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
2175+
return v, nil
2176+
}
2177+
20812178
func expandNotebooksRuntimeSoftwareConfigCustomGpuDriverPath(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
20822179
return v, nil
20832180
}
20842181

20852182
func expandNotebooksRuntimeSoftwareConfigPostStartupScript(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
20862183
return v, nil
20872184
}
2185+
2186+
func expandNotebooksRuntimeSoftwareConfigPostStartupScriptBehavior(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
2187+
return v, nil
2188+
}
2189+
2190+
func expandNotebooksRuntimeSoftwareConfigKernels(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
2191+
l := v.([]interface{})
2192+
req := make([]interface{}, 0, len(l))
2193+
for _, raw := range l {
2194+
if raw == nil {
2195+
continue
2196+
}
2197+
original := raw.(map[string]interface{})
2198+
transformed := make(map[string]interface{})
2199+
2200+
transformedRepository, err := expandNotebooksRuntimeSoftwareConfigKernelsRepository(original["repository"], d, config)
2201+
if err != nil {
2202+
return nil, err
2203+
} else if val := reflect.ValueOf(transformedRepository); val.IsValid() && !isEmptyValue(val) {
2204+
transformed["repository"] = transformedRepository
2205+
}
2206+
2207+
transformedTag, err := expandNotebooksRuntimeSoftwareConfigKernelsTag(original["tag"], d, config)
2208+
if err != nil {
2209+
return nil, err
2210+
} else if val := reflect.ValueOf(transformedTag); val.IsValid() && !isEmptyValue(val) {
2211+
transformed["tag"] = transformedTag
2212+
}
2213+
2214+
req = append(req, transformed)
2215+
}
2216+
return req, nil
2217+
}
2218+
2219+
func expandNotebooksRuntimeSoftwareConfigKernelsRepository(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
2220+
return v, nil
2221+
}
2222+
2223+
func expandNotebooksRuntimeSoftwareConfigKernelsTag(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
2224+
return v, nil
2225+
}

google-beta/resource_notebooks_runtime_generated_test.go

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,113 @@ resource "google_notebooks_runtime" "runtime_container" {
185185
`, context)
186186
}
187187

188+
func TestAccNotebooksRuntime_notebookRuntimeKernelsExample(t *testing.T) {
189+
t.Parallel()
190+
191+
context := map[string]interface{}{
192+
"random_suffix": randString(t, 10),
193+
}
194+
195+
vcrTest(t, resource.TestCase{
196+
PreCheck: func() { testAccPreCheck(t) },
197+
Providers: testAccProviders,
198+
CheckDestroy: testAccCheckNotebooksRuntimeDestroyProducer(t),
199+
Steps: []resource.TestStep{
200+
{
201+
Config: testAccNotebooksRuntime_notebookRuntimeKernelsExample(context),
202+
},
203+
{
204+
ResourceName: "google_notebooks_runtime.runtime_container",
205+
ImportState: true,
206+
ImportStateVerify: true,
207+
ImportStateVerifyIgnore: []string{"name", "location"},
208+
},
209+
},
210+
})
211+
}
212+
213+
func testAccNotebooksRuntime_notebookRuntimeKernelsExample(context map[string]interface{}) string {
214+
return Nprintf(`
215+
resource "google_notebooks_runtime" "runtime_container" {
216+
name = "tf-test-notebooks-runtime-kernel%{random_suffix}"
217+
location = "us-central1"
218+
access_config {
219+
access_type = "SINGLE_USER"
220+
runtime_owner = "[email protected]"
221+
}
222+
software_config {
223+
kernels {
224+
repository = "gcr.io/deeplearning-platform-release/base-cpu"
225+
tag = "latest"
226+
}
227+
}
228+
virtual_machine {
229+
virtual_machine_config {
230+
machine_type = "n1-standard-4"
231+
data_disk {
232+
initialize_params {
233+
disk_size_gb = "100"
234+
disk_type = "PD_STANDARD"
235+
}
236+
}
237+
}
238+
}
239+
}
240+
`, context)
241+
}
242+
243+
func TestAccNotebooksRuntime_notebookRuntimeScriptExample(t *testing.T) {
244+
t.Parallel()
245+
246+
context := map[string]interface{}{
247+
"random_suffix": randString(t, 10),
248+
}
249+
250+
vcrTest(t, resource.TestCase{
251+
PreCheck: func() { testAccPreCheck(t) },
252+
Providers: testAccProviders,
253+
CheckDestroy: testAccCheckNotebooksRuntimeDestroyProducer(t),
254+
Steps: []resource.TestStep{
255+
{
256+
Config: testAccNotebooksRuntime_notebookRuntimeScriptExample(context),
257+
},
258+
{
259+
ResourceName: "google_notebooks_runtime.runtime_container",
260+
ImportState: true,
261+
ImportStateVerify: true,
262+
ImportStateVerifyIgnore: []string{"name", "location"},
263+
},
264+
},
265+
})
266+
}
267+
268+
func testAccNotebooksRuntime_notebookRuntimeScriptExample(context map[string]interface{}) string {
269+
return Nprintf(`
270+
resource "google_notebooks_runtime" "runtime_container" {
271+
name = "tf-test-notebooks-runtime-script%{random_suffix}"
272+
location = "us-central1"
273+
access_config {
274+
access_type = "SINGLE_USER"
275+
runtime_owner = "[email protected]"
276+
}
277+
software_config {
278+
post_startup_script_behavior = "RUN_EVERY_START"
279+
}
280+
virtual_machine {
281+
virtual_machine_config {
282+
machine_type = "n1-standard-4"
283+
data_disk {
284+
initialize_params {
285+
disk_size_gb = "100"
286+
disk_type = "PD_STANDARD"
287+
}
288+
}
289+
}
290+
}
291+
}
292+
`, context)
293+
}
294+
188295
func testAccCheckNotebooksRuntimeDestroyProducer(t *testing.T) func(s *terraform.State) error {
189296
return func(s *terraform.State) error {
190297
for name, rs := range s.RootModule().Resources {

website/docs/r/notebooks_instance.html.markdown

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,12 @@ The following arguments are supported:
211211
Structure is [documented below](#nested_shielded_instance_config).
212212

213213
* `nic_type` -
214-
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
214+
(Optional)
215215
The type of vNIC driver.
216216
Possible values are `UNSPECIFIED_NIC_TYPE`, `VIRTIO_NET`, and `GVNIC`.
217217

218218
* `reservation_affinity` -
219-
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
219+
(Optional)
220220
Reservation Affinity for consuming Zonal reservation.
221221
Structure is [documented below](#nested_reservation_affinity).
222222

@@ -234,7 +234,7 @@ The following arguments are supported:
234234
* `boot_disk_type` -
235235
(Optional)
236236
Possible disk types for notebook instances.
237-
Possible values are `DISK_TYPE_UNSPECIFIED`, `PD_STANDARD`, `PD_SSD`, and `PD_BALANCED`.
237+
Possible values are `DISK_TYPE_UNSPECIFIED`, `PD_STANDARD`, `PD_SSD`, `PD_BALANCED`, and `PD_EXTREME`.
238238

239239
* `boot_disk_size_gb` -
240240
(Optional)
@@ -245,7 +245,7 @@ The following arguments are supported:
245245
* `data_disk_type` -
246246
(Optional)
247247
Possible disk types for notebook instances.
248-
Possible values are `DISK_TYPE_UNSPECIFIED`, `PD_STANDARD`, `PD_SSD`, and `PD_BALANCED`.
248+
Possible values are `DISK_TYPE_UNSPECIFIED`, `PD_STANDARD`, `PD_SSD`, `PD_BALANCED`, and `PD_EXTREME`.
249249

250250
* `data_disk_size_gb` -
251251
(Optional)

0 commit comments

Comments
 (0)