Search code examples
google-compute-enginegcloud

Create compute engine from instance-template using gcloud CLI


I want to create a compute engine from a instance-template using the gcloud CLI. I have created a instance template named it-collector-server. When I try to create a server with the instance template I get a error: The resource 'projects/s-dev/global/instanceTemplates/it-collector-server' was not found. What causes this error and how can I fix it?

I have one instance template:

gcloud compute instance-templates list

NAME                 MACHINE_TYPE  PREEMPTIBLE  CREATION_TIMESTAMP
it-collector-server  e2-medium                  2024-04-30T03:01:14.759-07:00

This is the full information about the template:

gcloud compute instance-templates list --format=json

gcloud compute instance-templates list --format=json
[
  {
    "creationTimestamp": "2024-04-30T03:01:14.759-07:00",
    "description": "",
    "id": "12345",
    "kind": "compute#instanceTemplate",
    "name": "it-collector-server",
    "properties": {
      "canIpForward": false,
      "confidentialInstanceConfig": {
        "enableConfidentialCompute": false
      },
      "description": "",
      "disks": [
        {
          "autoDelete": true,
          "boot": true,
          "deviceName": "it-collector-server",
          "index": 0,
          "initializeParams": {
            "diskSizeGb": "10",
            "diskType": "pd-balanced",
            "sourceImage": "projects/ubuntu-os-cloud/global/images/ubuntu-2004-focal-v20240426"
          },
          "kind": "compute#attachedDisk",
          "mode": "READ_WRITE",
          "type": "PERSISTENT"
        }
      ],
      "keyRevocationActionType": "NONE",
      "machineType": "e2-medium",
      "metadata": {
        "fingerprint": "i9go6u23i84=",
        "kind": "compute#metadata"
      },
      "networkInterfaces": [
        {
          "accessConfigs": [
            {
              "kind": "compute#accessConfig",
              "name": "External NAT",
              "networkTier": "PREMIUM",
              "type": "ONE_TO_ONE_NAT"
            }
          ],
          "kind": "compute#networkInterface",
          "name": "nic0",
          "network": "https://www.googleapis.com/compute/v1/projects/s-dev/global/networks/default",
          "stackType": "IPV4_ONLY"
        }
      ],
      "reservationAffinity": {
        "consumeReservationType": "ANY_RESERVATION"
      },
      "scheduling": {
        "automaticRestart": true,
        "onHostMaintenance": "MIGRATE",
        "preemptible": false,
        "provisioningModel": "STANDARD"
      },
      "serviceAccounts": [
        {
          "email": "[email protected]",
          "scopes": [
            "https://www.googleapis.com/auth/devstorage.read_only",
            "https://www.googleapis.com/auth/logging.write",
            "https://www.googleapis.com/auth/monitoring.write",
            "https://www.googleapis.com/auth/servicecontrol",
            "https://www.googleapis.com/auth/service.management.readonly",
            "https://www.googleapis.com/auth/trace.append"
          ]
        }
      ],
      "shieldedInstanceConfig": {
        "enableIntegrityMonitoring": true,
        "enableSecureBoot": false,
        "enableVtpm": true
      },
      "tags": {}
    },
    "region": "https://www.googleapis.com/compute/v1/projects/s-dev/regions/europe-north1",
    "selfLink": "https://www.googleapis.com/compute/v1/projects/s-dev/regions/europe-north1/instanceTemplates/it-collector-server"
  }
]

Now I want to create a compute engine using the instance template:

gcloud compute instances create my-test-vm --source-instance-template=it-collector-server

ERROR: (gcloud.compute.instances.create) Could not fetch resource:
 - The resource 'projects/s-dev/global/instanceTemplates/it-collector-server' was not found

Solution

  • You might want to double check the region.I know that it shows on the template but try specifying the region explicitly when creating the instance using the --region flag.

    gcloud compute instances create my-test-vm --source-instance-template=it-collector-server --region=europe-north1