Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add disk resource policies #412

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/instance_template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ See the [simple](../../examples/instance_template/simple) for a usage example.
| can\_ip\_forward | Enable IP forwarding, for NAT instances for example | `string` | `"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\_resource\_policies | A list (short name or id) of resource policies to attach to this disk for automatic snapshot creations | `list(string)` | `[]` | no |
| disk\_size\_gb | Boot disk size in GB | `string` | `"100"` | no |
| disk\_type | Boot disk type, can be either pd-ssd, local-ssd, or pd-standard | `string` | `"pd-standard"` | 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 |
Expand Down
40 changes: 21 additions & 19 deletions modules/instance_template/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ locals {

boot_disk = [
{
source_image = var.source_image != "" ? format("${local.source_image_project}/${local.source_image}") : format("${local.source_image_project}/${local.source_image_family}")
disk_size_gb = var.disk_size_gb
disk_type = var.disk_type
disk_labels = var.disk_labels
auto_delete = var.auto_delete
boot = "true"
source_image = var.source_image != "" ? format("${local.source_image_project}/${local.source_image}") : format("${local.source_image_project}/${local.source_image_family}")
disk_size_gb = var.disk_size_gb
disk_type = var.disk_type
disk_labels = var.disk_labels
auto_delete = var.auto_delete
boot = "true"
resource_policies = var.disk_resource_policies
},
]

Expand Down Expand Up @@ -78,19 +79,20 @@ 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)
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)
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)
resource_policies = lookup(disk.value, "resource_policies", [])

dynamic "disk_encryption_key" {
for_each = compact([var.disk_encryption_key == null ? null : 1])
Expand Down
4 changes: 4 additions & 0 deletions modules/instance_template/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ spec:
description: Labels to be assigned to boot disk, provided as a map
varType: map(string)
defaultValue: {}
- name: disk_resource_policies
description: A list (short name or id) of resource policies to attach to this disk for automatic snapshot creations
varType: list(string)
defaultValue: []
- name: disk_size_gb
description: Boot disk size in GB
varType: string
Expand Down
6 changes: 6 additions & 0 deletions modules/instance_template/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ variable "additional_disks" {
default = []
}

variable "disk_resource_policies" {
description = "A list (short name or id) of resource policies to attach to this disk for automatic snapshot creations"
type = list(string)
default = []
}

####################
# network_interface
####################
Expand Down