From 76e9c192869c444b84a9e6468e711e948a9219be Mon Sep 17 00:00:00 2001 From: anisf Date: Sat, 23 Sep 2023 03:53:36 +0400 Subject: [PATCH] feat: support source_snapshot for additional_disks (#341) Signed-off-by: Anis FATHALLAH Co-authored-by: Awais Malik --- modules/instance_template/README.md | 2 +- modules/instance_template/main.tf | 25 +++++++++++++------------ modules/instance_template/variables.tf | 15 ++++++++------- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/modules/instance_template/README.md b/modules/instance_template/README.md index ce489f5f..13647251 100644 --- a/modules/instance_template/README.md +++ b/modules/instance_template/README.md @@ -14,7 +14,7 @@ See the [simple](../../examples/instance_template/simple) for a usage example. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | access\_config | Access configurations, i.e. IPs via which the VM instance can be accessed via the Internet. |
list(object({
nat_ip = string
network_tier = string
}))
| `[]` | no | -| additional\_disks | List of maps of additional disks. See https://www.terraform.io/docs/providers/google/r/compute_instance_template#disk_name |
list(object({
disk_name = string
device_name = string
auto_delete = bool
boot = bool
disk_size_gb = number
disk_type = string
disk_labels = map(string)
}))
| `[]` | no | +| additional\_disks | List of maps of additional disks. See https://www.terraform.io/docs/providers/google/r/compute_instance_template#disk_name |
list(object({
disk_name = string
device_name = string
auto_delete = bool
boot = bool
disk_size_gb = number
disk_type = string
disk_labels = map(string)
source_snapshot = optional(string)
}))
| `[]` | no | | additional\_networks | Additional network interface details for GCE, if any. |
list(object({
network = string
subnetwork = string
subnetwork_project = string
network_ip = string
nic_type = string
stack_type = string
queue_count = number
access_config = list(object({
nat_ip = string
network_tier = string
}))
ipv6_access_config = list(object({
network_tier = string
}))
alias_ip_range = list(object({
ip_cidr_range = string
subnetwork_range_name = string
}))
}))
| `[]` | 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({
ip_cidr_range = string
subnetwork_range_name = string
})
| `null` | no | | auto\_delete | Whether or not the boot disk should be auto-deleted | `string` | `"true"` | no | diff --git a/modules/instance_template/main.tf b/modules/instance_template/main.tf index 22d8c11f..e05a8df6 100644 --- a/modules/instance_template/main.tf +++ b/modules/instance_template/main.tf @@ -76,18 +76,19 @@ resource "google_compute_instance_template" "tpl" { dynamic "disk" { for_each = local.all_disks content { - auto_delete = lookup(disk.value, "auto_delete", null) - boot = lookup(disk.value, "boot", null) - device_name = lookup(disk.value, "device_name", null) - disk_name = lookup(disk.value, "disk_name", null) - disk_size_gb = lookup(disk.value, "disk_size_gb", lookup(disk.value, "disk_type", null) == "local-ssd" ? "375" : null) - disk_type = lookup(disk.value, "disk_type", null) - interface = lookup(disk.value, "interface", lookup(disk.value, "disk_type", null) == "local-ssd" ? "NVME" : null) - mode = lookup(disk.value, "mode", null) - source = lookup(disk.value, "source", null) - source_image = lookup(disk.value, "source_image", null) - type = lookup(disk.value, "disk_type", null) == "local-ssd" ? "SCRATCH" : "PERSISTENT" - labels = lookup(disk.value, "disk_labels", null) + auto_delete = lookup(disk.value, "auto_delete", null) + boot = lookup(disk.value, "boot", null) + device_name = lookup(disk.value, "device_name", null) + disk_name = lookup(disk.value, "disk_name", null) + disk_size_gb = lookup(disk.value, "disk_size_gb", lookup(disk.value, "disk_type", null) == "local-ssd" ? "375" : null) + disk_type = lookup(disk.value, "disk_type", null) + interface = lookup(disk.value, "interface", lookup(disk.value, "disk_type", null) == "local-ssd" ? "NVME" : null) + mode = lookup(disk.value, "mode", null) + source = lookup(disk.value, "source", null) + source_image = lookup(disk.value, "source_image", null) + source_snapshot = lookup(disk.value, "source_snapshot", null) + type = lookup(disk.value, "disk_type", null) == "local-ssd" ? "SCRATCH" : "PERSISTENT" + labels = lookup(disk.value, "disk_labels", null) dynamic "disk_encryption_key" { for_each = compact([var.disk_encryption_key == null ? null : 1]) diff --git a/modules/instance_template/variables.tf b/modules/instance_template/variables.tf index 624b6431..a80ad371 100644 --- a/modules/instance_template/variables.tf +++ b/modules/instance_template/variables.tf @@ -163,13 +163,14 @@ variable "auto_delete" { variable "additional_disks" { description = "List of maps of additional disks. See https://www.terraform.io/docs/providers/google/r/compute_instance_template#disk_name" type = list(object({ - disk_name = string - device_name = string - auto_delete = bool - boot = bool - disk_size_gb = number - disk_type = string - disk_labels = map(string) + disk_name = string + device_name = string + auto_delete = bool + boot = bool + disk_size_gb = number + disk_type = string + disk_labels = map(string) + source_snapshot = optional(string) })) default = [] }