| // Copyright (c) HashiCorp, Inc. |
| // SPDX-License-Identifier: MPL-2.0 |
| |
| // ---------------------------------------------------------------------------- |
| // |
| // *** AUTO GENERATED CODE *** Type: MMv1 *** |
| // |
| // ---------------------------------------------------------------------------- |
| // |
| // This file is automatically generated by Magic Modules and manual |
| // changes will be clobbered when the file is regenerated. |
| // |
| // Please read more about how to change this file in |
| // .github/CONTRIBUTING.md. |
| // |
| // ---------------------------------------------------------------------------- |
| |
| package notebooks |
| |
| import ( |
| "context" |
| "fmt" |
| "log" |
| "reflect" |
| "sort" |
| "strings" |
| "time" |
| |
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" |
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| |
| "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" |
| transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" |
| "github.com/hashicorp/terraform-provider-google-beta/google-beta/verify" |
| ) |
| |
| var NotebooksInstanceProvidedScopes = []string{ |
| "https://www.googleapis.com/auth/cloud-platform", |
| "https://www.googleapis.com/auth/userinfo.email", |
| } |
| |
| func NotebooksInstanceScopesDiffSuppress(_, _, _ string, d *schema.ResourceData) bool { |
| old, new := d.GetChange("service_account_scopes") |
| oldValue := old.([]interface{}) |
| newValue := new.([]interface{}) |
| oldValueList := []string{} |
| newValueList := []string{} |
| |
| for _, item := range oldValue { |
| oldValueList = append(oldValueList, item.(string)) |
| } |
| |
| for _, item := range newValue { |
| newValueList = append(newValueList, item.(string)) |
| } |
| newValueList = append(newValueList, NotebooksInstanceProvidedScopes...) |
| |
| sort.Strings(oldValueList) |
| sort.Strings(newValueList) |
| if reflect.DeepEqual(oldValueList, newValueList) { |
| return true |
| } |
| return false |
| } |
| |
| func NotebooksInstanceKmsDiffSuppress(_, old, new string, _ *schema.ResourceData) bool { |
| if strings.HasPrefix(old, new) { |
| return true |
| } |
| return false |
| } |
| |
| // waitForNotebooksInstanceActive waits for an Notebook instance to become "ACTIVE" |
| func waitForNotebooksInstanceActive(d *schema.ResourceData, config *transport_tpg.Config, timeout time.Duration) error { |
| return resource.Retry(timeout, func() *resource.RetryError { |
| if err := resourceNotebooksInstanceRead(d, config); err != nil { |
| return resource.NonRetryableError(err) |
| } |
| |
| name := d.Get("name").(string) |
| state := d.Get("state").(string) |
| if state == "ACTIVE" { |
| log.Printf("[DEBUG] Notebook Instance %q has state %q.", name, state) |
| return nil |
| } else { |
| return resource.RetryableError(fmt.Errorf("Notebook Instance %q has state %q. Waiting for ACTIVE state", name, state)) |
| } |
| |
| }) |
| } |
| |
| func modifyNotebooksInstanceState(config *transport_tpg.Config, d *schema.ResourceData, project string, billingProject string, userAgent string, state string) (map[string]interface{}, error) { |
| url, err := tpgresource.ReplaceVars(d, config, "{{NotebooksBasePath}}projects/{{project}}/locations/{{location}}/instances/{{name}}:"+state) |
| if err != nil { |
| return nil, err |
| } |
| |
| res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ |
| Config: config, |
| Method: "POST", |
| Project: billingProject, |
| RawURL: url, |
| UserAgent: userAgent, |
| }) |
| if err != nil { |
| return nil, fmt.Errorf("Unable to %q google_notebooks_instance %q: %s", state, d.Id(), err) |
| } |
| return res, nil |
| } |
| |
| func waitForNotebooksOperation(config *transport_tpg.Config, d *schema.ResourceData, project string, billingProject string, userAgent string, response map[string]interface{}) error { |
| var opRes map[string]interface{} |
| err := NotebooksOperationWaitTimeWithResponse( |
| config, response, &opRes, project, "Modifying Notebook Instance state", userAgent, |
| d.Timeout(schema.TimeoutUpdate)) |
| if err != nil { |
| return err |
| } |
| return nil |
| } |
| |
| func ResourceNotebooksInstance() *schema.Resource { |
| return &schema.Resource{ |
| Create: resourceNotebooksInstanceCreate, |
| Read: resourceNotebooksInstanceRead, |
| Update: resourceNotebooksInstanceUpdate, |
| Delete: resourceNotebooksInstanceDelete, |
| |
| Importer: &schema.ResourceImporter{ |
| State: resourceNotebooksInstanceImport, |
| }, |
| |
| Timeouts: &schema.ResourceTimeout{ |
| Create: schema.DefaultTimeout(20 * time.Minute), |
| Update: schema.DefaultTimeout(20 * time.Minute), |
| Delete: schema.DefaultTimeout(20 * time.Minute), |
| }, |
| |
| SchemaVersion: 1, |
| |
| StateUpgraders: []schema.StateUpgrader{ |
| { |
| Type: resourceNotebooksInstanceResourceV0().CoreConfigSchema().ImpliedType(), |
| Upgrade: ResourceNotebooksInstanceUpgradeV0, |
| Version: 0, |
| }, |
| }, |
| CustomizeDiff: customdiff.All( |
| tpgresource.SetLabelsDiff, |
| tpgresource.DefaultProviderProject, |
| ), |
| |
| DeprecationMessage: "`google_notebook_instance` is deprecated and will be removed in a future major release. Use `google_workbench_instance` instead.", |
| |
| Schema: map[string]*schema.Schema{ |
| "location": { |
| Type: schema.TypeString, |
| Required: true, |
| ForceNew: true, |
| DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, |
| Description: `A reference to the zone where the machine resides.`, |
| }, |
| "machine_type": { |
| Type: schema.TypeString, |
| Required: true, |
| ForceNew: true, |
| DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, |
| Description: `A reference to a machine type which defines VM kind.`, |
| }, |
| "name": { |
| Type: schema.TypeString, |
| Required: true, |
| ForceNew: true, |
| Description: `The name specified for the Notebook instance.`, |
| }, |
| "accelerator_config": { |
| Type: schema.TypeList, |
| Optional: true, |
| ForceNew: true, |
| Description: `The hardware accelerator used on this instance. If you use accelerators, |
| make sure that your configuration has enough vCPUs and memory to support the |
| machineType you have selected.`, |
| MaxItems: 1, |
| Elem: &schema.Resource{ |
| Schema: map[string]*schema.Schema{ |
| "core_count": { |
| Type: schema.TypeInt, |
| Required: true, |
| ForceNew: true, |
| Description: `Count of cores of this accelerator.`, |
| }, |
| "type": { |
| Type: schema.TypeString, |
| Required: true, |
| ForceNew: true, |
| ValidateFunc: verify.ValidateEnum([]string{"ACCELERATOR_TYPE_UNSPECIFIED", "NVIDIA_TESLA_K80", "NVIDIA_TESLA_P100", "NVIDIA_TESLA_V100", "NVIDIA_TESLA_P4", "NVIDIA_TESLA_T4", "NVIDIA_TESLA_T4_VWS", "NVIDIA_TESLA_P100_VWS", "NVIDIA_TESLA_P4_VWS", "NVIDIA_TESLA_A100", "TPU_V2", "TPU_V3"}), |
| Description: `Type of this accelerator. Possible values: ["ACCELERATOR_TYPE_UNSPECIFIED", "NVIDIA_TESLA_K80", "NVIDIA_TESLA_P100", "NVIDIA_TESLA_V100", "NVIDIA_TESLA_P4", "NVIDIA_TESLA_T4", "NVIDIA_TESLA_T4_VWS", "NVIDIA_TESLA_P100_VWS", "NVIDIA_TESLA_P4_VWS", "NVIDIA_TESLA_A100", "TPU_V2", "TPU_V3"]`, |
| }, |
| }, |
| }, |
| }, |
| "boot_disk_size_gb": { |
| Type: schema.TypeInt, |
| Optional: true, |
| ForceNew: true, |
| Description: `The size of the boot disk in GB attached to this instance, |
| up to a maximum of 64000 GB (64 TB). The minimum recommended value is 100 GB. |
| If not specified, this defaults to 100.`, |
| }, |
| "boot_disk_type": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| ValidateFunc: verify.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, |
| Optional: true, |
| ForceNew: true, |
| Description: `Use a container image to start the notebook instance.`, |
| MaxItems: 1, |
| Elem: &schema.Resource{ |
| Schema: map[string]*schema.Schema{ |
| "repository": { |
| Type: schema.TypeString, |
| Required: true, |
| ForceNew: true, |
| Description: `The path to the container image repository. |
| For example: gcr.io/{project_id}/{imageName}`, |
| }, |
| "tag": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| Description: `The tag of the container image. If not specified, this defaults to the latest tag.`, |
| }, |
| }, |
| }, |
| ExactlyOneOf: []string{"vm_image", "container_image"}, |
| }, |
| "custom_gpu_driver_path": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| Description: `Specify a custom Cloud Storage path where the GPU driver is stored. |
| If not specified, we'll automatically choose from official GPU drivers.`, |
| }, |
| "data_disk_size_gb": { |
| Type: schema.TypeInt, |
| Optional: true, |
| ForceNew: true, |
| Description: `The size of the data disk in GB attached to this instance, |
| up to a maximum of 64000 GB (64 TB). |
| You can choose the size of the data disk based on how big your notebooks and data are. |
| If not specified, this defaults to 100.`, |
| }, |
| "data_disk_type": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| ValidateFunc: verify.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"]`, |
| }, |
| "disk_encryption": { |
| Type: schema.TypeString, |
| Computed: true, |
| Optional: true, |
| ForceNew: true, |
| ValidateFunc: verify.ValidateEnum([]string{"DISK_ENCRYPTION_UNSPECIFIED", "GMEK", "CMEK", ""}), |
| DiffSuppressFunc: tpgresource.EmptyOrDefaultStringSuppress("DISK_ENCRYPTION_UNSPECIFIED"), |
| Description: `Disk encryption method used on the boot and data disks, defaults to GMEK. Possible values: ["DISK_ENCRYPTION_UNSPECIFIED", "GMEK", "CMEK"]`, |
| }, |
| "install_gpu_driver": { |
| Type: schema.TypeBool, |
| Optional: true, |
| ForceNew: true, |
| Description: `Whether the end user authorizes Google Cloud to install GPU driver |
| on this instance. If this field is empty or set to false, the GPU driver |
| won't be installed. Only applicable to instances with GPUs.`, |
| }, |
| "instance_owners": { |
| Type: schema.TypeList, |
| Optional: true, |
| ForceNew: true, |
| Description: `The list of owners of this instance after creation. |
| Format: alias@example.com. |
| Currently supports one owner only. |
| If not specified, all of the service account users of |
| your VM instance's service account can use the instance.`, |
| Elem: &schema.Schema{ |
| Type: schema.TypeString, |
| }, |
| }, |
| "kms_key": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| DiffSuppressFunc: NotebooksInstanceKmsDiffSuppress, |
| Description: `The KMS key used to encrypt the disks, only applicable if diskEncryption is CMEK. |
| Format: projects/{project_id}/locations/{location}/keyRings/{key_ring_id}/cryptoKeys/{key_id}`, |
| }, |
| "labels": { |
| Type: schema.TypeMap, |
| Optional: true, |
| Description: `Labels to apply to this instance. These can be later modified by the setLabels method. |
| An object containing a list of "key": value pairs. Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }. |
| |
| |
| **Note**: This field is non-authoritative, and will only manage the labels present in your configuration. |
| Please refer to the field 'effective_labels' for all of the labels present on the resource.`, |
| Elem: &schema.Schema{Type: schema.TypeString}, |
| }, |
| "metadata": { |
| Type: schema.TypeMap, |
| Optional: true, |
| Description: `Custom metadata to apply to this instance. |
| An object containing a list of "key": value pairs. Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.`, |
| Elem: &schema.Schema{Type: schema.TypeString}, |
| }, |
| "network": { |
| Type: schema.TypeString, |
| Computed: true, |
| Optional: true, |
| ForceNew: true, |
| DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, |
| Description: `The name of the VPC that this instance is in. |
| Format: projects/{project_id}/global/networks/{network_id}`, |
| }, |
| "nic_type": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| ValidateFunc: verify.ValidateEnum([]string{"UNSPECIFIED_NIC_TYPE", "VIRTIO_NET", "GVNIC", ""}), |
| Description: `The type of vNIC driver. Possible values: ["UNSPECIFIED_NIC_TYPE", "VIRTIO_NET", "GVNIC"]`, |
| }, |
| "no_proxy_access": { |
| Type: schema.TypeBool, |
| Optional: true, |
| ForceNew: true, |
| Description: `The notebook instance will not register with the proxy..`, |
| }, |
| "no_public_ip": { |
| Type: schema.TypeBool, |
| Optional: true, |
| ForceNew: true, |
| Description: `No public IP will be assigned to this instance.`, |
| }, |
| "no_remove_data_disk": { |
| Type: schema.TypeBool, |
| Optional: true, |
| ForceNew: true, |
| Description: `If true, the data disk will not be auto deleted when deleting the instance.`, |
| }, |
| "post_startup_script": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| Description: `Path to a Bash script that automatically runs after a |
| notebook instance fully boots up. The path must be a URL |
| or Cloud Storage path (gs://path-to-file/file-name).`, |
| }, |
| "reservation_affinity": { |
| Type: schema.TypeList, |
| Optional: true, |
| ForceNew: true, |
| Description: `Reservation Affinity for consuming Zonal reservation.`, |
| MaxItems: 1, |
| Elem: &schema.Resource{ |
| Schema: map[string]*schema.Schema{ |
| "consume_reservation_type": { |
| Type: schema.TypeString, |
| Required: true, |
| ForceNew: true, |
| ValidateFunc: verify.ValidateEnum([]string{"NO_RESERVATION", "ANY_RESERVATION", "SPECIFIC_RESERVATION"}), |
| Description: `The type of Compute Reservation. Possible values: ["NO_RESERVATION", "ANY_RESERVATION", "SPECIFIC_RESERVATION"]`, |
| }, |
| "key": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| Description: `Corresponds to the label key of reservation resource.`, |
| }, |
| "values": { |
| Type: schema.TypeList, |
| Optional: true, |
| ForceNew: true, |
| Description: `Corresponds to the label values of reservation resource.`, |
| Elem: &schema.Schema{ |
| Type: schema.TypeString, |
| }, |
| }, |
| }, |
| }, |
| }, |
| "service_account": { |
| Type: schema.TypeString, |
| Computed: true, |
| Optional: true, |
| ForceNew: true, |
| Description: `The service account on this instance, giving access to other |
| Google Cloud services. You can use any service account within |
| the same project, but you must have the service account user |
| permission to use the instance. If not specified, |
| the Compute Engine default service account is used.`, |
| }, |
| "service_account_scopes": { |
| Type: schema.TypeList, |
| Computed: true, |
| Optional: true, |
| ForceNew: true, |
| DiffSuppressFunc: NotebooksInstanceScopesDiffSuppress, |
| Description: `Optional. The URIs of service account scopes to be included in Compute Engine instances. |
| If not specified, the following scopes are defined: |
| - https://www.googleapis.com/auth/cloud-platform |
| - https://www.googleapis.com/auth/userinfo.email`, |
| Elem: &schema.Schema{ |
| Type: schema.TypeString, |
| }, |
| }, |
| "shielded_instance_config": { |
| Type: schema.TypeList, |
| Computed: true, |
| Optional: true, |
| ForceNew: true, |
| Description: `A set of Shielded Instance options. Check [Images using supported Shielded VM features] |
| Not all combinations are valid`, |
| MaxItems: 1, |
| Elem: &schema.Resource{ |
| Schema: map[string]*schema.Schema{ |
| "enable_integrity_monitoring": { |
| Type: schema.TypeBool, |
| Optional: true, |
| ForceNew: true, |
| Description: `Defines whether the instance has integrity monitoring enabled. Enables monitoring and attestation of the |
| boot integrity of the instance. The attestation is performed against the integrity policy baseline. |
| This baseline is initially derived from the implicitly trusted boot image when the instance is created. |
| Enabled by default.`, |
| Default: true, |
| }, |
| "enable_secure_boot": { |
| Type: schema.TypeBool, |
| Optional: true, |
| ForceNew: true, |
| Description: `Defines whether the instance has Secure Boot enabled. Secure Boot helps ensure that the system only runs |
| authentic software by verifying the digital signature of all boot components, and halting the boot process |
| if signature verification fails. |
| Disabled by default.`, |
| }, |
| "enable_vtpm": { |
| Type: schema.TypeBool, |
| Optional: true, |
| ForceNew: true, |
| Description: `Defines whether the instance has the vTPM enabled. |
| Enabled by default.`, |
| Default: true, |
| }, |
| }, |
| }, |
| }, |
| "subnet": { |
| Type: schema.TypeString, |
| Computed: true, |
| Optional: true, |
| ForceNew: true, |
| DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, |
| Description: `The name of the subnet that this instance is in. |
| Format: projects/{project_id}/regions/{region}/subnetworks/{subnetwork_id}`, |
| }, |
| "tags": { |
| Type: schema.TypeList, |
| Computed: true, |
| Optional: true, |
| ForceNew: true, |
| Description: `The Compute Engine tags to add to instance.`, |
| Elem: &schema.Schema{ |
| Type: schema.TypeString, |
| }, |
| }, |
| "vm_image": { |
| Type: schema.TypeList, |
| Optional: true, |
| ForceNew: true, |
| Description: `Use a Compute Engine VM image to start the notebook instance.`, |
| MaxItems: 1, |
| Elem: &schema.Resource{ |
| Schema: map[string]*schema.Schema{ |
| "project": { |
| Type: schema.TypeString, |
| Required: true, |
| ForceNew: true, |
| Description: `The name of the Google Cloud project that this VM image belongs to. |
| Format: projects/{project_id}`, |
| }, |
| "image_family": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| Description: `Use this VM image family to find the image; the newest image in this family will be used.`, |
| }, |
| "image_name": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| Description: `Use VM image name to find the image.`, |
| }, |
| }, |
| }, |
| ExactlyOneOf: []string{"vm_image", "container_image"}, |
| }, |
| "create_time": { |
| Type: schema.TypeString, |
| Computed: true, |
| Optional: true, |
| Description: `Instance creation time`, |
| }, |
| "effective_labels": { |
| Type: schema.TypeMap, |
| Computed: true, |
| Description: `All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.`, |
| Elem: &schema.Schema{Type: schema.TypeString}, |
| }, |
| "proxy_uri": { |
| Type: schema.TypeString, |
| Computed: true, |
| Description: `The proxy endpoint that is used to access the Jupyter notebook. |
| Only returned when the resource is in a 'PROVISIONED' state. If |
| needed you can utilize 'terraform apply -refresh-only' to await |
| the population of this value.`, |
| }, |
| "state": { |
| Type: schema.TypeString, |
| Computed: true, |
| Description: `The state of this instance.`, |
| }, |
| "terraform_labels": { |
| Type: schema.TypeMap, |
| Computed: true, |
| Description: `The combination of labels configured directly on the resource |
| and default labels configured on the provider.`, |
| Elem: &schema.Schema{Type: schema.TypeString}, |
| }, |
| "update_time": { |
| Type: schema.TypeString, |
| Computed: true, |
| Optional: true, |
| Description: `Instance update time.`, |
| }, |
| "desired_state": { |
| Type: schema.TypeString, |
| Optional: true, |
| Default: "ACTIVE", |
| Description: `Desired state of the Notebook Instance. Set this field to 'ACTIVE' to start the Instance, and 'STOPPED' to stop the Instance.`, |
| }, |
| "project": { |
| Type: schema.TypeString, |
| Optional: true, |
| Computed: true, |
| ForceNew: true, |
| }, |
| }, |
| UseJSONNumber: true, |
| } |
| } |
| |
| func resourceNotebooksInstanceCreate(d *schema.ResourceData, meta interface{}) error { |
| config := meta.(*transport_tpg.Config) |
| userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) |
| if err != nil { |
| return err |
| } |
| |
| obj := make(map[string]interface{}) |
| machineTypeProp, err := expandNotebooksInstanceMachineType(d.Get("machine_type"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("machine_type"); !tpgresource.IsEmptyValue(reflect.ValueOf(machineTypeProp)) && (ok || !reflect.DeepEqual(v, machineTypeProp)) { |
| obj["machineType"] = machineTypeProp |
| } |
| postStartupScriptProp, err := expandNotebooksInstancePostStartupScript(d.Get("post_startup_script"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("post_startup_script"); !tpgresource.IsEmptyValue(reflect.ValueOf(postStartupScriptProp)) && (ok || !reflect.DeepEqual(v, postStartupScriptProp)) { |
| obj["postStartupScript"] = postStartupScriptProp |
| } |
| instanceOwnersProp, err := expandNotebooksInstanceInstanceOwners(d.Get("instance_owners"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("instance_owners"); !tpgresource.IsEmptyValue(reflect.ValueOf(instanceOwnersProp)) && (ok || !reflect.DeepEqual(v, instanceOwnersProp)) { |
| obj["instanceOwners"] = instanceOwnersProp |
| } |
| serviceAccountProp, err := expandNotebooksInstanceServiceAccount(d.Get("service_account"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("service_account"); !tpgresource.IsEmptyValue(reflect.ValueOf(serviceAccountProp)) && (ok || !reflect.DeepEqual(v, serviceAccountProp)) { |
| obj["serviceAccount"] = serviceAccountProp |
| } |
| serviceAccountScopesProp, err := expandNotebooksInstanceServiceAccountScopes(d.Get("service_account_scopes"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("service_account_scopes"); !tpgresource.IsEmptyValue(reflect.ValueOf(serviceAccountScopesProp)) && (ok || !reflect.DeepEqual(v, serviceAccountScopesProp)) { |
| obj["serviceAccountScopes"] = serviceAccountScopesProp |
| } |
| acceleratorConfigProp, err := expandNotebooksInstanceAcceleratorConfig(d.Get("accelerator_config"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("accelerator_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(acceleratorConfigProp)) && (ok || !reflect.DeepEqual(v, acceleratorConfigProp)) { |
| obj["acceleratorConfig"] = acceleratorConfigProp |
| } |
| shieldedInstanceConfigProp, err := expandNotebooksInstanceShieldedInstanceConfig(d.Get("shielded_instance_config"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("shielded_instance_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(shieldedInstanceConfigProp)) && (ok || !reflect.DeepEqual(v, shieldedInstanceConfigProp)) { |
| obj["shieldedInstanceConfig"] = shieldedInstanceConfigProp |
| } |
| nicTypeProp, err := expandNotebooksInstanceNicType(d.Get("nic_type"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("nic_type"); !tpgresource.IsEmptyValue(reflect.ValueOf(nicTypeProp)) && (ok || !reflect.DeepEqual(v, nicTypeProp)) { |
| obj["nicType"] = nicTypeProp |
| } |
| reservationAffinityProp, err := expandNotebooksInstanceReservationAffinity(d.Get("reservation_affinity"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("reservation_affinity"); !tpgresource.IsEmptyValue(reflect.ValueOf(reservationAffinityProp)) && (ok || !reflect.DeepEqual(v, reservationAffinityProp)) { |
| obj["reservationAffinity"] = reservationAffinityProp |
| } |
| installGpuDriverProp, err := expandNotebooksInstanceInstallGpuDriver(d.Get("install_gpu_driver"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("install_gpu_driver"); !tpgresource.IsEmptyValue(reflect.ValueOf(installGpuDriverProp)) && (ok || !reflect.DeepEqual(v, installGpuDriverProp)) { |
| obj["installGpuDriver"] = installGpuDriverProp |
| } |
| customGpuDriverPathProp, err := expandNotebooksInstanceCustomGpuDriverPath(d.Get("custom_gpu_driver_path"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("custom_gpu_driver_path"); !tpgresource.IsEmptyValue(reflect.ValueOf(customGpuDriverPathProp)) && (ok || !reflect.DeepEqual(v, customGpuDriverPathProp)) { |
| obj["customGpuDriverPath"] = customGpuDriverPathProp |
| } |
| bootDiskTypeProp, err := expandNotebooksInstanceBootDiskType(d.Get("boot_disk_type"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("boot_disk_type"); !tpgresource.IsEmptyValue(reflect.ValueOf(bootDiskTypeProp)) && (ok || !reflect.DeepEqual(v, bootDiskTypeProp)) { |
| obj["bootDiskType"] = bootDiskTypeProp |
| } |
| bootDiskSizeGbProp, err := expandNotebooksInstanceBootDiskSizeGb(d.Get("boot_disk_size_gb"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("boot_disk_size_gb"); !tpgresource.IsEmptyValue(reflect.ValueOf(bootDiskSizeGbProp)) && (ok || !reflect.DeepEqual(v, bootDiskSizeGbProp)) { |
| obj["bootDiskSizeGb"] = bootDiskSizeGbProp |
| } |
| dataDiskTypeProp, err := expandNotebooksInstanceDataDiskType(d.Get("data_disk_type"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("data_disk_type"); !tpgresource.IsEmptyValue(reflect.ValueOf(dataDiskTypeProp)) && (ok || !reflect.DeepEqual(v, dataDiskTypeProp)) { |
| obj["dataDiskType"] = dataDiskTypeProp |
| } |
| dataDiskSizeGbProp, err := expandNotebooksInstanceDataDiskSizeGb(d.Get("data_disk_size_gb"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("data_disk_size_gb"); !tpgresource.IsEmptyValue(reflect.ValueOf(dataDiskSizeGbProp)) && (ok || !reflect.DeepEqual(v, dataDiskSizeGbProp)) { |
| obj["dataDiskSizeGb"] = dataDiskSizeGbProp |
| } |
| noRemoveDataDiskProp, err := expandNotebooksInstanceNoRemoveDataDisk(d.Get("no_remove_data_disk"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("no_remove_data_disk"); !tpgresource.IsEmptyValue(reflect.ValueOf(noRemoveDataDiskProp)) && (ok || !reflect.DeepEqual(v, noRemoveDataDiskProp)) { |
| obj["noRemoveDataDisk"] = noRemoveDataDiskProp |
| } |
| diskEncryptionProp, err := expandNotebooksInstanceDiskEncryption(d.Get("disk_encryption"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("disk_encryption"); !tpgresource.IsEmptyValue(reflect.ValueOf(diskEncryptionProp)) && (ok || !reflect.DeepEqual(v, diskEncryptionProp)) { |
| obj["diskEncryption"] = diskEncryptionProp |
| } |
| kmsKeyProp, err := expandNotebooksInstanceKmsKey(d.Get("kms_key"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("kms_key"); !tpgresource.IsEmptyValue(reflect.ValueOf(kmsKeyProp)) && (ok || !reflect.DeepEqual(v, kmsKeyProp)) { |
| obj["kmsKey"] = kmsKeyProp |
| } |
| noPublicIpProp, err := expandNotebooksInstanceNoPublicIp(d.Get("no_public_ip"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("no_public_ip"); !tpgresource.IsEmptyValue(reflect.ValueOf(noPublicIpProp)) && (ok || !reflect.DeepEqual(v, noPublicIpProp)) { |
| obj["noPublicIp"] = noPublicIpProp |
| } |
| noProxyAccessProp, err := expandNotebooksInstanceNoProxyAccess(d.Get("no_proxy_access"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("no_proxy_access"); !tpgresource.IsEmptyValue(reflect.ValueOf(noProxyAccessProp)) && (ok || !reflect.DeepEqual(v, noProxyAccessProp)) { |
| obj["noProxyAccess"] = noProxyAccessProp |
| } |
| networkProp, err := expandNotebooksInstanceNetwork(d.Get("network"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("network"); !tpgresource.IsEmptyValue(reflect.ValueOf(networkProp)) && (ok || !reflect.DeepEqual(v, networkProp)) { |
| obj["network"] = networkProp |
| } |
| subnetProp, err := expandNotebooksInstanceSubnet(d.Get("subnet"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("subnet"); !tpgresource.IsEmptyValue(reflect.ValueOf(subnetProp)) && (ok || !reflect.DeepEqual(v, subnetProp)) { |
| obj["subnet"] = subnetProp |
| } |
| tagsProp, err := expandNotebooksInstanceTags(d.Get("tags"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("tags"); !tpgresource.IsEmptyValue(reflect.ValueOf(tagsProp)) && (ok || !reflect.DeepEqual(v, tagsProp)) { |
| obj["tags"] = tagsProp |
| } |
| metadataProp, err := expandNotebooksInstanceMetadata(d.Get("metadata"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("metadata"); !tpgresource.IsEmptyValue(reflect.ValueOf(metadataProp)) && (ok || !reflect.DeepEqual(v, metadataProp)) { |
| obj["metadata"] = metadataProp |
| } |
| vmImageProp, err := expandNotebooksInstanceVmImage(d.Get("vm_image"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("vm_image"); !tpgresource.IsEmptyValue(reflect.ValueOf(vmImageProp)) && (ok || !reflect.DeepEqual(v, vmImageProp)) { |
| obj["vmImage"] = vmImageProp |
| } |
| containerImageProp, err := expandNotebooksInstanceContainerImage(d.Get("container_image"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("container_image"); !tpgresource.IsEmptyValue(reflect.ValueOf(containerImageProp)) && (ok || !reflect.DeepEqual(v, containerImageProp)) { |
| obj["containerImage"] = containerImageProp |
| } |
| labelsProp, err := expandNotebooksInstanceEffectiveLabels(d.Get("effective_labels"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("effective_labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) { |
| obj["labels"] = labelsProp |
| } |
| |
| url, err := tpgresource.ReplaceVars(d, config, "{{NotebooksBasePath}}projects/{{project}}/locations/{{location}}/instances?instanceId={{name}}") |
| if err != nil { |
| return err |
| } |
| |
| log.Printf("[DEBUG] Creating new Instance: %#v", obj) |
| billingProject := "" |
| |
| project, err := tpgresource.GetProject(d, config) |
| if err != nil { |
| return fmt.Errorf("Error fetching project for Instance: %s", err) |
| } |
| billingProject = project |
| |
| // err == nil indicates that the billing_project value was found |
| if bp, err := tpgresource.GetBillingProject(d, config); err == nil { |
| billingProject = bp |
| } |
| |
| res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ |
| Config: config, |
| Method: "POST", |
| Project: billingProject, |
| RawURL: url, |
| UserAgent: userAgent, |
| Body: obj, |
| Timeout: d.Timeout(schema.TimeoutCreate), |
| }) |
| if err != nil { |
| return fmt.Errorf("Error creating Instance: %s", err) |
| } |
| |
| // Store the ID now |
| id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{location}}/instances/{{name}}") |
| if err != nil { |
| return fmt.Errorf("Error constructing id: %s", err) |
| } |
| d.SetId(id) |
| |
| // Use the resource in the operation response to populate |
| // identity fields and d.Id() before read |
| var opRes map[string]interface{} |
| err = NotebooksOperationWaitTimeWithResponse( |
| config, res, &opRes, project, "Creating Instance", userAgent, |
| d.Timeout(schema.TimeoutCreate)) |
| if err != nil { |
| // The resource didn't actually create |
| d.SetId("") |
| |
| return fmt.Errorf("Error waiting to create Instance: %s", err) |
| } |
| |
| // This may have caused the ID to update - update it if so. |
| id, err = tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{location}}/instances/{{name}}") |
| if err != nil { |
| return fmt.Errorf("Error constructing id: %s", err) |
| } |
| d.SetId(id) |
| |
| if err := waitForNotebooksInstanceActive(d, config, d.Timeout(schema.TimeoutCreate)-time.Minute); err != nil { |
| return fmt.Errorf("Notebook instance %q did not reach ACTIVE state: %q", d.Get("name").(string), err) |
| } |
| |
| if p, ok := d.GetOk("desired_state"); ok && p.(string) == "STOPPED" { |
| dRes, err := modifyNotebooksInstanceState(config, d, project, billingProject, userAgent, "stop") |
| if err != nil { |
| return err |
| } |
| if err := waitForNotebooksOperation(config, d, project, billingProject, userAgent, dRes); err != nil { |
| return fmt.Errorf("Error stopping Notebook Instance: %s", err) |
| } |
| } |
| |
| log.Printf("[DEBUG] Finished creating Instance %q: %#v", d.Id(), res) |
| |
| return resourceNotebooksInstanceRead(d, meta) |
| } |
| |
| func resourceNotebooksInstanceRead(d *schema.ResourceData, meta interface{}) error { |
| config := meta.(*transport_tpg.Config) |
| userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) |
| if err != nil { |
| return err |
| } |
| |
| url, err := tpgresource.ReplaceVars(d, config, "{{NotebooksBasePath}}projects/{{project}}/locations/{{location}}/instances/{{name}}") |
| if err != nil { |
| return err |
| } |
| |
| billingProject := "" |
| |
| project, err := tpgresource.GetProject(d, config) |
| if err != nil { |
| return fmt.Errorf("Error fetching project for Instance: %s", err) |
| } |
| billingProject = project |
| |
| // err == nil indicates that the billing_project value was found |
| if bp, err := tpgresource.GetBillingProject(d, config); err == nil { |
| billingProject = bp |
| } |
| |
| res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ |
| Config: config, |
| Method: "GET", |
| Project: billingProject, |
| RawURL: url, |
| UserAgent: userAgent, |
| }) |
| if err != nil { |
| return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("NotebooksInstance %q", d.Id())) |
| } |
| |
| // Explicitly set virtual fields to default values if unset |
| if _, ok := d.GetOkExists("desired_state"); !ok { |
| if err := d.Set("desired_state", "ACTIVE"); err != nil { |
| return fmt.Errorf("Error setting desired_state: %s", err) |
| } |
| } |
| if err := d.Set("project", project); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| |
| if err := d.Set("machine_type", flattenNotebooksInstanceMachineType(res["machineType"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("post_startup_script", flattenNotebooksInstancePostStartupScript(res["postStartupScript"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("proxy_uri", flattenNotebooksInstanceProxyUri(res["proxyUri"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("service_account", flattenNotebooksInstanceServiceAccount(res["serviceAccount"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("service_account_scopes", flattenNotebooksInstanceServiceAccountScopes(res["serviceAccountScopes"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("accelerator_config", flattenNotebooksInstanceAcceleratorConfig(res["acceleratorConfig"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("shielded_instance_config", flattenNotebooksInstanceShieldedInstanceConfig(res["shieldedInstanceConfig"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("nic_type", flattenNotebooksInstanceNicType(res["nicType"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("reservation_affinity", flattenNotebooksInstanceReservationAffinity(res["reservationAffinity"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("state", flattenNotebooksInstanceState(res["state"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("install_gpu_driver", flattenNotebooksInstanceInstallGpuDriver(res["installGpuDriver"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("custom_gpu_driver_path", flattenNotebooksInstanceCustomGpuDriverPath(res["customGpuDriverPath"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("disk_encryption", flattenNotebooksInstanceDiskEncryption(res["diskEncryption"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("kms_key", flattenNotebooksInstanceKmsKey(res["kmsKey"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("no_public_ip", flattenNotebooksInstanceNoPublicIp(res["noPublicIp"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("no_proxy_access", flattenNotebooksInstanceNoProxyAccess(res["noProxyAccess"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("network", flattenNotebooksInstanceNetwork(res["network"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("subnet", flattenNotebooksInstanceSubnet(res["subnet"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("labels", flattenNotebooksInstanceLabels(res["labels"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("tags", flattenNotebooksInstanceTags(res["tags"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("create_time", flattenNotebooksInstanceCreateTime(res["createTime"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("update_time", flattenNotebooksInstanceUpdateTime(res["updateTime"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("terraform_labels", flattenNotebooksInstanceTerraformLabels(res["labels"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("effective_labels", flattenNotebooksInstanceEffectiveLabels(res["labels"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| |
| return nil |
| } |
| |
| func resourceNotebooksInstanceUpdate(d *schema.ResourceData, meta interface{}) error { |
| config := meta.(*transport_tpg.Config) |
| userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) |
| if err != nil { |
| return err |
| } |
| |
| billingProject := "" |
| |
| project, err := tpgresource.GetProject(d, config) |
| if err != nil { |
| return fmt.Errorf("Error fetching project for Instance: %s", err) |
| } |
| billingProject = project |
| |
| d.Partial(true) |
| |
| if d.HasChange("metadata") { |
| obj := make(map[string]interface{}) |
| |
| metadataProp, err := expandNotebooksInstanceMetadata(d.Get("metadata"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("metadata"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, metadataProp)) { |
| obj["metadata"] = metadataProp |
| } |
| |
| obj, err = resourceNotebooksInstanceUpdateEncoder(d, meta, obj) |
| if err != nil { |
| return err |
| } |
| |
| url, err := tpgresource.ReplaceVars(d, config, "{{NotebooksBasePath}}projects/{{project}}/locations/{{location}}/instances/{{name}}:updateMetadataItems") |
| if err != nil { |
| return err |
| } |
| |
| // err == nil indicates that the billing_project value was found |
| if bp, err := tpgresource.GetBillingProject(d, config); err == nil { |
| billingProject = bp |
| } |
| |
| res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ |
| Config: config, |
| Method: "PATCH", |
| Project: billingProject, |
| RawURL: url, |
| UserAgent: userAgent, |
| Body: obj, |
| Timeout: d.Timeout(schema.TimeoutUpdate), |
| }) |
| if err != nil { |
| return fmt.Errorf("Error updating Instance %q: %s", d.Id(), err) |
| } else { |
| log.Printf("[DEBUG] Finished updating Instance %q: %#v", d.Id(), res) |
| } |
| |
| err = NotebooksOperationWaitTime( |
| config, res, project, "Updating Instance", userAgent, |
| d.Timeout(schema.TimeoutUpdate)) |
| if err != nil { |
| return err |
| } |
| } |
| if d.HasChange("effective_labels") { |
| obj := make(map[string]interface{}) |
| |
| labelsProp, err := expandNotebooksInstanceEffectiveLabels(d.Get("effective_labels"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("effective_labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, labelsProp)) { |
| obj["labels"] = labelsProp |
| } |
| |
| obj, err = resourceNotebooksInstanceUpdateEncoder(d, meta, obj) |
| if err != nil { |
| return err |
| } |
| |
| url, err := tpgresource.ReplaceVars(d, config, "{{NotebooksBasePath}}projects/{{project}}/locations/{{location}}/instances/{{name}}:setLabels") |
| if err != nil { |
| return err |
| } |
| |
| // err == nil indicates that the billing_project value was found |
| if bp, err := tpgresource.GetBillingProject(d, config); err == nil { |
| billingProject = bp |
| } |
| |
| res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ |
| Config: config, |
| Method: "PATCH", |
| Project: billingProject, |
| RawURL: url, |
| UserAgent: userAgent, |
| Body: obj, |
| Timeout: d.Timeout(schema.TimeoutUpdate), |
| }) |
| if err != nil { |
| return fmt.Errorf("Error updating Instance %q: %s", d.Id(), err) |
| } else { |
| log.Printf("[DEBUG] Finished updating Instance %q: %#v", d.Id(), res) |
| } |
| |
| err = NotebooksOperationWaitTime( |
| config, res, project, "Updating Instance", userAgent, |
| d.Timeout(schema.TimeoutUpdate)) |
| if err != nil { |
| return err |
| } |
| } |
| |
| d.Partial(false) |
| |
| name := d.Get("name").(string) |
| state := d.Get("state").(string) |
| desired_state := d.Get("desired_state").(string) |
| |
| if state != desired_state { |
| verb := "start" |
| if desired_state == "STOPPED" { |
| verb = "stop" |
| } |
| pRes, err := modifyNotebooksInstanceState(config, d, project, billingProject, userAgent, verb) |
| if err != nil { |
| return err |
| } |
| |
| if err := waitForNotebooksOperation(config, d, project, billingProject, userAgent, pRes); err != nil { |
| return fmt.Errorf("Error waiting to modify Notebook Instance state: %s", err) |
| } |
| |
| } else { |
| log.Printf("[DEBUG] Notebook Instance %q has state %q.", name, state) |
| } |
| return resourceNotebooksInstanceRead(d, meta) |
| } |
| |
| func resourceNotebooksInstanceDelete(d *schema.ResourceData, meta interface{}) error { |
| config := meta.(*transport_tpg.Config) |
| userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) |
| if err != nil { |
| return err |
| } |
| |
| billingProject := "" |
| |
| project, err := tpgresource.GetProject(d, config) |
| if err != nil { |
| return fmt.Errorf("Error fetching project for Instance: %s", err) |
| } |
| billingProject = project |
| |
| url, err := tpgresource.ReplaceVars(d, config, "{{NotebooksBasePath}}projects/{{project}}/locations/{{location}}/instances/{{name}}") |
| if err != nil { |
| return err |
| } |
| |
| var obj map[string]interface{} |
| log.Printf("[DEBUG] Deleting Instance %q", d.Id()) |
| |
| // err == nil indicates that the billing_project value was found |
| if bp, err := tpgresource.GetBillingProject(d, config); err == nil { |
| billingProject = bp |
| } |
| |
| res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ |
| Config: config, |
| Method: "DELETE", |
| Project: billingProject, |
| RawURL: url, |
| UserAgent: userAgent, |
| Body: obj, |
| Timeout: d.Timeout(schema.TimeoutDelete), |
| }) |
| if err != nil { |
| return transport_tpg.HandleNotFoundError(err, d, "Instance") |
| } |
| |
| err = NotebooksOperationWaitTime( |
| config, res, project, "Deleting Instance", userAgent, |
| d.Timeout(schema.TimeoutDelete)) |
| |
| if err != nil { |
| return err |
| } |
| |
| log.Printf("[DEBUG] Finished deleting Instance %q: %#v", d.Id(), res) |
| return nil |
| } |
| |
| func resourceNotebooksInstanceImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { |
| config := meta.(*transport_tpg.Config) |
| if err := tpgresource.ParseImportId([]string{ |
| "^projects/(?P<project>[^/]+)/locations/(?P<location>[^/]+)/instances/(?P<name>[^/]+)$", |
| "^(?P<project>[^/]+)/(?P<location>[^/]+)/(?P<name>[^/]+)$", |
| "^(?P<location>[^/]+)/(?P<name>[^/]+)$", |
| }, d, config); err != nil { |
| return nil, err |
| } |
| |
| // Replace import id for the resource id |
| id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{location}}/instances/{{name}}") |
| if err != nil { |
| return nil, fmt.Errorf("Error constructing id: %s", err) |
| } |
| d.SetId(id) |
| |
| // Explicitly set virtual fields to default values on import |
| if err := d.Set("desired_state", "ACTIVE"); err != nil { |
| return nil, fmt.Errorf("Error setting desired_state: %s", err) |
| } |
| |
| return []*schema.ResourceData{d}, nil |
| } |
| |
| func flattenNotebooksInstanceMachineType(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| if v == nil { |
| return v |
| } |
| return tpgresource.NameFromSelfLinkStateFunc(v) |
| } |
| |
| func flattenNotebooksInstancePostStartupScript(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenNotebooksInstanceProxyUri(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenNotebooksInstanceServiceAccount(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenNotebooksInstanceServiceAccountScopes(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenNotebooksInstanceAcceleratorConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| if v == nil { |
| return nil |
| } |
| original := v.(map[string]interface{}) |
| if len(original) == 0 { |
| return nil |
| } |
| transformed := make(map[string]interface{}) |
| transformed["type"] = |
| flattenNotebooksInstanceAcceleratorConfigType(original["type"], d, config) |
| transformed["core_count"] = |
| flattenNotebooksInstanceAcceleratorConfigCoreCount(original["coreCount"], d, config) |
| return []interface{}{transformed} |
| } |
| func flattenNotebooksInstanceAcceleratorConfigType(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenNotebooksInstanceAcceleratorConfigCoreCount(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| // Handles the string fixed64 format |
| if strVal, ok := v.(string); ok { |
| if intVal, err := tpgresource.StringToFixed64(strVal); err == nil { |
| return intVal |
| } |
| } |
| |
| // number values are represented as float64 |
| if floatVal, ok := v.(float64); ok { |
| intVal := int(floatVal) |
| return intVal |
| } |
| |
| return v // let terraform core handle it otherwise |
| } |
| |
| func flattenNotebooksInstanceShieldedInstanceConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| if v == nil { |
| return nil |
| } |
| original := v.(map[string]interface{}) |
| if len(original) == 0 { |
| return nil |
| } |
| transformed := make(map[string]interface{}) |
| transformed["enable_integrity_monitoring"] = |
| flattenNotebooksInstanceShieldedInstanceConfigEnableIntegrityMonitoring(original["enableIntegrityMonitoring"], d, config) |
| transformed["enable_secure_boot"] = |
| flattenNotebooksInstanceShieldedInstanceConfigEnableSecureBoot(original["enableSecureBoot"], d, config) |
| transformed["enable_vtpm"] = |
| flattenNotebooksInstanceShieldedInstanceConfigEnableVtpm(original["enableVtpm"], d, config) |
| return []interface{}{transformed} |
| } |
| func flattenNotebooksInstanceShieldedInstanceConfigEnableIntegrityMonitoring(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenNotebooksInstanceShieldedInstanceConfigEnableSecureBoot(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenNotebooksInstanceShieldedInstanceConfigEnableVtpm(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenNotebooksInstanceNicType(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenNotebooksInstanceReservationAffinity(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| if v == nil { |
| return nil |
| } |
| original := v.(map[string]interface{}) |
| if len(original) == 0 { |
| return nil |
| } |
| transformed := make(map[string]interface{}) |
| transformed["consume_reservation_type"] = |
| flattenNotebooksInstanceReservationAffinityConsumeReservationType(original["consumeReservationType"], d, config) |
| transformed["key"] = |
| flattenNotebooksInstanceReservationAffinityKey(original["key"], d, config) |
| transformed["values"] = |
| flattenNotebooksInstanceReservationAffinityValues(original["values"], d, config) |
| return []interface{}{transformed} |
| } |
| func flattenNotebooksInstanceReservationAffinityConsumeReservationType(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenNotebooksInstanceReservationAffinityKey(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenNotebooksInstanceReservationAffinityValues(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenNotebooksInstanceState(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenNotebooksInstanceInstallGpuDriver(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenNotebooksInstanceCustomGpuDriverPath(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenNotebooksInstanceDiskEncryption(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenNotebooksInstanceKmsKey(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenNotebooksInstanceNoPublicIp(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenNotebooksInstanceNoProxyAccess(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenNotebooksInstanceNetwork(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenNotebooksInstanceSubnet(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenNotebooksInstanceLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| if v == nil { |
| return v |
| } |
| |
| transformed := make(map[string]interface{}) |
| if l, ok := d.GetOkExists("labels"); ok { |
| for k := range l.(map[string]interface{}) { |
| transformed[k] = v.(map[string]interface{})[k] |
| } |
| } |
| |
| return transformed |
| } |
| |
| func flattenNotebooksInstanceTags(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenNotebooksInstanceCreateTime(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenNotebooksInstanceUpdateTime(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenNotebooksInstanceTerraformLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| if v == nil { |
| return v |
| } |
| |
| transformed := make(map[string]interface{}) |
| if l, ok := d.GetOkExists("terraform_labels"); ok { |
| for k := range l.(map[string]interface{}) { |
| transformed[k] = v.(map[string]interface{})[k] |
| } |
| } |
| |
| return transformed |
| } |
| |
| func flattenNotebooksInstanceEffectiveLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func expandNotebooksInstanceMachineType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstancePostStartupScript(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceInstanceOwners(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceServiceAccount(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceServiceAccountScopes(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceAcceleratorConfig(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| l := v.([]interface{}) |
| if len(l) == 0 || l[0] == nil { |
| return nil, nil |
| } |
| raw := l[0] |
| original := raw.(map[string]interface{}) |
| transformed := make(map[string]interface{}) |
| |
| transformedType, err := expandNotebooksInstanceAcceleratorConfigType(original["type"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedType); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["type"] = transformedType |
| } |
| |
| transformedCoreCount, err := expandNotebooksInstanceAcceleratorConfigCoreCount(original["core_count"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedCoreCount); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["coreCount"] = transformedCoreCount |
| } |
| |
| return transformed, nil |
| } |
| |
| func expandNotebooksInstanceAcceleratorConfigType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceAcceleratorConfigCoreCount(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceShieldedInstanceConfig(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| l := v.([]interface{}) |
| if len(l) == 0 || l[0] == nil { |
| return nil, nil |
| } |
| raw := l[0] |
| original := raw.(map[string]interface{}) |
| transformed := make(map[string]interface{}) |
| |
| transformedEnableIntegrityMonitoring, err := expandNotebooksInstanceShieldedInstanceConfigEnableIntegrityMonitoring(original["enable_integrity_monitoring"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedEnableIntegrityMonitoring); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["enableIntegrityMonitoring"] = transformedEnableIntegrityMonitoring |
| } |
| |
| transformedEnableSecureBoot, err := expandNotebooksInstanceShieldedInstanceConfigEnableSecureBoot(original["enable_secure_boot"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedEnableSecureBoot); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["enableSecureBoot"] = transformedEnableSecureBoot |
| } |
| |
| transformedEnableVtpm, err := expandNotebooksInstanceShieldedInstanceConfigEnableVtpm(original["enable_vtpm"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedEnableVtpm); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["enableVtpm"] = transformedEnableVtpm |
| } |
| |
| return transformed, nil |
| } |
| |
| func expandNotebooksInstanceShieldedInstanceConfigEnableIntegrityMonitoring(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceShieldedInstanceConfigEnableSecureBoot(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceShieldedInstanceConfigEnableVtpm(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceNicType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceReservationAffinity(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| l := v.([]interface{}) |
| if len(l) == 0 || l[0] == nil { |
| return nil, nil |
| } |
| raw := l[0] |
| original := raw.(map[string]interface{}) |
| transformed := make(map[string]interface{}) |
| |
| transformedConsumeReservationType, err := expandNotebooksInstanceReservationAffinityConsumeReservationType(original["consume_reservation_type"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedConsumeReservationType); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["consumeReservationType"] = transformedConsumeReservationType |
| } |
| |
| transformedKey, err := expandNotebooksInstanceReservationAffinityKey(original["key"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedKey); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["key"] = transformedKey |
| } |
| |
| transformedValues, err := expandNotebooksInstanceReservationAffinityValues(original["values"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedValues); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["values"] = transformedValues |
| } |
| |
| return transformed, nil |
| } |
| |
| func expandNotebooksInstanceReservationAffinityConsumeReservationType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceReservationAffinityKey(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceReservationAffinityValues(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceInstallGpuDriver(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceCustomGpuDriverPath(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceBootDiskType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceBootDiskSizeGb(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceDataDiskType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceDataDiskSizeGb(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceNoRemoveDataDisk(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceDiskEncryption(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceKmsKey(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceNoPublicIp(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceNoProxyAccess(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceNetwork(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceSubnet(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceTags(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceMetadata(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) { |
| if v == nil { |
| return map[string]string{}, nil |
| } |
| m := make(map[string]string) |
| for k, val := range v.(map[string]interface{}) { |
| m[k] = val.(string) |
| } |
| return m, nil |
| } |
| |
| func expandNotebooksInstanceVmImage(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| l := v.([]interface{}) |
| if len(l) == 0 || l[0] == nil { |
| return nil, nil |
| } |
| raw := l[0] |
| original := raw.(map[string]interface{}) |
| transformed := make(map[string]interface{}) |
| |
| transformedProject, err := expandNotebooksInstanceVmImageProject(original["project"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedProject); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["project"] = transformedProject |
| } |
| |
| transformedImageFamily, err := expandNotebooksInstanceVmImageImageFamily(original["image_family"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedImageFamily); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["imageFamily"] = transformedImageFamily |
| } |
| |
| transformedImageName, err := expandNotebooksInstanceVmImageImageName(original["image_name"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedImageName); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["imageName"] = transformedImageName |
| } |
| |
| return transformed, nil |
| } |
| |
| func expandNotebooksInstanceVmImageProject(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceVmImageImageFamily(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceVmImageImageName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceContainerImage(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| l := v.([]interface{}) |
| if len(l) == 0 || l[0] == nil { |
| return nil, nil |
| } |
| raw := l[0] |
| original := raw.(map[string]interface{}) |
| transformed := make(map[string]interface{}) |
| |
| transformedRepository, err := expandNotebooksInstanceContainerImageRepository(original["repository"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedRepository); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["repository"] = transformedRepository |
| } |
| |
| transformedTag, err := expandNotebooksInstanceContainerImageTag(original["tag"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedTag); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["tag"] = transformedTag |
| } |
| |
| return transformed, nil |
| } |
| |
| func expandNotebooksInstanceContainerImageRepository(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceContainerImageTag(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandNotebooksInstanceEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) { |
| if v == nil { |
| return map[string]string{}, nil |
| } |
| m := make(map[string]string) |
| for k, val := range v.(map[string]interface{}) { |
| m[k] = val.(string) |
| } |
| return m, nil |
| } |
| |
| func resourceNotebooksInstanceUpdateEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) { |
| // Update requests use "items" as the api name instead of "metadata" |
| // https://cloud.google.com/vertex-ai/docs/workbench/reference/rest/v1/projects.locations.instances/updateMetadataItems |
| if metadata, ok := obj["metadata"]; ok { |
| obj["items"] = metadata |
| delete(obj, "metadata") |
| } |
| return obj, nil |
| } |
| |
| const notebooksInstanceGoogleProvidedLabel = "goog-caip-notebook" |
| |
| func NotebooksInstanceLabelDiffSuppress(k, old, new string, d *schema.ResourceData) bool { |
| // Suppress diffs for the label provided by Google |
| if strings.Contains(k, notebooksInstanceGoogleProvidedLabel) && new == "" { |
| return true |
| } |
| |
| // Let diff be determined by labels (above) |
| if strings.Contains(k, "labels.%") { |
| return true |
| } |
| |
| // For other keys, don't suppress diff. |
| return false |
| } |
| |
| func resourceNotebooksInstanceResourceV0() *schema.Resource { |
| return &schema.Resource{ |
| Schema: map[string]*schema.Schema{ |
| "location": { |
| Type: schema.TypeString, |
| Required: true, |
| ForceNew: true, |
| DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, |
| Description: `A reference to the zone where the machine resides.`, |
| }, |
| "machine_type": { |
| Type: schema.TypeString, |
| Required: true, |
| ForceNew: true, |
| DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, |
| Description: `A reference to a machine type which defines VM kind.`, |
| }, |
| "name": { |
| Type: schema.TypeString, |
| Required: true, |
| ForceNew: true, |
| Description: `The name specified for the Notebook instance.`, |
| }, |
| "accelerator_config": { |
| Type: schema.TypeList, |
| Optional: true, |
| ForceNew: true, |
| Description: `The hardware accelerator used on this instance. If you use accelerators, |
| make sure that your configuration has enough vCPUs and memory to support the |
| machineType you have selected.`, |
| MaxItems: 1, |
| Elem: &schema.Resource{ |
| Schema: map[string]*schema.Schema{ |
| "core_count": { |
| Type: schema.TypeInt, |
| Required: true, |
| ForceNew: true, |
| Description: `Count of cores of this accelerator.`, |
| }, |
| "type": { |
| Type: schema.TypeString, |
| Required: true, |
| ForceNew: true, |
| ValidateFunc: verify.ValidateEnum([]string{"ACCELERATOR_TYPE_UNSPECIFIED", "NVIDIA_TESLA_K80", "NVIDIA_TESLA_P100", "NVIDIA_TESLA_V100", "NVIDIA_TESLA_P4", "NVIDIA_TESLA_T4", "NVIDIA_TESLA_T4_VWS", "NVIDIA_TESLA_P100_VWS", "NVIDIA_TESLA_P4_VWS", "NVIDIA_TESLA_A100", "TPU_V2", "TPU_V3"}), |
| Description: `Type of this accelerator. Possible values: ["ACCELERATOR_TYPE_UNSPECIFIED", "NVIDIA_TESLA_K80", "NVIDIA_TESLA_P100", "NVIDIA_TESLA_V100", "NVIDIA_TESLA_P4", "NVIDIA_TESLA_T4", "NVIDIA_TESLA_T4_VWS", "NVIDIA_TESLA_P100_VWS", "NVIDIA_TESLA_P4_VWS", "NVIDIA_TESLA_A100", "TPU_V2", "TPU_V3"]`, |
| }, |
| }, |
| }, |
| }, |
| "boot_disk_size_gb": { |
| Type: schema.TypeInt, |
| Optional: true, |
| ForceNew: true, |
| Description: `The size of the boot disk in GB attached to this instance, |
| up to a maximum of 64000 GB (64 TB). The minimum recommended value is 100 GB. |
| If not specified, this defaults to 100.`, |
| }, |
| "boot_disk_type": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| ValidateFunc: verify.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, |
| Optional: true, |
| ForceNew: true, |
| Description: `Use a container image to start the notebook instance.`, |
| MaxItems: 1, |
| Elem: &schema.Resource{ |
| Schema: map[string]*schema.Schema{ |
| "repository": { |
| Type: schema.TypeString, |
| Required: true, |
| ForceNew: true, |
| Description: `The path to the container image repository. |
| For example: gcr.io/{project_id}/{imageName}`, |
| }, |
| "tag": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| Description: `The tag of the container image. If not specified, this defaults to the latest tag.`, |
| }, |
| }, |
| }, |
| ExactlyOneOf: []string{"vm_image", "container_image"}, |
| }, |
| "custom_gpu_driver_path": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| Description: `Specify a custom Cloud Storage path where the GPU driver is stored. |
| If not specified, we'll automatically choose from official GPU drivers.`, |
| }, |
| "data_disk_size_gb": { |
| Type: schema.TypeInt, |
| Optional: true, |
| ForceNew: true, |
| Description: `The size of the data disk in GB attached to this instance, |
| up to a maximum of 64000 GB (64 TB). |
| You can choose the size of the data disk based on how big your notebooks and data are. |
| If not specified, this defaults to 100.`, |
| }, |
| "data_disk_type": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| ValidateFunc: verify.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"]`, |
| }, |
| "disk_encryption": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| ValidateFunc: verify.ValidateEnum([]string{"DISK_ENCRYPTION_UNSPECIFIED", "GMEK", "CMEK", ""}), |
| DiffSuppressFunc: tpgresource.EmptyOrDefaultStringSuppress("DISK_ENCRYPTION_UNSPECIFIED"), |
| Description: `Disk encryption method used on the boot and data disks, defaults to GMEK. Possible values: ["DISK_ENCRYPTION_UNSPECIFIED", "GMEK", "CMEK"]`, |
| }, |
| "install_gpu_driver": { |
| Type: schema.TypeBool, |
| Optional: true, |
| ForceNew: true, |
| Description: `Whether the end user authorizes Google Cloud to install GPU driver |
| on this instance. If this field is empty or set to false, the GPU driver |
| won't be installed. Only applicable to instances with GPUs.`, |
| }, |
| "instance_owners": { |
| Type: schema.TypeList, |
| Optional: true, |
| ForceNew: true, |
| Description: `The list of owners of this instance after creation. |
| Format: alias@example.com. |
| Currently supports one owner only. |
| If not specified, all of the service account users of |
| your VM instance's service account can use the instance.`, |
| Elem: &schema.Schema{ |
| Type: schema.TypeString, |
| }, |
| }, |
| "kms_key": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| Description: `The KMS key used to encrypt the disks, only applicable if diskEncryption is CMEK. |
| Format: projects/{project_id}/locations/{location}/keyRings/{key_ring_id}/cryptoKeys/{key_id}`, |
| }, |
| "labels": { |
| Type: schema.TypeMap, |
| Computed: true, |
| Optional: true, |
| DiffSuppressFunc: NotebooksInstanceLabelDiffSuppress, |
| Description: `Labels to apply to this instance. These can be later modified by the setLabels method. |
| An object containing a list of "key": value pairs. Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.`, |
| Elem: &schema.Schema{Type: schema.TypeString}, |
| }, |
| "metadata": { |
| Type: schema.TypeMap, |
| Optional: true, |
| Description: `Custom metadata to apply to this instance. |
| An object containing a list of "key": value pairs. Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.`, |
| Elem: &schema.Schema{Type: schema.TypeString}, |
| }, |
| "network": { |
| Type: schema.TypeString, |
| Computed: true, |
| Optional: true, |
| ForceNew: true, |
| DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, |
| Description: `The name of the VPC that this instance is in. |
| Format: projects/{project_id}/global/networks/{network_id}`, |
| }, |
| "nic_type": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| ValidateFunc: verify.ValidateEnum([]string{"UNSPECIFIED_NIC_TYPE", "VIRTIO_NET", "GVNIC", ""}), |
| Description: `The type of vNIC driver. Possible values: ["UNSPECIFIED_NIC_TYPE", "VIRTIO_NET", "GVNIC"]`, |
| }, |
| "no_proxy_access": { |
| Type: schema.TypeBool, |
| Optional: true, |
| ForceNew: true, |
| Description: `The notebook instance will not register with the proxy..`, |
| }, |
| "no_public_ip": { |
| Type: schema.TypeBool, |
| Optional: true, |
| ForceNew: true, |
| Description: `No public IP will be assigned to this instance.`, |
| }, |
| "no_remove_data_disk": { |
| Type: schema.TypeBool, |
| Optional: true, |
| ForceNew: true, |
| Description: `If true, the data disk will not be auto deleted when deleting the instance.`, |
| }, |
| "post_startup_script": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| Description: `Path to a Bash script that automatically runs after a |
| notebook instance fully boots up. The path must be a URL |
| or Cloud Storage path (gs://path-to-file/file-name).`, |
| }, |
| "reservation_affinity": { |
| Type: schema.TypeList, |
| Optional: true, |
| ForceNew: true, |
| Description: `Reservation Affinity for consuming Zonal reservation.`, |
| MaxItems: 1, |
| Elem: &schema.Resource{ |
| Schema: map[string]*schema.Schema{ |
| "consume_reservation_type": { |
| Type: schema.TypeString, |
| Required: true, |
| ForceNew: true, |
| ValidateFunc: verify.ValidateEnum([]string{"NO_RESERVATION", "ANY_RESERVATION", "SPECIFIC_RESERVATION"}), |
| Description: `The type of Compute Reservation. Possible values: ["NO_RESERVATION", "ANY_RESERVATION", "SPECIFIC_RESERVATION"]`, |
| }, |
| "key": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| Description: `Corresponds to the label key of reservation resource.`, |
| }, |
| "values": { |
| Type: schema.TypeList, |
| Optional: true, |
| ForceNew: true, |
| Description: `Corresponds to the label values of reservation resource.`, |
| Elem: &schema.Schema{ |
| Type: schema.TypeString, |
| }, |
| }, |
| }, |
| }, |
| }, |
| "service_account": { |
| Type: schema.TypeString, |
| Computed: true, |
| Optional: true, |
| ForceNew: true, |
| Description: `The service account on this instance, giving access to other |
| Google Cloud services. You can use any service account within |
| the same project, but you must have the service account user |
| permission to use the instance. If not specified, |
| the Compute Engine default service account is used.`, |
| }, |
| "service_account_scopes": { |
| Type: schema.TypeList, |
| Optional: true, |
| ForceNew: true, |
| Description: `Optional. The URIs of service account scopes to be included in Compute Engine instances. |
| If not specified, the following scopes are defined: |
| - https://www.googleapis.com/auth/cloud-platform |
| - https://www.googleapis.com/auth/userinfo.email`, |
| Elem: &schema.Schema{ |
| Type: schema.TypeString, |
| }, |
| }, |
| "shielded_instance_config": { |
| Type: schema.TypeList, |
| Computed: true, |
| Optional: true, |
| ForceNew: true, |
| Description: `A set of Shielded Instance options. Check [Images using supported Shielded VM features] |
| Not all combinations are valid`, |
| MaxItems: 1, |
| Elem: &schema.Resource{ |
| Schema: map[string]*schema.Schema{ |
| "enable_integrity_monitoring": { |
| Type: schema.TypeBool, |
| Optional: true, |
| ForceNew: true, |
| Description: `Defines whether the instance has integrity monitoring enabled. Enables monitoring and attestation of the |
| boot integrity of the instance. The attestation is performed against the integrity policy baseline. |
| This baseline is initially derived from the implicitly trusted boot image when the instance is created. |
| Enabled by default.`, |
| Default: true, |
| }, |
| "enable_secure_boot": { |
| Type: schema.TypeBool, |
| Optional: true, |
| ForceNew: true, |
| Description: `Defines whether the instance has Secure Boot enabled. Secure Boot helps ensure that the system only runs |
| authentic software by verifying the digital signature of all boot components, and halting the boot process |
| if signature verification fails. |
| Disabled by default.`, |
| }, |
| "enable_vtpm": { |
| Type: schema.TypeBool, |
| Optional: true, |
| ForceNew: true, |
| Description: `Defines whether the instance has the vTPM enabled. |
| Enabled by default.`, |
| Default: true, |
| }, |
| }, |
| }, |
| }, |
| "subnet": { |
| Type: schema.TypeString, |
| Computed: true, |
| Optional: true, |
| ForceNew: true, |
| DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, |
| Description: `The name of the subnet that this instance is in. |
| Format: projects/{project_id}/regions/{region}/subnetworks/{subnetwork_id}`, |
| }, |
| "tags": { |
| Type: schema.TypeList, |
| Optional: true, |
| ForceNew: true, |
| Description: `The Compute Engine tags to add to instance.`, |
| Elem: &schema.Schema{ |
| Type: schema.TypeString, |
| }, |
| }, |
| "vm_image": { |
| Type: schema.TypeList, |
| Optional: true, |
| ForceNew: true, |
| Description: `Use a Compute Engine VM image to start the notebook instance.`, |
| MaxItems: 1, |
| Elem: &schema.Resource{ |
| Schema: map[string]*schema.Schema{ |
| "project": { |
| Type: schema.TypeString, |
| Required: true, |
| ForceNew: true, |
| Description: `The name of the Google Cloud project that this VM image belongs to. |
| Format: projects/{project_id}`, |
| }, |
| "image_family": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| Description: `Use this VM image family to find the image; the newest image in this family will be used.`, |
| }, |
| "image_name": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| Description: `Use VM image name to find the image.`, |
| }, |
| }, |
| }, |
| ExactlyOneOf: []string{"vm_image", "container_image"}, |
| }, |
| "create_time": { |
| Type: schema.TypeString, |
| Computed: true, |
| Optional: true, |
| Description: `Instance creation time`, |
| }, |
| "proxy_uri": { |
| Type: schema.TypeString, |
| Computed: true, |
| Description: `The proxy endpoint that is used to access the Jupyter notebook. |
| Only returned when the resource is in a 'PROVISIONED' state. If |
| needed you can utilize 'terraform apply -refresh-only' to await |
| the population of this value.`, |
| }, |
| "state": { |
| Type: schema.TypeString, |
| Computed: true, |
| Description: `The state of this instance.`, |
| }, |
| "update_time": { |
| Type: schema.TypeString, |
| Computed: true, |
| Optional: true, |
| Description: `Instance update time.`, |
| }, |
| "project": { |
| Type: schema.TypeString, |
| Optional: true, |
| Computed: true, |
| ForceNew: true, |
| }, |
| }, |
| UseJSONNumber: true, |
| } |
| } |
| |
| func ResourceNotebooksInstanceUpgradeV0(_ context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { |
| return tpgresource.LabelsStateUpgrade(rawState, notebooksInstanceGoogleProvidedLabel) |
| } |