google::compute-instance-template

Creates an instance template.

Example

google::compute-instance-template instance-template-example
    name: "instance-template-example"
    description: "Instance template example"

    properties
        disk
            auto-delete: true
            boot: true

            initialize-params
                disk-name: "instance-template-example-disk-1"
                source-image: "projects/debian-cloud/global/images/family/debian-9"
            end
        end

        disk
            auto-delete: true
            boot: false

            initialize-params
                disk-name: "instance-template-example-disk-2"
                source-image: "projects/debian-cloud/global/images/family/debian-9"
            end
        end

        machine-type: "f1-micro"

        network-interface
            network: $(external-query google::compute-network {name: "default"})

            access-config
                name: "External NAT"
                type: "ONE_TO_ONE_NAT"
                network-tier: "PREMIUM"
            end
        end

        scheduling
            automatic-restart: true
            on-host-maintenance: "MIGRATE"
            preemptible: false
        end

        metadata: {
            test-key: "test-value"
        }

        tags: ["test-tag"]
    end
end

Attributes

Attribute Description
description Description of this resource.
name Name of the resource. Must be a string 1-63 characters long and the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash. Valid values satisfy the regex: [[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?]. (Required)
properties subresource

The instance properties for this instance template. Cannot be set if source-instance is set.

can-ip-forward

When set to true instances are created based on this template to send packets with source IP addresses other than their own and receive packets with destination IP addresses other than their own.

If these instances will be used as an IP gateway or it will be set as the next-hop in a Route resource, specify true.

description
Text description for the instances that are created from this instance template.
disk list subresource

List of disks that are associated with the instances that are created from this template. (Required)

auto-delete
When set to true the disk will be auto-deleted when the instance is deleted, but not when the disk is detached from the instance.
boot
When set to true, the virtual machine will use the first partition of the boot disk for its root filesystem.
device-name
Only for persistent disks, the unique device name reflected into the /dev/disk/by-id/google-* tree of a Linux operating system running within the instance. The name can then be used to reference the device for mounting, resizing, etc.. from within the instance. Unspecified the server chooses a default name in the form of persistent-disk-x, where x is a number assigned by Google Compute Engine.
disk-encryption-key subresource

When creating a new disk this field encrypts the new disk using the supplied encryption key. If attaching an existing disk already encrypted, this decrypts the disk using the supplied encryption key.||If you encrypt a disk using a customer-supplied key, you must provide the same key again when you attempt to use this resource at a later time.||If you do not provide an encryption key, then the disk will be encrypted using an automatically generated key and you do not need to provide a key to use the disk later. Instance templates do not store customer-supplied encryption keys, so you cannot use your own keys to encrypt disks in a managed instance group.

raw-key
The 256-bit encryption key, encoded in RFC 4648 base64, that protects this resource. See Encrypt disks with customer-supplied encryption keys. (Required)
guest-os-feature list subresource

List of features to enable on the guest operating system. Applicable only for bootable images. See `enabling guest operating system features<https://cloud.google.com/compute/docs/images/create-delete-deprecate-private-images#guest-os-features/>`_.

type
Enables one or more features for VM instances that use the image for their boot disks. Valid values are FEATURE_TYPE_UNSPECIFIED, MULTI_IP_SUBNET, SECURE_BOOT, UEFI_COMPATIBLE, VIRTIO_SCSI_MULTIQUEUE or WINDOWS. See Enabling guest operating system features.
initialize-params subresource

Parameters for a new disk that will be created alongside the new instance. Use initialization parameters to create boot disks or local SSDs attached to the new instance. Cannot be set if source is set.

source-image
The source image to create this disk in the form of a URL path. See Images. (Required)
description
An optional description. Provide this property when creating the disk.
disk-name
The disk name. If the disk with the instance name exists already in the given zone/region a new name will be automatically generated. Must be a string 1-63 characters long and the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash. Valid values satisfy the regex: [(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?)]. (Required)
disk-size-gb
Size of the disk in base-2 GB. Unspecified, the disk will be the same size as the image (usually 10GB). If specified, the size must be equal to or larger than 10GB.
disk-type
The disk type to use to create the instance. Unspecified, the default is pd-standard, specified using the full URL (e.g. https://www.googleapis.com/compute/v1/projects/project/zones/zone/diskTypes/pd-standard). Other values include pd-ssd and local-ssd. Provide either the full or partial URL. Note that for InstanceTemplate, this is the name of the disk type, not URL.
labels map
Labels to apply to this disk. Only applicable for persistent disks.
source-image-encryption-key subresource

Encryption key of the source image. Required if the source image is protected by a customer-supplied encryption key. Instance templates do not store customer-supplied encryption keys, so you cannot create disks or instances in a managed instance group if the source images are encrypted with your own keys.

raw-key
The 256-bit encryption key, encoded in RFC 4648 base64, that protects this resource. See Encrypt disks with customer-supplied encryption keys. (Required)
source-snapshot-encryption-key subresource

Encryption key of the source snapshot.

raw-key
The 256-bit encryption key, encoded in RFC 4648 base64, that protects this resource. See Encrypt disks with customer-supplied encryption keys. (Required)
resource-policy list
Resource policies applied to this disk for automatic snapshot creations.
auto-generate-disk-name
If set to true, uses an autogenerated disk name instead of the one provided. Defaults to false.
disk-interface
Disk interface to use for attaching this disk. Default is SCSI. Persistent disks must always use SCSI and the request will fail if you attempt to attach a persistent disk in any other format than SCSI. Valid values are SCSI or NVME.
mode
The mode in which to attach this disk. Default is READ_WRITE. Valid values are READ_WRITE or READ_ONLY.
source resource

The Persistent Disk resource. Cannot be set if initializeParams is set.

type
Type of the disk, Default is PERSISTENT. Valid values are SCRATCH or PERSISTENT.
guest-accelerator list subresource

List of guest accelerator card type and count to use for instances created from the instance template.

accelerator-count
The number of the guest accelerator cards exposed to this instance. (Required)
accelerator-type

Full or partial URL of the accelerator type resource to attach to this instance.

For example: projects/my-project/zones/us-central1-c/acceleratorTypes/nvidia-tesla-p100 If you are creating an instance template, specify only the accelerator name. (Required)

labels map
Labels to apply to instances that are created from this template.
machine-type
The machine type to use for instances that are created from this template. (Required)
metadata map

The metadata key/value pairs to assign to instances that are created from this template.

Keys may only contain alphanumeric characters, dashes, and underscores, and must be 1-128 characters in length. Values must be 0-262144 characters in length.

min-cpu-platform

Minimum cpu/platform to be used by this instance.

The instance may be scheduled on the specified or newer cpu/platform. Applicable values are the friendly names of CPU platforms, such as Intel Haswell or Intel Sandy Bridge.

network-interface list subresource

List of network access configurations for this interface. (Required)

network resource

Network for this instance. If neither the network or subnetwork is specified, the default network global/networks/default is used and if the network is not specified but the subnetwork is specified, the network is inferred. (Required)

subnetwork resource

Subnetwork for this instance. If the network resource is in legacy mode, do not specify this field. If the network is in auto subnet mode, specifying the subnetwork is optional. If the network is in custom subnet mode, specifying the subnetwork is required.

network-ip
An IPv4 internal IP address to assign for this network interface. If unspecified an unused internal IP is assigned.
access-config list subresource

A list of access configurations for this interface. Currently, only NE_TO_ONE_NAT is supported. If unspecified this instance will have no external internet access.

name
Name of this access configuration. Default and recommended name is External NAT, but can be any arbitrary string.
nat-ip
An unused static external IP address available to the project. Leave this field undefined to use an IP from a shared ephemeral IP address pool. If you specify a static external IP address, it must live in the same region as the zone of the instance.
network-tier
Signifies the networking tier used for configuring this access configuration. If specified without a valid external IP address, an ephemeral IP will be created with this networkTier. If a valid external IP address is specified, it must match that of the networkTier associated with the Address resource owning that IP. Valid values are PREMIUM or STANDARD.
public-ptr-domain-name
The DNS domain name for the public PTR record. Can only be set if the setPublicPtr field is set to true.
set-public-ptr
if true a public DNS ‘PTR’ record should be created to map the external IP address of the instance to a DNS domain name.
type
The type of configuration. Defaults to ONE_TO_ONE_NAT. Currently the only supported value is ONE_TO_ONE_NAT.
alias-ip-range list subresource

A list of alias IP ranges for this network interface. Can only specify this for network interfaces in VPC networks.

ip-cidr-range
The IP alias ranges to allocate for this interface. This IP CIDR range must belong to the specified subnetwork and cannot contain IP addresses reserved by system or used by other network interfaces. This range may be a single IP address (e.g. 10.2.3.4), a netmask (e.g. /24) or a CIDR-formatted string (e.g. 10.1.2.0/24).
subnetwork-range-name
Name given to a subnetwork secondary IP range for use in allocating the IP alias range. Unspecified the primary range of the subnetwork is used.
fingerprint
Fingerprint hash of contents stored in this network interface. Will be ignored when inserting an Instance or adding a NetworkInterface. An up-to-date fingerprint must be provided in order to update the NetworkInterface, otherwise the request will fail with HTTP error 412.
reservation-affinity subresource

Specifies the reservations that this instance can consume from.

consume-reservation-type

Specifies the type of reservation from which this instance can consume resources.

Valid values are:

  • ANY_RESERVATION (default)
  • SPECIFIC_RESERVATION
  • NO_RESERVATION Valid values are ANY_RESERVATION, SPECIFIC_RESERVATION or NO_RESERVATION.
key

Corresponds to the label key of a reservation resource.

To target a SPECIFIC_RESERVATION by name, specify googleapis.com/reservation-name as the key and specify the name of your reservation as its value. (Required)

values list
Corresponds to the label values of a reservation resource. (Required)
scheduling subresource

Specifies the scheduling options for the instances that are created from this template.

automatic-restart

Specifies whether the instance should be automatically restarted if it is terminated by Compute Engine (not terminated by a user).

You can only set the automatic restart option for standard instances. Preemptible instances cannot be automatically restarted. By default, this is set to true so an instance is automatically restarted if it is terminated by Compute Engine.

node-affinity list subresource

List of node affinity and anti-affinity configurations.

key
Corresponds to the label key of Node resource. (Required)
operator
Defines the operation of node selection. Valid values are IN or NOT_IN.
values list
Corresponds to the label values of Node resource.
on-host-maintenance

Defines the maintenance behavior for this instance.

For standard instances, the default behavior is MIGRATE. For preemptible instances, the default and only possible behavior is TERMINATE.

preemptible

Defines whether the instance is preemptible.

This can only be set during instance creation, it cannot be set or changed after the instance has been created.

service-account list subresource

List of service accounts with specified scopes.

Access tokens for these service accounts are available to the instances that are created from this template. Use metadata queries to obtain the access tokens for these instances.

service-account
The service account. (Required)
scopes list
List of scopes to be made available for this service account.
shielded-instance-config subresource

Configuration for shielded instance.

enable-integrity-monitoring
Defines whether the instance has integrity monitoring enabled.
enable-secure-boot
Defines whether the instance has Secure Boot enabled.
enable-vtpm
Defines whether the instance has the vTPM enabled.
tags list

Tags to apply to the instances that are created from this template.

The tags identify valid sources or targets for network firewalls. Maximum allowed items are 64. Must be a string with only dashes, lowercase letters, or digits. The first character must be a lowercase letter, and the last character cannot be a dash. Each tag must be 1-63 characters. Valid values satisfy the regex: [^[a-z]([-a-z0-9]{0,61}[a-z0-9]$)?].

source-instance resource

The source instance used to create the template. Cannot be set if properties is set.

source-instance-params subresource

The source instance params to use to create this instance template. Can only be set if source-instance is set.

disk-config list subresource

List of attached disks configuration.

For boot disk and any other R/W disks, new custom images will be created from each disk. For read-only disks, they will be attached in read-only mode. Local SSD disks will be created as blank volumes. (Required)

auto-delete
Specifies whether the disk will be auto-deleted when the instance is deleted, but not when the disk is detached from the instance.
custom-image
The custom source image to be used to restore this disk when instantiating this instance template.
device-name
Specifies the device name of the disk to which the configurations apply to. (Required)
instantiate-from

Specifies whether to include the disk and what image to use.

Possible values are:

  • source-image: to use the same image that was used to create the source instance’s corresponding disk. Applicable to the boot disk and additional read-write disks.
  • source-image-family: to use the same image family that was used to create the source instance’s corresponding disk. Applicable to the boot disk and additional read-write disks.
  • custom-image: to use a user-provided image url for disk creation. Applicable to the boot disk and additional read-write disks.
  • attach-read-only: to attach a read-only disk. Applicable to read-only disks.
  • do-not-include: to exclude a disk from the template. Applicable to additional read-write disks, local SSDs, and read-only disks. Valid values are source-image, source-image-family, custom-image, attach-read-only or do-not-include.

Outputs

Attribute Description
self-link The URL for this instance template. The server defines this URL.