2022-09-26 08:11:52 -04:00
|
|
|
terraform {
|
|
|
|
required_providers {
|
|
|
|
google = {
|
|
|
|
source = "hashicorp/google"
|
2024-04-16 12:13:47 -04:00
|
|
|
version = "5.23.0"
|
|
|
|
}
|
|
|
|
|
|
|
|
google-beta = {
|
|
|
|
source = "hashicorp/google-beta"
|
|
|
|
version = "5.23.0"
|
2022-09-26 08:11:52 -04:00
|
|
|
}
|
2023-06-19 07:02:01 -04:00
|
|
|
|
|
|
|
random = {
|
|
|
|
source = "hashicorp/random"
|
2023-12-12 10:00:16 -05:00
|
|
|
version = "3.6.0"
|
2023-06-19 07:02:01 -04:00
|
|
|
}
|
2022-09-26 08:11:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
locals {
|
2023-06-19 07:02:01 -04:00
|
|
|
group_uid = random_id.uid.hex
|
2023-06-23 06:08:30 -04:00
|
|
|
name = "${var.base_name}-${var.role}-${local.group_uid}"
|
2023-01-27 06:59:25 -05:00
|
|
|
state_disk_name = "state-disk"
|
2022-09-26 08:11:52 -04:00
|
|
|
}
|
|
|
|
|
2023-06-19 07:02:01 -04:00
|
|
|
resource "random_id" "uid" {
|
|
|
|
byte_length = 4
|
|
|
|
}
|
|
|
|
|
2022-09-26 08:11:52 -04:00
|
|
|
resource "google_compute_instance_template" "template" {
|
2024-04-16 12:13:47 -04:00
|
|
|
# Beta provider is necessary to set confidential instance types.
|
|
|
|
# TODO(msanft): Remove beta provider once confidential instance type setting is in GA.
|
|
|
|
provider = google-beta
|
|
|
|
|
2022-09-26 08:11:52 -04:00
|
|
|
name = local.name
|
|
|
|
machine_type = var.instance_type
|
2023-06-05 08:52:39 -04:00
|
|
|
tags = ["constellation-${var.uid}"] // Note that this is also applied as a label
|
2023-06-19 07:02:01 -04:00
|
|
|
labels = merge(var.labels, {
|
2023-06-23 06:08:30 -04:00
|
|
|
constellation-role = var.role,
|
2023-06-19 07:02:01 -04:00
|
|
|
constellation-node-group = var.node_group_name,
|
|
|
|
})
|
2022-09-26 08:11:52 -04:00
|
|
|
|
|
|
|
confidential_instance_config {
|
|
|
|
enable_confidential_compute = true
|
2024-04-16 12:13:47 -04:00
|
|
|
confidential_instance_type = var.cc_technology
|
2022-09-26 08:11:52 -04:00
|
|
|
}
|
|
|
|
|
2024-04-16 12:13:47 -04:00
|
|
|
# If SEV-SNP is used, we have to explicitly select a Milan processor, as per
|
|
|
|
# https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance_template#confidential_instance_type
|
|
|
|
min_cpu_platform = var.cc_technology == "SEV_SNP" ? "AMD Milan" : null
|
|
|
|
|
2022-09-26 08:11:52 -04:00
|
|
|
disk {
|
|
|
|
disk_size_gb = 10
|
|
|
|
source_image = var.image_id
|
|
|
|
auto_delete = true
|
|
|
|
boot = true
|
|
|
|
mode = "READ_WRITE"
|
|
|
|
}
|
|
|
|
|
|
|
|
disk {
|
|
|
|
disk_size_gb = var.disk_size
|
|
|
|
disk_type = var.disk_type
|
|
|
|
auto_delete = true
|
2023-01-27 06:59:25 -05:00
|
|
|
device_name = local.state_disk_name // This name is used by disk mapper to find the disk
|
2022-09-26 08:11:52 -04:00
|
|
|
boot = false
|
|
|
|
mode = "READ_WRITE"
|
|
|
|
type = "PERSISTENT"
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata = {
|
2022-11-26 13:44:34 -05:00
|
|
|
kube-env = var.kube_env
|
|
|
|
constellation-init-secret-hash = var.init_secret_hash
|
|
|
|
serial-port-enable = var.debug ? "TRUE" : "FALSE"
|
2022-09-26 08:11:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = var.network
|
|
|
|
subnetwork = var.subnetwork
|
|
|
|
alias_ip_range {
|
|
|
|
ip_cidr_range = "/24"
|
2023-03-21 17:56:03 -04:00
|
|
|
subnetwork_range_name = var.alias_ip_range_name
|
2022-09-26 08:11:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
scheduling {
|
|
|
|
on_host_maintenance = "TERMINATE"
|
|
|
|
}
|
|
|
|
|
|
|
|
service_account {
|
|
|
|
scopes = [
|
|
|
|
"https://www.googleapis.com/auth/compute",
|
|
|
|
"https://www.googleapis.com/auth/servicecontrol",
|
|
|
|
"https://www.googleapis.com/auth/service.management.readonly",
|
|
|
|
"https://www.googleapis.com/auth/devstorage.read_only",
|
|
|
|
"https://www.googleapis.com/auth/logging.write",
|
|
|
|
"https://www.googleapis.com/auth/monitoring.write",
|
|
|
|
"https://www.googleapis.com/auth/trace.append",
|
2022-11-17 09:25:25 -05:00
|
|
|
"https://www.googleapis.com/auth/cloud-platform",
|
2022-09-26 08:11:52 -04:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
shielded_instance_config {
|
2023-09-22 10:35:38 -04:00
|
|
|
enable_secure_boot = false
|
2022-09-26 08:11:52 -04:00
|
|
|
enable_vtpm = true
|
|
|
|
enable_integrity_monitoring = true
|
|
|
|
}
|
2023-06-05 08:52:39 -04:00
|
|
|
|
|
|
|
lifecycle {
|
|
|
|
ignore_changes = [
|
2023-06-23 06:08:30 -04:00
|
|
|
name, # required. legacy instance templates used different naming scheme
|
2023-06-05 08:52:39 -04:00
|
|
|
tags,
|
|
|
|
labels,
|
|
|
|
disk, # required. update procedure modifies the instance template externally
|
|
|
|
metadata,
|
|
|
|
network_interface,
|
|
|
|
scheduling,
|
|
|
|
service_account,
|
|
|
|
shielded_instance_config,
|
|
|
|
]
|
|
|
|
}
|
2022-09-26 08:11:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_instance_group_manager" "instance_group_manager" {
|
|
|
|
name = local.name
|
2022-09-27 11:04:26 -04:00
|
|
|
description = "Instance group manager for Constellation"
|
2022-09-26 08:11:52 -04:00
|
|
|
base_instance_name = local.name
|
2023-06-19 07:02:01 -04:00
|
|
|
zone = var.zone
|
2023-06-30 04:53:00 -04:00
|
|
|
target_size = var.initial_count
|
2022-09-26 08:11:52 -04:00
|
|
|
|
2023-01-27 06:59:25 -05:00
|
|
|
dynamic "stateful_disk" {
|
2023-06-23 06:08:30 -04:00
|
|
|
for_each = var.role == "control-plane" ? [1] : []
|
2023-01-27 06:59:25 -05:00
|
|
|
content {
|
|
|
|
device_name = local.state_disk_name
|
|
|
|
delete_rule = "ON_PERMANENT_INSTANCE_DELETION"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dynamic "stateful_internal_ip" {
|
2023-06-23 06:08:30 -04:00
|
|
|
for_each = var.role == "control-plane" ? [1] : []
|
2023-01-27 06:59:25 -05:00
|
|
|
content {
|
|
|
|
interface_name = "nic0"
|
|
|
|
delete_rule = "ON_PERMANENT_INSTANCE_DELETION"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-26 08:11:52 -04:00
|
|
|
version {
|
|
|
|
instance_template = google_compute_instance_template.template.id
|
|
|
|
}
|
|
|
|
|
|
|
|
dynamic "named_port" {
|
|
|
|
for_each = toset(var.named_ports)
|
|
|
|
content {
|
|
|
|
name = named_port.value.name
|
|
|
|
port = named_port.value.port
|
|
|
|
}
|
|
|
|
}
|
2022-11-07 05:04:10 -05:00
|
|
|
|
|
|
|
lifecycle {
|
|
|
|
ignore_changes = [
|
2023-06-23 06:08:30 -04:00
|
|
|
name, # required. legacy instance templates used different naming scheme
|
|
|
|
base_instance_name, # required. legacy instance templates used different naming scheme
|
|
|
|
target_size, # required. autoscaling modifies the instance count externally
|
|
|
|
version, # required. update procedure modifies the instance template externally
|
2022-11-07 05:04:10 -05:00
|
|
|
]
|
|
|
|
}
|
2022-09-26 08:11:52 -04:00
|
|
|
}
|