Skip to content

Instantly share code, notes, and snippets.

@caetano-colin
Last active May 2, 2024 20:24
Show Gist options
  • Save caetano-colin/02e66f73af472e6a6f9c141e577a65af to your computer and use it in GitHub Desktop.
Save caetano-colin/02e66f73af472e6a6f9c141e577a65af to your computer and use it in GitHub Desktop.
Experiment

Copy JSON body from terraform DEBUG Output and save to body.json file. Change networkInterfaces.network value to the documented API format.

Changed from https://compute.googleapis.com/compute/v1/projects/prj-d-shared-restricted-9enw/global/networks/vpc-d-shared-restricted to projects/prj-d-shared-restricted-9enw/global/networks/vpc-d-shared-restricted see original request on this link: https://gist.github.com/caetano-colin/8435956b49b1eb761ac51653f1727f58

{
 "gceSetup": {
  "bootDisk": {
   "diskEncryption": "CMEK",
   "diskSizeGb": "150",
   "diskType": "PD_SSD",
   "kmsKey": "projects/prj-d-kms-3i3k/locations/us-central1/keyRings/sample-keyring/cryptoKeys/prj-d-bu3machine-learning"
  },
  "dataDisks": [
   {
    "diskEncryption": "CMEK",
    "diskSizeGb": "150",
    "diskType": "PD_SSD",
    "kmsKey": "projects/prj-d-kms-3i3k/locations/us-central1/keyRings/sample-keyring/cryptoKeys/prj-d-bu3machine-learning"
   }
  ],
  "disablePublicIp": true,
  "machineType": "e2-standard-4",
  "metadata": {
   "disable-mixer": "false",
   "notebook-disable-downloads": "true",
   "notebook-disable-root": "true",
   "notebook-disable-terminal": "true",
   "notebook-upgrade-schedule": "00 19 * * MON",
   "report-dns-resolution": "true",
   "report-event-health": "true",
   "terraform": "true"
  },
  "networkInterfaces": [
   {
    "network": "projects/prj-d-shared-restricted-9enw/global/networks/vpc-d-shared-restricted",
    "subnet": "projects/prj-d-shared-restricted-9enw/regions/us-central1/subnetworks/sb-d-shared-restricted-us-central1"
   }
  ],
  "shieldedInstanceConfig": null,
  "tags": [
   "egress-internet"
  ],
  "vmImage": {
   "family": "workbench-instances",
   "project": "cloud-notebooks-managed"
  }
 },
 "labels": {
  "boundry_code": "001",
  "environment": "development"
 }
}

Make the request using curl

curl "https://notebooks.googleapis.com/v2/projects/prj-d-bu3machine-learning-ma6i/locations/us-central1-a/instances?alt=json&instanceId=test-ml-instance" \
  -H "User-Agent: Terraform/1.7.5 (+https://www.terraform.io) Terraform-Plugin-SDK/2.33.0 terraform-provider-google/5.25.0" \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type: application/json" \
  -d @body.json

This is the output (HTTP 200 OK):

{
  "name": "projects/prj-d-bu3machine-learning-ma6i/locations/us-central1-a/operations/operation-1714680397365-6177e23fd00be-9d5dc76c-0835a2e7",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.notebooks.v2.OperationMetadata",
    "createTime": "2024-05-02T20:06:38.928450327Z",
    "target": "projects/prj-d-bu3machine-learning-ma6i/locations/us-central1-a/instances/test-ml-instance",
    "verb": "create",
    "requestedCancellation": false,
    "apiVersion": "v2",
    "endpoint": "CreateInstance"
  },
  "done": false
}

Output of command gcloud compute instances list --project=prj-d-bu3machine-learning-ma6i

NAME              ZONE           MACHINE_TYPE   PREEMPTIBLE  INTERNAL_IP  EXTERNAL_IP  STATUS
test-ml-instance  us-central1-a  e2-standard-4               10.9.64.58                RUNNING
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment