Skip to content

Commit 76e9c19

Browse files
anisfg-awmalik
andauthored
feat: support source_snapshot for additional_disks (#341)
Signed-off-by: Anis FATHALLAH <[email protected]> Co-authored-by: Awais Malik <[email protected]>
1 parent 16cd050 commit 76e9c19

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

modules/instance_template/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the [simple](../../examples/instance_template/simple) for a usage example.
1414
| Name | Description | Type | Default | Required |
1515
|------|-------------|------|---------|:--------:|
1616
| access\_config | Access configurations, i.e. IPs via which the VM instance can be accessed via the Internet. | <pre>list(object({<br> nat_ip = string<br> network_tier = string<br> }))</pre> | `[]` | no |
17-
| additional\_disks | List of maps of additional disks. See https://www.terraform.io/docs/providers/google/r/compute_instance_template#disk_name | <pre>list(object({<br> disk_name = string<br> device_name = string<br> auto_delete = bool<br> boot = bool<br> disk_size_gb = number<br> disk_type = string<br> disk_labels = map(string)<br> }))</pre> | `[]` | no |
17+
| additional\_disks | List of maps of additional disks. See https://www.terraform.io/docs/providers/google/r/compute_instance_template#disk_name | <pre>list(object({<br> disk_name = string<br> device_name = string<br> auto_delete = bool<br> boot = bool<br> disk_size_gb = number<br> disk_type = string<br> disk_labels = map(string)<br> source_snapshot = optional(string)<br> }))</pre> | `[]` | no |
1818
| additional\_networks | Additional network interface details for GCE, if any. | <pre>list(object({<br> network = string<br> subnetwork = string<br> subnetwork_project = string<br> network_ip = string<br> nic_type = string<br> stack_type = string<br> queue_count = number<br> access_config = list(object({<br> nat_ip = string<br> network_tier = string<br> }))<br> ipv6_access_config = list(object({<br> network_tier = string<br> }))<br> alias_ip_range = list(object({<br> ip_cidr_range = string<br> subnetwork_range_name = string<br> }))<br> }))</pre> | `[]` | no |
1919
| alias\_ip\_range | An array of alias IP ranges for this network interface. Can only be specified for network interfaces on subnet-mode networks.<br>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.<br>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. | <pre>object({<br> ip_cidr_range = string<br> subnetwork_range_name = string<br> })</pre> | `null` | no |
2020
| auto\_delete | Whether or not the boot disk should be auto-deleted | `string` | `"true"` | no |

modules/instance_template/main.tf

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,19 @@ resource "google_compute_instance_template" "tpl" {
7676
dynamic "disk" {
7777
for_each = local.all_disks
7878
content {
79-
auto_delete = lookup(disk.value, "auto_delete", null)
80-
boot = lookup(disk.value, "boot", null)
81-
device_name = lookup(disk.value, "device_name", null)
82-
disk_name = lookup(disk.value, "disk_name", null)
83-
disk_size_gb = lookup(disk.value, "disk_size_gb", lookup(disk.value, "disk_type", null) == "local-ssd" ? "375" : null)
84-
disk_type = lookup(disk.value, "disk_type", null)
85-
interface = lookup(disk.value, "interface", lookup(disk.value, "disk_type", null) == "local-ssd" ? "NVME" : null)
86-
mode = lookup(disk.value, "mode", null)
87-
source = lookup(disk.value, "source", null)
88-
source_image = lookup(disk.value, "source_image", null)
89-
type = lookup(disk.value, "disk_type", null) == "local-ssd" ? "SCRATCH" : "PERSISTENT"
90-
labels = lookup(disk.value, "disk_labels", null)
79+
auto_delete = lookup(disk.value, "auto_delete", null)
80+
boot = lookup(disk.value, "boot", null)
81+
device_name = lookup(disk.value, "device_name", null)
82+
disk_name = lookup(disk.value, "disk_name", null)
83+
disk_size_gb = lookup(disk.value, "disk_size_gb", lookup(disk.value, "disk_type", null) == "local-ssd" ? "375" : null)
84+
disk_type = lookup(disk.value, "disk_type", null)
85+
interface = lookup(disk.value, "interface", lookup(disk.value, "disk_type", null) == "local-ssd" ? "NVME" : null)
86+
mode = lookup(disk.value, "mode", null)
87+
source = lookup(disk.value, "source", null)
88+
source_image = lookup(disk.value, "source_image", null)
89+
source_snapshot = lookup(disk.value, "source_snapshot", null)
90+
type = lookup(disk.value, "disk_type", null) == "local-ssd" ? "SCRATCH" : "PERSISTENT"
91+
labels = lookup(disk.value, "disk_labels", null)
9192

9293
dynamic "disk_encryption_key" {
9394
for_each = compact([var.disk_encryption_key == null ? null : 1])

modules/instance_template/variables.tf

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,14 @@ variable "auto_delete" {
163163
variable "additional_disks" {
164164
description = "List of maps of additional disks. See https://www.terraform.io/docs/providers/google/r/compute_instance_template#disk_name"
165165
type = list(object({
166-
disk_name = string
167-
device_name = string
168-
auto_delete = bool
169-
boot = bool
170-
disk_size_gb = number
171-
disk_type = string
172-
disk_labels = map(string)
166+
disk_name = string
167+
device_name = string
168+
auto_delete = bool
169+
boot = bool
170+
disk_size_gb = number
171+
disk_type = string
172+
disk_labels = map(string)
173+
source_snapshot = optional(string)
173174
}))
174175
default = []
175176
}

0 commit comments

Comments
 (0)