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

Runtime patch #12113

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
6 changes: 6 additions & 0 deletions .changelog/6137.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```release-note:enhancement
notebooks: added field `reserved_ip_range` to `google_notebooks_runtime`
```
```release-note:bug
notebooks: fixed a bug where`google_notebooks_runtime` can't be updated
```
57 changes: 55 additions & 2 deletions google/resource_notebooks_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func resourceNotebooksRuntime() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `The name specified for the Notebook instance.`,
Description: `The name specified for the Notebook runtime.`,
},
"access_config": {
Type: schema.TypeList,
Expand Down Expand Up @@ -357,6 +357,7 @@ rest/v1/projects.locations.runtimes#AcceleratorType'`,
Type: schema.TypeList,
Computed: true,
Optional: true,
ForceNew: true,
Description: `Use a list of container images to start the notebook instance.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand All @@ -377,6 +378,7 @@ For example: gcr.io/{project_id}/{imageName}`,
"encryption_config": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `Encryption settings for virtual machine data disk.`,
MaxItems: 1,
Elem: &schema.Resource{
Expand All @@ -396,6 +398,7 @@ It has the following format:
"internal_ip_only": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
Description: `If true, runtime will only have internal IP addresses. By default,
runtimes are not restricted to internal IP addresses, and will
have ephemeral external IP addresses assigned to each vm. This
Expand Down Expand Up @@ -429,6 +432,7 @@ _metadata)).`,
"network": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `The Compute Engine network to be used for machine communications.
Cannot be specified with subnetwork. If neither 'network' nor
'subnet' is specified, the "default" network of the project is
Expand All @@ -447,13 +451,22 @@ Runtimes support the following network configurations:
"nic_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validateEnum([]string{"UNSPECIFIED_NIC_TYPE", "VIRTIO_NET", "GVNIC", ""}),
Description: `The type of vNIC to be used on this interface. This may be gVNIC
or VirtioNet. Possible values: ["UNSPECIFIED_NIC_TYPE", "VIRTIO_NET", "GVNIC"]`,
},
"reserved_ip_range": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `Reserved IP Range name is used for VPC Peering. The
subnetwork allocation will use the range *name* if it's assigned.`,
},
"shielded_instance_config": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `Shielded VM Instance configuration settings.`,
MaxItems: 1,
Elem: &schema.Resource{
Expand Down Expand Up @@ -489,6 +502,7 @@ default.`,
"subnet": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `The Compute Engine subnetwork to be used for machine
communications. Cannot be specified with network. A full URL or
partial URI are valid. Examples:
Expand Down Expand Up @@ -756,13 +770,35 @@ func resourceNotebooksRuntimeUpdate(d *schema.ResourceData, meta interface{}) er
}

log.Printf("[DEBUG] Updating Runtime %q: %#v", d.Id(), obj)
updateMask := []string{}

if d.HasChange("virtual_machine") {
updateMask = append(updateMask, "virtualMachine")
}

if d.HasChange("access_config") {
updateMask = append(updateMask, "accessConfig")
}

if d.HasChange("software_config") {
updateMask = append(updateMask, "softwareConfig.idleShutdown",
"softwareConfig.idleShutdownTimeout",
"softwareConfig.customGpuDriverPath",
"softwareConfig.postStartupScript")
}
// updateMask is a URL parameter but not present in the schema, so replaceVars
// won't set it
url, err = addQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
if err != nil {
return err
}

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

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

if err != nil {
return fmt.Errorf("Error updating Runtime %q: %s", d.Id(), err)
Expand Down Expand Up @@ -910,6 +946,8 @@ func flattenNotebooksRuntimeVirtualMachineVirtualMachineConfig(v interface{}, d
flattenNotebooksRuntimeVirtualMachineVirtualMachineConfigLabels(original["labels"], d, config)
transformed["nic_type"] =
flattenNotebooksRuntimeVirtualMachineVirtualMachineConfigNicType(original["nicType"], d, config)
transformed["reserved_ip_range"] =
flattenNotebooksRuntimeVirtualMachineVirtualMachineConfigReservedIpRange(original["reservedIpRange"], d, config)
return []interface{}{transformed}
}
func flattenNotebooksRuntimeVirtualMachineVirtualMachineConfigZone(v interface{}, d *schema.ResourceData, config *Config) interface{} {
Expand Down Expand Up @@ -1207,6 +1245,10 @@ func flattenNotebooksRuntimeVirtualMachineVirtualMachineConfigNicType(v interfac
return v
}

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

func flattenNotebooksRuntimeState(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}
Expand Down Expand Up @@ -1482,6 +1524,13 @@ func expandNotebooksRuntimeVirtualMachineVirtualMachineConfig(v interface{}, d T
transformed["nicType"] = transformedNicType
}

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

return transformed, nil
}

Expand Down Expand Up @@ -1899,6 +1948,10 @@ func expandNotebooksRuntimeVirtualMachineVirtualMachineConfigNicType(v interface
return v, nil
}

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

func expandNotebooksRuntimeAccessConfig(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down
99 changes: 99 additions & 0 deletions google/resource_notebooks_runtime_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package google

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccNotebooksRuntime_update(t *testing.T) {
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_basic(context),
},
{
ResourceName: "google_notebooks_runtime.runtime",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccNotebooksRuntime_update(context),
},
{
ResourceName: "google_notebooks_runtime.runtime",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccNotebooksRuntime_basic(context),
},
{
ResourceName: "google_notebooks_runtime.runtime",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

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

func testAccNotebooksRuntime_update(context map[string]interface{}) string {
return Nprintf(`
resource "google_notebooks_runtime" "runtime" {
name = "tf-test-notebooks-runtime%{random_suffix}"
location = "us-central1"
access_config {
access_type = "SINGLE_USER"
runtime_owner = "[email protected]"
}
software_config {
idle_shutdown_timeout = "80"
}
virtual_machine {
virtual_machine_config {
machine_type = "n1-standard-4"
data_disk {
initialize_params {
disk_size_gb = "100"
disk_type = "PD_STANDARD"
}
}
reserved_ip_range = "192.168.255.0/24"
}
}
}
`, context)
}
7 changes: 6 additions & 1 deletion website/docs/r/notebooks_runtime.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ The following arguments are supported:

* `name` -
(Required)
The name specified for the Notebook instance.
The name specified for the Notebook runtime.

* `location` -
(Required)
Expand Down Expand Up @@ -291,6 +291,11 @@ The following arguments are supported:
or VirtioNet.
Possible values are `UNSPECIFIED_NIC_TYPE`, `VIRTIO_NET`, and `GVNIC`.

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


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

Expand Down