Skip to content

Commit 9e930ce

Browse files
authored
feat: Adds labels to boot and additional disks (#168)
1 parent 5c0f061 commit 9e930ce

File tree

10 files changed

+26
-2
lines changed

10 files changed

+26
-2
lines changed

examples/compute_instance/disk_snapshot/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module "instance_template" {
4444
disk_type = "pd-standard"
4545
disk_name = null
4646
device_name = null
47+
disk_labels = { "foo" : "bar" }
4748
},
4849
{
4950
auto_delete = true
@@ -52,6 +53,7 @@ module "instance_template" {
5253
disk_type = "pd-standard"
5354
disk_name = null
5455
device_name = null
56+
disk_labels = {}
5557
}
5658
]
5759
}

examples/instance_template/additional_disks/main.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module "instance_template" {
3636
disk_type = "pd-standard"
3737
auto_delete = "true"
3838
boot = "false"
39+
disk_labels = {}
3940
},
4041
{
4142
disk_name = "disk-1"
@@ -44,6 +45,7 @@ module "instance_template" {
4445
disk_type = "pd-standard"
4546
auto_delete = "true"
4647
boot = "false"
48+
disk_labels = { "foo" : "bar" }
4749
},
4850
{
4951
disk_name = "disk-2"
@@ -52,6 +54,7 @@ module "instance_template" {
5254
disk_type = "pd-standard"
5355
auto_delete = "true"
5456
boot = "false"
57+
disk_labels = { "foo" : "bar" }
5558
},
5659
]
5760
}

examples/mig/full/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ module "instance_template" {
5353
/* disks */
5454
disk_size_gb = var.disk_size_gb
5555
disk_type = var.disk_type
56+
disk_labels = var.disk_labels
5657
auto_delete = var.auto_delete
5758
additional_disks = var.additional_disks
5859
}

examples/mig/full/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ variable "disk_type" {
116116
default = "pd-standard"
117117
}
118118

119+
variable "disk_labels" {
120+
description = "Labels to be assigned to boot disk, provided as a map"
121+
default = { "foo" : "bar" }
122+
}
123+
119124
variable "auto_delete" {
120125
description = "Whether or not the disk should be auto-deleted"
121126
default = "true"
@@ -130,6 +135,7 @@ variable "additional_disks" {
130135
boot = bool
131136
disk_size_gb = number
132137
disk_type = string
138+
disk_labels = map(string)
133139
}))
134140
default = []
135141
}

examples/umig/full/variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ variable "additional_disks" {
130130
boot = bool
131131
disk_size_gb = number
132132
disk_type = string
133+
disk_labels = map(string)
133134
}))
134135
default = []
135136
}

modules/instance_template/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ 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.html#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> }))</pre> | `[]` | no |
17+
| additional\_disks | List of maps of additional disks. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#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 |
1818
| auto\_delete | Whether or not the boot disk should be auto-deleted | `string` | `"true"` | no |
1919
| can\_ip\_forward | Enable IP forwarding, for NAT instances for example | `string` | `"false"` | no |
20+
| disk\_labels | Labels to be assigned to boot disk, provided as a map | `map(string)` | `{}` | no |
2021
| disk\_size\_gb | Boot disk size in GB | `string` | `"100"` | no |
2122
| disk\_type | Boot disk type, can be either pd-ssd, local-ssd, or pd-standard | `string` | `"pd-standard"` | no |
2223
| 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 |

modules/instance_template/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ locals {
3737
source_image = var.source_image != "" ? data.google_compute_image.image.self_link : data.google_compute_image.image_family.self_link
3838
disk_size_gb = var.disk_size_gb
3939
disk_type = var.disk_type
40+
disk_labels = var.disk_labels
4041
auto_delete = var.auto_delete
4142
boot = "true"
4243
},
@@ -87,6 +88,7 @@ resource "google_compute_instance_template" "tpl" {
8788
source = lookup(disk.value, "source", null)
8889
source_image = lookup(disk.value, "source_image", null)
8990
type = lookup(disk.value, "disk_type", null) == "local-ssd" ? "SCRATCH" : "PERSISTENT"
91+
labels = lookup(disk.value, "disk_labels", null)
9092

9193
dynamic "disk_encryption_key" {
9294
for_each = lookup(disk.value, "disk_encryption_key", [])

modules/instance_template/variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ variable "disk_type" {
9999
default = "pd-standard"
100100
}
101101

102+
variable "disk_labels" {
103+
description = "Labels to be assigned to boot disk, provided as a map"
104+
type = map(string)
105+
default = {}
106+
}
107+
102108
variable "auto_delete" {
103109
description = "Whether or not the boot disk should be auto-deleted"
104110
default = "true"
@@ -113,6 +119,7 @@ variable "additional_disks" {
113119
boot = bool
114120
disk_size_gb = number
115121
disk_type = string
122+
disk_labels = map(string)
116123
}))
117124
default = []
118125
}

modules/preemptible_and_regular_instance_templates/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ See the [simple](../../examples/preemptible_and_regular_instance_templates/simpl
1313
| Name | Description | Type | Default | Required |
1414
|------|-------------|------|---------|:--------:|
1515
| 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 |
16-
| additional\_disks | List of maps of additional disks. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#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> }))</pre> | `[]` | no |
16+
| additional\_disks | List of maps of additional disks. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#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 |
1717
| auto\_delete | Whether or not the boot disk should be auto-deleted | `bool` | `true` | no |
1818
| can\_ip\_forward | Enable IP forwarding, for NAT instances for example | `string` | `"false"` | no |
1919
| disk\_size\_gb | Boot disk size in GB | `string` | `"100"` | no |

modules/preemptible_and_regular_instance_templates/variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ variable "additional_disks" {
8989
boot = bool
9090
disk_size_gb = number
9191
disk_type = string
92+
disk_labels = map(string)
9293
}))
9394
default = []
9495
}

0 commit comments

Comments
 (0)