Get information about a VM instance template resource within GCE. For more information see the official documentation and API.
# by name
data "google_compute_region_instance_template" "generic" {
name = "generic-tpl-20200107"
}
# using a filter
data "google_compute_region_instance_template" "generic-regex" {
filter = "name != generic-tpl-20200107"
most_recent = true
}
The following arguments are supported:
name
- (Optional) The name of the instance template. One of name
or filter
must be provided.
filter
- (Optional) A filter to retrieve the instance templates.
See gcloud topic filters for reference.
If multiple instance templates match, either adjust the filter or specify most_recent
. One of name
or filter
must be provided.
most_recent
- (Optional) If filter
is provided, ensures the most recent template is returned when multiple instance templates match. One of name
or filter
must be provided.
project
- (Optional) The ID of the project in which the resource belongs.
If project
is not provided, the provider project is used.
region
- (Optional) The Region in which the resource belongs.
If region
is not provided, the provider region is used.
disk
- Disks to attach to instances created from this template.
This can be specified multiple times for multiple disks. Structure is
documented below.
machine_type
- The machine type to create.
To create a machine with a [custom type][custom-vm-types] (such as extended memory), format the value like custom-VCPUS-MEM_IN_MB
like custom-6-20480
for 6 vCPU and 20GB of RAM.
name
- The name of the instance template. If you leave
this blank, Terraform will auto-generate a unique name.
name_prefix
- Creates a unique name beginning with the specified
prefix. Conflicts with name
.
can_ip_forward
- Whether to allow sending and receiving of
packets with non-matching source or destination IPs. This defaults to false.
description
- A brief description of this resource.
instance_description
- A brief description to use for instances
created from this template.
labels
- A set of key/value label pairs to assign to instances
created from this template,
metadata
- Metadata key/value pairs to make available from
within instances created from this template.
metadata_startup_script
- An alternative to using the
startup-script metadata key, mostly to match the compute_instance resource.
This replaces the startup-script metadata key on the created instance and
thus the two mechanisms are not allowed to be used simultaneously.
network_interface
- Networks to attach to instances created from
this template. This can be specified multiple times for multiple networks.
Structure is documented below.
network_performance_config
- The network performance configuration setting
for the instance, if set. Structure is documented below.
project
- The ID of the project in which the resource belongs. If it
is not provided, the provider project is used.
scheduling
- The scheduling strategy to use. More details about
this configuration option are detailed below.
service_account
- Service account to attach to the instance. Structure is documented below.
tags
- Tags to attach to the instance.
guest_accelerator
- List of the type and count of accelerator cards attached to the instance. Structure documented below.
min_cpu_platform
- Specifies a minimum CPU platform. Applicable values are the friendly names of CPU platforms, such as
Intel Haswell
or Intel Skylake
. See the complete list here.
shielded_instance_config
- Enable Shielded VM on this instance. Shielded VM provides verifiable integrity to prevent against malware and rootkits. Defaults to disabled. Structure is documented below.
Note: shielded_instance_config
can only be used with boot images with shielded vm support. See the complete list here.
enable_display
- Enable Virtual Displays on this instance.
Note: allow_stopping_for_update
must be set to true in order to update this field.
confidential_instance_config
- Enable Confidential Mode on this VM. Structure is documented below
auto_delete
- Whether or not the disk should be auto-deleted.
This defaults to true.
boot
- Indicates that this is a boot disk.
device_name
- A unique device name that is reflected into the
/dev/ tree of a Linux operating system running within the instance. If not
specified, the server chooses a default device name to apply to this disk.
disk_name
- Name of the disk. When not provided, this defaults
to the name of the instance.
provisioned_iops
- Indicates how many IOPS to provision for the disk. This
sets the number of I/O operations per second that the disk can handle.
Values must be between 10,000 and 120,000. For more details, see the
Extreme persistent disk documentation.
source_image
- The image from which to
initialize this disk. This can be one of: the image's self_link
,
projects/{project}/global/images/{image}
,
projects/{project}/global/images/family/{family}
, global/images/{image}
,
global/images/family/{family}
, family/{family}
, {project}/{family}
,
{project}/{image}
, {family}
, or {image}
.
interface
- Specifies the disk interface to use for attaching this disk,
which is either SCSI or NVME. The 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. Local SSDs can use either NVME or SCSI.
mode
- The mode in which to attach this disk, either READ_WRITE
or READ_ONLY. If you are attaching or creating a boot disk, this must
read-write mode.
source
- The name (not self_link)
of the disk (such as those managed by google_compute_disk
) to attach.
disk_type
- The GCE disk type. Such as "pd-ssd"
, "local-ssd"
,
"pd-balanced"
or "pd-standard"
.
disk_size_gb
- The size of the image in gigabytes. If not
specified, it will inherit the size of its base image. For SCRATCH disks,
the size must be exactly 375GB.
labels
- (Optional) A set of ket/value label pairs to assign to disk created from
this template
type
- The type of GCE disk, can be either "SCRATCH"
or
"PERSISTENT"
.
disk_encryption_key
- Encrypts or decrypts a disk using a customer-supplied encryption key.
If you are creating a new disk, this field encrypts the new disk using an encryption key that you provide. If you are attaching an existing disk that is already encrypted, this field decrypts the disk using the customer-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. For example, you must provide the key when you create a snapshot or an image from the disk or when you attach the disk to a virtual machine instance.
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.
resource_policies
(Optional) -- A list of short names of resource policies to attach to this disk for automatic snapshot creations. Currently a max of 1 resource policy is supported.
The disk_encryption_key
block supports:
kms_key_self_link
- The self link of the encryption key that is stored in Google Cloud KMSThe network_interface
block supports:
network
- The name or self_link of the network to attach this interface to.
Use network
attribute for Legacy or Auto subnetted networks and
subnetwork
for custom subnetted networks.
subnetwork
- the name of the subnetwork to attach this interface
to. The subnetwork must exist in the same region
this instance will be
created in. Either network
or subnetwork
must be provided.
subnetwork_project
- The ID of the project in which the subnetwork belongs.
If it is not provided, the provider project is used.
network_ip
- The private IP address to assign to the instance. If
empty, the address will be automatically assigned.
access_config
- Access configurations, i.e. IPs via which this
instance can be accessed via the Internet. Omit to ensure that the instance
is not accessible from the Internet (this means that ssh provisioners will
not work unless you are running Terraform can send traffic to the instance's
network (e.g. via tunnel or because it is running on another cloud instance
on that network). This block can be repeated multiple times. Structure documented below.
alias_ip_range
- An
array of alias IP ranges for this network interface. Can only be specified for network
interfaces on subnet-mode networks. Structure documented below.
The access_config
block supports:
nat_ip
- The IP address that will be 1:1 mapped to the instance's
network ip. If not given, one will be generated.
network_tier
- The [networking tier][network-tier] used for configuring
this instance template. This field can take the following values: PREMIUM or
STANDARD. If this field is not specified, it is assumed to be PREMIUM.
The alias_ip_range
block supports:
ip_cidr_range
- The IP CIDR range represented by this alias IP range. This IP CIDR range
must belong to the specified subnetwork and cannot contain IP addresses reserved by
system or used by other network interfaces. At the time of writing only a
netmask (e.g. /24) may be supplied, with a CIDR format resulting in an API
error.
subnetwork_range_name
- The subnetwork secondary range name specifying
the secondary range from which to allocate the IP CIDR range for this alias IP
range. If left unspecified, the primary range of the subnetwork will be used.
The service_account
block supports:
email
- The service account e-mail address. If not given, the
default Google Compute Engine service account is used.
scopes
- A list of service scopes. Both OAuth2 URLs and gcloud
short names are supported. To allow full access to all Cloud APIs, use the
cloud-platform
scope. See a complete list of scopes here.
The service accounts documentation explains that access scopes are the legacy method of specifying permissions for your instance. If you are following best practices and using IAM roles to grant permissions to service accounts, then you can define this field as an empty list.
The scheduling
block supports:
automatic_restart
- Specifies whether the instance should be
automatically restarted if it is terminated by Compute Engine (not
terminated by a user). This defaults to true.
on_host_maintenance
- Defines the maintenance behavior for this
instance.
preemptible
- Allows instance to be preempted. This defaults to
false. Read more on this
here.
node_affinities
- Specifies node affinities or anti-affinities
to determine which sole-tenant nodes your instances and managed instance
groups will use as host systems. Read more on sole-tenant node creation
here.
Structure documented below.
provisioning_model
- Describe the type of preemptible VM.
instance_termination_action
- Describe the type of termination action for SPOT
VM. Can be STOP
or DELETE
. Read more on here
The guest_accelerator
block supports:
type
- The accelerator type resource to expose to this instance. E.g. nvidia-tesla-k80
.
count
- The number of the guest accelerator cards exposed to this instance.
The node_affinities
block supports:
key
- The key for the node affinity label.
operator
- The operator. Can be IN
for node-affinities
or NOT_IN
for anti-affinities.
value
- The values for the node affinity label.
The shielded_instance_config
block supports:
enable_secure_boot
-- Verify the digital signature of all boot components, and halt the boot process if signature verification fails. Defaults to false.
enable_vtpm
-- Use a virtualized trusted platform module, which is a specialized computer chip you can use to encrypt objects like keys and certificates. Defaults to true.
enable_integrity_monitoring
-- Compare the most recent boot measurements to the integrity policy baseline and return a pair of pass/fail results depending on whether they match or not. Defaults to true.
The confidential_instance_config
block supports:
enable_confidential_compute
Defines whether the instance should have confidential compute enabled. on_host_maintenance
has to be set to TERMINATE or this will fail to create the VM.The network_performance_config
block supports:
total_egress_bandwidth_tier
- The egress bandwidth tier for the instance.id
- an identifier for the resource with format projects/{{project}}/regions/{{region}}/instanceTemplates/{{name}}
metadata_fingerprint
- The unique fingerprint of the metadata.
self_link
- The URI of the created resource.
tags_fingerprint
- The unique fingerprint of the tags.