1
votes

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. For more information about zonal resources, read >Regions and Zones.
https://cloud.google.com/compute/docs/instance-templates/

I would like to confirm the above phenomenon. What procedure can we reproduce.
Especially the following part you will specify some zonal resources in an >instance template, which restricts the template to the zone

However, I do not know how to reproduce it. GCP's web console and gcloud compute create-templates create command did not find a command to specify a zone.

1

1 Answers

1
votes

As mentioned in the document [1] referenced in your post. “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.” You have two options in regards to procedures on selecting zonal resources on an instance template.

If you are creating an instance template from scratch, please note that without altering the initial configuration, all default settings will be used as its been considered a global resource. However, should you want it only accessible from a specific zone, then see the following example:

  • Create a disk located in Zone: us-east4-a.
  • Create an instance template with that attached disk.
  • Create a VM or Manage Instance Group (MIG) with that template.
  • As this template is tagged to resources in the “us-east4-a” zone, please note that you cannot locate that VM instance in a different zone other than the location of where the disk is located.
  • Your only options are to change the zone to its corresponding disk location or detach the disks entirely.

Secondly, if you are creating an instance template based on an existing instance, you can look at the following document [2] or look at the command below.

  • Follow the gcloud command below and modify the field “--source-instance-zone=” with the desired zone of choice and fill the rest of the fields with the proper information.

    gcloud compute instance-templates create [INSTANCE_TEMPLATE_NAME] \
      --source-instance=[SOURCE_INSTANCE] \
      --source-instance-zone=[SOURCE_INSTANCE_ZONE] \
      [--configure-disk= \
        device-name=[SOURCE_DISK], \
        instantiate-from=[INSTANTIATE_FROM], \
        auto-delete=[AUTO_DELETE]]