Skip to content

Commit 615c8bc

Browse files
authored
feat: Add confidential compute flags (#131)
1 parent f101b64 commit 615c8bc

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

modules/instance_template/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ See the [simple](../../examples/instance_template/simple) for a usage example.
1919
| can\_ip\_forward | Enable IP forwarding, for NAT instances for example | `string` | `"false"` | no |
2020
| disk\_size\_gb | Boot disk size in GB | `string` | `"100"` | no |
2121
| disk\_type | Boot disk type, can be either pd-ssd, local-ssd, or pd-standard | `string` | `"pd-standard"` | no |
22+
| 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 |
2223
| 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 |
2324
| labels | Labels, provided as a map | `map(string)` | `{}` | no |
2425
| machine\_type | Machine type to create, e.g. n1-standard-1 | `string` | `"n1-standard-1"` | no |
2526
| metadata | Metadata, provided as a map | `map(string)` | `{}` | no |
2627
| name\_prefix | Name prefix for the instance template | `string` | `"default-instance-template"` | no |
2728
| 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 |
2829
| network\_ip | Private IP address to assign to the instance if desired. | `string` | `""` | no |
30+
| on\_host\_maintenance | Instance availability Policy | `string` | `"MIGRATE"` | no |
2931
| preemptible | Allow the instance to be preempted | `bool` | `false` | no |
3032
| project\_id | The GCP project ID | `string` | `null` | no |
3133
| region | Region where the instance template should be created. | `string` | `null` | no |

modules/instance_template/main.tf

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,18 @@ locals {
4444

4545
all_disks = concat(local.boot_disk, var.additional_disks)
4646

47-
# NOTE: Even if all the shielded_instance_config values are false, if the
48-
# config block exists and an unsupported image is chosen, the apply will fail
49-
# so we use a single-value array with the default value to initialize the block
50-
# only if it is enabled.
51-
shielded_vm_configs = var.enable_shielded_vm ? [true] : []
47+
# NOTE: Even if all the shielded_instance_config or confidential_instance_config
48+
# values are false, if the config block exists and an unsupported image is chosen,
49+
# the apply will fail so we use a single-value array with the default value to
50+
# initialize the block only if it is enabled.
51+
shielded_vm_configs = var.enable_shielded_vm ? [true] : []
52+
confidential_instance_config = var.enable_confidential_vm ? [true] : []
53+
54+
on_host_maintenance = (
55+
var.preemptible || var.enable_confidential_vm
56+
? "TERMINATE"
57+
: var.on_host_maintenance
58+
)
5259
}
5360

5461
####################
@@ -116,8 +123,9 @@ resource "google_compute_instance_template" "tpl" {
116123

117124
# scheduling must have automatic_restart be false when preemptible is true.
118125
scheduling {
119-
preemptible = var.preemptible
120-
automatic_restart = ! var.preemptible
126+
preemptible = var.preemptible
127+
automatic_restart = ! var.preemptible
128+
on_host_maintenance = local.on_host_maintenance
121129
}
122130

123131
dynamic "shielded_instance_config" {
@@ -128,4 +136,8 @@ resource "google_compute_instance_template" "tpl" {
128136
enable_integrity_monitoring = lookup(var.shielded_instance_config, "enable_integrity_monitoring", shielded_instance_config.value)
129137
}
130138
}
139+
140+
confidential_instance_config {
141+
enable_confidential_compute = var.enable_confidential_vm
142+
}
131143
}

modules/instance_template/variables.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ variable "preemptible" {
5353
default = false
5454
}
5555

56+
variable "on_host_maintenance" {
57+
type = string
58+
description = "Instance availability Policy"
59+
default = "MIGRATE"
60+
}
61+
5662
variable "region" {
5763
type = string
5864
description = "Region where the instance template should be created."
@@ -178,6 +184,14 @@ variable "shielded_instance_config" {
178184
}
179185
}
180186

187+
###########################
188+
# Confidential Compute VMs
189+
###########################
190+
variable "enable_confidential_vm" {
191+
default = false
192+
description = "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"
193+
}
194+
181195
###########################
182196
# Public IP
183197
###########################

0 commit comments

Comments
 (0)