This Terraform module provides infrastructure configuration for creating a Template-Instance in Google Cloud Platform (GCP) along with vpc subnets, firewall rules . It's designed to be used for managing network resources in a GCP environment.
To use this module, include it in your Terraform configuration. Below is an example of how to call the template-instance module and its dependencies.
data "google_compute_instance_template" "generic" {
name = "template-test-020230919082713685100000001"
}
module "compute_instance" {
source = "cypik/template-instance/google"
version = "1.0.1"
name = "instance"
environment = "test"
region = "asia-northeast1"
zone = "asia-northeast1-a"
subnetwork = module.subnet.subnet_id
instance_from_template = true
deletion_protection = false
service_account = null
## public IP if enable_public_ip is true
enable_public_ip = true
source_instance_template = data.google_compute_instance_template.generic.self_link
}
module "instance_template" {
source = "cypik/template-instance/google"
version = "1.0.1"
name = "template"
environment = "test"
region = "asia-northeast1"
source_image = "ubuntu-2204-jammy-v20230908"
source_image_family = "ubuntu-2204-lts"
source_image_project = "ubuntu-os-cloud"
disk_size_gb = "20"
subnetwork = module.subnet.subnet_id
instance_template = true
service_account = null
## public IP if enable_public_ip is true
enable_public_ip = true
metadata = {
ssh-keys = <<EOF
dev:ssh-rsa AAAAB3NzaC1yc2EAA/3mwt2y+PDQMU= suresh@suresh
EOF
}
}
# compute-instance
module "compute_instance" {
source = "cypik/template-instance/google"
version = "1.0.1"
name = "instance"
environment = "test"
region = "asia-northeast1"
zone = "asia-northeast1-a"
subnetwork = module.subnet.subnet_id
instance_from_template = true
deletion_protection = false
service_account = null
## public IP if enable_public_ip is true
enable_public_ip = true
source_instance_template = module.instance_template.self_link_unique
}
This example demonstrates how to create various GCP resources using the provided modules. Adjust the input values to suit your specific requirements.
For detailed examples on how to use this module, please refer to the Examples directory within this repository.
This Terraform module is provided under the MIT License. Please see the LICENSE file for more details.
Your Name Replace MIT and Cypik with the appropriate license and your information. Feel free to expand this README with additional details or usage instructions as needed for your specific use case.
Name | Version |
---|---|
terraform | >= 1.6.6 |
>= 3.50, < 5.11.0 |
Name | Version |
---|---|
>= 3.50, < 5.11.0 |
Name | Source | Version |
---|---|---|
labels | cypik/labels/google | 1.0.1 |
Name | Type |
---|---|
google_compute_instance_from_template.compute_instance | resource |
google_compute_instance_template.tpl | resource |
google_client_config.current | data source |
google_compute_zones.available | data source |
Name | Description | Type | Default | Required |
---|---|---|---|---|
additional_disks | List of maps of additional disks. See https://www.terraform.io/docs/providers/google/r/compute_instance_template#disk_name | list(object({ |
[] |
no |
additional_networks | Additional network interface details for GCE, if any. | list(object({ |
[] |
no |
alias_ip_range | An array of alias IP ranges for this network interface. Can only be specified for network interfaces on subnet-mode networks. 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. |
object({ |
null |
no |
alias_ip_ranges | (Optional) An array of alias IP ranges for this network interface. Can only be specified for network interfaces on subnet-mode networks. | list(object({ |
[] |
no |
auto_delete | Whether or not the boot disk should be auto-deleted | string |
"true" |
no |
automatic_restart | (Optional) Specifies whether the instance should be automatically restarted if it is terminated by Compute Engine (not terminated by a user). | bool |
true |
no |
can_ip_forward | Enable IP forwarding, for NAT instances for example | string |
"false" |
no |
deletion_protection | Enable deletion protection on this instance. Note: you must disable deletion protection before removing the resource, or the instance cannot be deleted and the Terraform run will not complete successfully. | bool |
false |
no |
disk_encryption_key | The id of the encryption key that is stored in Google Cloud KMS to use to encrypt all the disks on this instance | string |
null |
no |
disk_labels | Labels to be assigned to boot disk, provided as a map | map(string) |
{} |
no |
disk_size_gb | Boot disk size in GB | string |
"20" |
no |
disk_type | Boot disk type, can be either pd-ssd, local-ssd, or pd-standard | string |
"" |
no |
enable_confidential_vm | Whether to enable the Confidential VM configuration on the instance. Note that the instance image must support Confidential VMs. See https://cloud.google.com/compute/docs/images | bool |
false |
no |
enable_nested_virtualization | Defines whether the instance should have nested virtualization enabled. | bool |
false |
no |
enable_public_ip | Predefined enable_public_ip address for the instance. | bool |
false |
no |
enable_shielded_vm | Whether to enable the Shielded VM configuration on the instance. Note that the instance image must support Shielded VMs. See https://cloud.google.com/compute/docs/images | bool |
false |
no |
environment | Environment (e.g. prod , dev , staging ). |
string |
"" |
no |
gpu | GPU information. Type and count of GPU to attach to the instance template. See https://cloud.google.com/compute/docs/gpus more details | object({ |
null |
no |
instance_from_template | Set to true if instances should be created from the specified instance template, false otherwise. | bool |
false |
no |
instance_template | Instance template self_link used to create compute instances | bool |
false |
no |
ipv6_access_config | IPv6 access configurations. Currently a max of 1 IPv6 access configuration is supported. If not specified, the instance will have no external IPv6 Internet access. | list(object({ |
[] |
no |
label_order | Label order, e.g. sequence of application name and environment name ,environment ,'attribute' [webserver ,qa ,devops ,public ,] . |
list(any) |
[ |
no |
labels | Labels, provided as a map | map(string) |
{} |
no |
machine_type | Machine type to create, e.g. n1-standard-1 | string |
"e2-small" |
no |
managedby | ManagedBy, eg 'cypik'. | string |
"cypik" |
no |
metadata | Metadata, provided as a map | map(string) |
{} |
no |
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: https://cloud.google.com/compute/docs/instances/specify-min-cpu-platform | string |
null |
no |
name | Name of the resource. Provided by the client when the resource is created. | string |
"test" |
no |
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. | string |
"" |
no |
network_ip | Private IP address to assign to the instance if desired. | string |
"" |
no |
on_host_maintenance | Instance availability Policy | string |
"MIGRATE" |
no |
preemptible | Allow the instance to be preempted | bool |
false |
no |
region | Region where the instance template should be created. | string |
null |
no |
repository | Terraform current module repo | string |
"https://github.com/cypik/terraform-google-template-instance" |
no |
resource_policies | (Optional) A list of short names or self_links of resource policies to attach to the instance. Modifying this list will cause the instance to recreate. Currently a max of 1 resource policy is supported. | list(string) |
[] |
no |
service_account | Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template#service_account. | object({ |
n/a | yes |
service_account_email | The service account e-mail address. | string |
"" |
no |
service_account_scopes | A list of service scopes. | list(string) |
[] |
no |
shielded_instance_config | Not used unless enable_shielded_vm is true. Shielded VM configuration for the instance. | object({ |
{ |
no |
source_image | Source disk image. If neither source_image nor source_image_family is specified, defaults to the latest public CentOS image. | string |
"" |
no |
source_image_family | Source image family. If neither source_image nor source_image_family is specified, defaults to the latest public CentOS image. | string |
"" |
no |
source_image_project | Project where the source image comes from. The default project contains CentOS images. | string |
"" |
no |
source_instance_template | The name or path of the instance template to use as the source when creating instances. | string |
"" |
no |
stack_type | The stack type for this network interface to identify whether the IPv6 feature is enabled or not. Values are IPV4_IPV6 or IPV4_ONLY . Default behavior is equivalent to IPV4_ONLY. |
string |
null |
no |
startup_script | User startup script to run when instances spin up | string |
"" |
no |
static_ips | List of static IPs for VM instances | list(string) |
[] |
no |
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. | string |
"" |
no |
subnetwork_project | The ID of the project in which the subnetwork belongs. If it is not provided, the provider project is used. | string |
"" |
no |
tags | Network tags, provided as a list | list(string) |
[] |
no |
threads_per_core | The number of threads per physical core. To disable simultaneous multithreading (SMT) set this to 1. | number |
null |
no |
zone | Zone where the instances should be created. If not specified, instances will be spread across available zones in the region. | string |
null |
no |
Name | Description |
---|---|
available_zones | List of available zones in region |
id | An identifier for the resource with format |
instances_details | List of all details for compute instances |
instances_self_links | List of self-links for compute instances |
metadata_fingerprint | The unique fingerprint of the metadata. |
self_link | The URI of the created resource. |
self_link_unique | A special URI of the created resource that uniquely identifies this instance template with the following format: |
template_id | An identifier for the resource with format |
template_metadata_fingerprint | An identifier for the resource with format |
template_self_link | An identifier for the resource with format |
template_tags_fingerprint | The unique fingerprint of the tags. |