1 Answers
There is an additional I would like to consider as part of this lecture. On the final slide, the "Key Takeaways", Mattias comments:
>> Even via CLI — Can create Instance Template via CLI, too
As I got myself curious, I went to test.
Instance Templates are global and can be used to create VMs everywhere. Unless it were created having zonal dependencies like a persistent disk in us-central1-a, you wouldn’t be able to create a VM template-based in the us-west1-b, as mentioned below.
An instance template is a global resource that is not bound to a zone or a region. However, you will specify some zonal resources in an instance template, which restricts the template to the zone where that resource resides. For example, if you include a read-only persistent disk from us-central1-b in your instance template, you cannot use that template in any other zone because that specific disk exists only in zone us-central1-b (https://cloud.google.com/compute/docs/instance-templates/).
The curiosity here is how to create a VM based on a template and then:
pimballeke@cloudshell:~$ gcloud config set project optimistic-leaf-265401
Updated property [core/project].
pimballeke@cloudshell:~ (optimistic-leaf-265401)$ gcloud compute instance-templates list
NAME MACHINE_TYPE PREEMPTIBLE CREATION_TIMESTAMP
worker-instance-template f1-micro 2020-01-25T11:10:20.270-08:00
pimballeke@cloudshell:~ (optimistic-leaf-265401)$ gcloud compute instances create mybrandnewvm --source-instance-template worker-instance-template
Did you mean zone [us-east1-c] for instance: [mybrandnewvm] (Y/n)? Y
Created [https://www.googleapis.com/compute/v1/projects/optimistic-leaf-265401/zones/us-east1-c/instances/mybrandnewvm].
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
mybrandnewvm us-east1-c f1-micro 10.142.0.3 35.196.53.11 RUNNING
pimballeke@cloudshell:~ (optimistic-leaf-265401)$ gcloud compute instances delete mybrandnewvm --zone us-east1-c The following instances will be deleted. Any attached disks configured
to be auto-deleted will be deleted unless they are attached to any
other instances or the `--keep-disks` flag is given and specifies them
for keeping. Deleting a disk is irreversible and any data on the disk
will be lost.
- [mybrandnewvm] in [us-east1-c]
Do you want to continue (Y/n)? Y
Deleted [https://www.googleapis.com/compute/v1/projects/optimistic-leaf-265401/zones/us-east1-c/instances/mybrandnewvm].
Of course, we can explore more possibilities here, but this is just the beginning.