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

notebooks - add args + promote some args to GA #4530

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changelog/6243.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
```release-note:enhancement
notebooks: promoted `nicType` and `reservationAffinity` in `google_notebooks_instance` to GA
```
```release-note:enhancement
notebooks: added `bootDiskType` support for `PD_EXTREME` in `google_notebooks_instance`
```
```release-note:enhancement
notebooks: added `softwareConfig.upgradeable, `softwareConfig.postStartupScriptBehavior`, `softwareConfig.kernels` in `google_notebooks_runtime`
```
8 changes: 4 additions & 4 deletions google-beta/resource_notebooks_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ If not specified, this defaults to 100.`,
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validateEnum([]string{"DISK_TYPE_UNSPECIFIED", "PD_STANDARD", "PD_SSD", "PD_BALANCED", ""}),
Description: `Possible disk types for notebook instances. Possible values: ["DISK_TYPE_UNSPECIFIED", "PD_STANDARD", "PD_SSD", "PD_BALANCED"]`,
ValidateFunc: validateEnum([]string{"DISK_TYPE_UNSPECIFIED", "PD_STANDARD", "PD_SSD", "PD_BALANCED", "PD_EXTREME", ""}),
Description: `Possible disk types for notebook instances. Possible values: ["DISK_TYPE_UNSPECIFIED", "PD_STANDARD", "PD_SSD", "PD_BALANCED", "PD_EXTREME"]`,
},
"container_image": {
Type: schema.TypeList,
Expand Down Expand Up @@ -165,9 +165,9 @@ If not specified, this defaults to 100.`,
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validateEnum([]string{"DISK_TYPE_UNSPECIFIED", "PD_STANDARD", "PD_SSD", "PD_BALANCED", ""}),
ValidateFunc: validateEnum([]string{"DISK_TYPE_UNSPECIFIED", "PD_STANDARD", "PD_SSD", "PD_BALANCED", "PD_EXTREME", ""}),
DiffSuppressFunc: emptyOrDefaultStringSuppress("DISK_TYPE_UNSPECIFIED"),
Description: `Possible disk types for notebook instances. Possible values: ["DISK_TYPE_UNSPECIFIED", "PD_STANDARD", "PD_SSD", "PD_BALANCED"]`,
Description: `Possible disk types for notebook instances. Possible values: ["DISK_TYPE_UNSPECIFIED", "PD_STANDARD", "PD_SSD", "PD_BALANCED", "PD_EXTREME"]`,
},
"disk_encryption": {
Type: schema.TypeString,
Expand Down
138 changes: 138 additions & 0 deletions google-beta/resource_notebooks_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,26 @@ Default: 180 minutes`,
Optional: true,
Description: `Install Nvidia Driver automatically.`,
},
"kernels": {
Type: schema.TypeList,
Optional: true,
Description: `Use a list of container images to use as Kernels in the notebook instance.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"repository": {
Type: schema.TypeString,
Required: true,
Description: `The path to the container image repository.
For example: gcr.io/{project_id}/{imageName}`,
},
"tag": {
Type: schema.TypeString,
Optional: true,
Description: `The tag of the container image. If not specified, this defaults to the latest tag.`,
},
},
},
},
"notebook_upgrade_schedule": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -156,6 +176,17 @@ Please follow the [cron format](https://en.wikipedia.org/wiki/Cron).`,
fully boots up. The path must be a URL or
Cloud Storage path (gs://path-to-file/file-name).`,
},
"post_startup_script_behavior": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateEnum([]string{"POST_STARTUP_SCRIPT_BEHAVIOR_UNSPECIFIED", "RUN_EVERY_START", "DOWNLOAD_AND_RUN_EVERY_START", ""}),
Description: `Behavior for the post startup script. Possible values: ["POST_STARTUP_SCRIPT_BEHAVIOR_UNSPECIFIED", "RUN_EVERY_START", "DOWNLOAD_AND_RUN_EVERY_START"]`,
},
"upgradeable": {
Type: schema.TypeBool,
Computed: true,
Description: `Bool indicating whether an newer image is available in an image family.`,
},
},
},
},
Expand Down Expand Up @@ -1305,10 +1336,16 @@ func flattenNotebooksRuntimeSoftwareConfig(v interface{}, d *schema.ResourceData
flattenNotebooksRuntimeSoftwareConfigIdleShutdownTimeout(original["idleShutdownTimeout"], d, config)
transformed["install_gpu_driver"] =
flattenNotebooksRuntimeSoftwareConfigInstallGpuDriver(original["installGpuDriver"], d, config)
transformed["upgradeable"] =
flattenNotebooksRuntimeSoftwareConfigUpgradeable(original["upgradeable"], d, config)
transformed["custom_gpu_driver_path"] =
flattenNotebooksRuntimeSoftwareConfigCustomGpuDriverPath(original["customGpuDriverPath"], d, config)
transformed["post_startup_script"] =
flattenNotebooksRuntimeSoftwareConfigPostStartupScript(original["postStartupScript"], d, config)
transformed["post_startup_script_behavior"] =
flattenNotebooksRuntimeSoftwareConfigPostStartupScriptBehavior(original["postStartupScriptBehavior"], d, config)
transformed["kernels"] =
flattenNotebooksRuntimeSoftwareConfigKernels(original["kernels"], d, config)
return []interface{}{transformed}
}
func flattenNotebooksRuntimeSoftwareConfigNotebookUpgradeSchedule(v interface{}, d *schema.ResourceData, config *Config) interface{} {
Expand Down Expand Up @@ -1344,6 +1381,10 @@ func flattenNotebooksRuntimeSoftwareConfigInstallGpuDriver(v interface{}, d *sch
return v
}

func flattenNotebooksRuntimeSoftwareConfigUpgradeable(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenNotebooksRuntimeSoftwareConfigCustomGpuDriverPath(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}
Expand All @@ -1352,6 +1393,37 @@ func flattenNotebooksRuntimeSoftwareConfigPostStartupScript(v interface{}, d *sc
return v
}

func flattenNotebooksRuntimeSoftwareConfigPostStartupScriptBehavior(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenNotebooksRuntimeSoftwareConfigKernels(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return v
}
l := v.([]interface{})
transformed := make([]interface{}, 0, len(l))
for _, raw := range l {
original := raw.(map[string]interface{})
if len(original) < 1 {
// Do not include empty json objects coming back from the api
continue
}
transformed = append(transformed, map[string]interface{}{
"repository": flattenNotebooksRuntimeSoftwareConfigKernelsRepository(original["repository"], d, config),
"tag": flattenNotebooksRuntimeSoftwareConfigKernelsTag(original["tag"], d, config),
})
}
return transformed
}
func flattenNotebooksRuntimeSoftwareConfigKernelsRepository(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenNotebooksRuntimeSoftwareConfigKernelsTag(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenNotebooksRuntimeMetrics(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -2041,6 +2113,13 @@ func expandNotebooksRuntimeSoftwareConfig(v interface{}, d TerraformResourceData
transformed["installGpuDriver"] = transformedInstallGpuDriver
}

transformedUpgradeable, err := expandNotebooksRuntimeSoftwareConfigUpgradeable(original["upgradeable"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedUpgradeable); val.IsValid() && !isEmptyValue(val) {
transformed["upgradeable"] = transformedUpgradeable
}

transformedCustomGpuDriverPath, err := expandNotebooksRuntimeSoftwareConfigCustomGpuDriverPath(original["custom_gpu_driver_path"], d, config)
if err != nil {
return nil, err
Expand All @@ -2055,6 +2134,20 @@ func expandNotebooksRuntimeSoftwareConfig(v interface{}, d TerraformResourceData
transformed["postStartupScript"] = transformedPostStartupScript
}

transformedPostStartupScriptBehavior, err := expandNotebooksRuntimeSoftwareConfigPostStartupScriptBehavior(original["post_startup_script_behavior"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedPostStartupScriptBehavior); val.IsValid() && !isEmptyValue(val) {
transformed["postStartupScriptBehavior"] = transformedPostStartupScriptBehavior
}

transformedKernels, err := expandNotebooksRuntimeSoftwareConfigKernels(original["kernels"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedKernels); val.IsValid() && !isEmptyValue(val) {
transformed["kernels"] = transformedKernels
}

return transformed, nil
}

Expand All @@ -2078,10 +2171,55 @@ func expandNotebooksRuntimeSoftwareConfigInstallGpuDriver(v interface{}, d Terra
return v, nil
}

func expandNotebooksRuntimeSoftwareConfigUpgradeable(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandNotebooksRuntimeSoftwareConfigCustomGpuDriverPath(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandNotebooksRuntimeSoftwareConfigPostStartupScript(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandNotebooksRuntimeSoftwareConfigPostStartupScriptBehavior(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandNotebooksRuntimeSoftwareConfigKernels(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
req := make([]interface{}, 0, len(l))
for _, raw := range l {
if raw == nil {
continue
}
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedRepository, err := expandNotebooksRuntimeSoftwareConfigKernelsRepository(original["repository"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedRepository); val.IsValid() && !isEmptyValue(val) {
transformed["repository"] = transformedRepository
}

transformedTag, err := expandNotebooksRuntimeSoftwareConfigKernelsTag(original["tag"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedTag); val.IsValid() && !isEmptyValue(val) {
transformed["tag"] = transformedTag
}

req = append(req, transformed)
}
return req, nil
}

func expandNotebooksRuntimeSoftwareConfigKernelsRepository(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandNotebooksRuntimeSoftwareConfigKernelsTag(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}
107 changes: 107 additions & 0 deletions google-beta/resource_notebooks_runtime_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,113 @@ resource "google_notebooks_runtime" "runtime_container" {
`, context)
}

func TestAccNotebooksRuntime_notebookRuntimeKernelsExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": randString(t, 10),
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNotebooksRuntimeDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccNotebooksRuntime_notebookRuntimeKernelsExample(context),
},
{
ResourceName: "google_notebooks_runtime.runtime_container",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"name", "location"},
},
},
})
}

func testAccNotebooksRuntime_notebookRuntimeKernelsExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_notebooks_runtime" "runtime_container" {
name = "tf-test-notebooks-runtime-kernel%{random_suffix}"
location = "us-central1"
access_config {
access_type = "SINGLE_USER"
runtime_owner = "[email protected]"
}
software_config {
kernels {
repository = "gcr.io/deeplearning-platform-release/base-cpu"
tag = "latest"
}
}
virtual_machine {
virtual_machine_config {
machine_type = "n1-standard-4"
data_disk {
initialize_params {
disk_size_gb = "100"
disk_type = "PD_STANDARD"
}
}
}
}
}
`, context)
}

func TestAccNotebooksRuntime_notebookRuntimeScriptExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": randString(t, 10),
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNotebooksRuntimeDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccNotebooksRuntime_notebookRuntimeScriptExample(context),
},
{
ResourceName: "google_notebooks_runtime.runtime_container",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"name", "location"},
},
},
})
}

func testAccNotebooksRuntime_notebookRuntimeScriptExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_notebooks_runtime" "runtime_container" {
name = "tf-test-notebooks-runtime-script%{random_suffix}"
location = "us-central1"
access_config {
access_type = "SINGLE_USER"
runtime_owner = "[email protected]"
}
software_config {
post_startup_script_behavior = "RUN_EVERY_START"
}
virtual_machine {
virtual_machine_config {
machine_type = "n1-standard-4"
data_disk {
initialize_params {
disk_size_gb = "100"
disk_type = "PD_STANDARD"
}
}
}
}
}
`, context)
}

func testAccCheckNotebooksRuntimeDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
8 changes: 4 additions & 4 deletions website/docs/r/notebooks_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ The following arguments are supported:
Structure is [documented below](#nested_shielded_instance_config).

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

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

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

* `boot_disk_size_gb` -
(Optional)
Expand All @@ -245,7 +245,7 @@ The following arguments are supported:
* `data_disk_type` -
(Optional)
Possible disk types for notebook instances.
Possible values are `DISK_TYPE_UNSPECIFIED`, `PD_STANDARD`, `PD_SSD`, and `PD_BALANCED`.
Possible values are `DISK_TYPE_UNSPECIFIED`, `PD_STANDARD`, `PD_SSD`, `PD_BALANCED`, and `PD_EXTREME`.

* `data_disk_size_gb` -
(Optional)
Expand Down
Loading