Refactor compute-vm for Terraform 1.3 (#860)

* refactor compute-vm for Terraform 1.3

* bump Terraform version in CI tests config

* fix optional null handling (ht jccb)

* tfdoc

* update blueprints

* align fast

* align README examples
This commit is contained in:
Ludovico Magnocavallo 2022-10-07 10:53:53 +02:00 committed by GitHub
parent 8c88517199
commit e66340c4db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 104 additions and 360 deletions

View File

@ -30,7 +30,7 @@ env:
PYTEST_ADDOPTS: "--color=yes" PYTEST_ADDOPTS: "--color=yes"
PYTHON_VERSION: "3.10" PYTHON_VERSION: "3.10"
TF_PLUGIN_CACHE_DIR: "/home/runner/.terraform.d/plugin-cache" TF_PLUGIN_CACHE_DIR: "/home/runner/.terraform.d/plugin-cache"
TF_VERSION: 1.3.0 TF_VERSION: 1.3.2
jobs: jobs:
doc-examples: doc-examples:

View File

@ -69,8 +69,6 @@ module "server" {
network_interfaces = [{ network_interfaces = [{
network = var.network_config == null ? module.vpc[0].self_link : var.network_config.network network = var.network_config == null ? module.vpc[0].self_link : var.network_config.network
subnetwork = var.network_config == null ? module.vpc[0].subnet_self_links["${var.region}/subnet"] : var.network_config.subnet subnetwork = var.network_config == null ? module.vpc[0].subnet_self_links["${var.region}/subnet"] : var.network_config.subnet
nat = false
addresses = null
}] }]
metadata = { metadata = {
# Enables OpenSSH in the Windows instance # Enables OpenSSH in the Windows instance

View File

@ -104,8 +104,6 @@ module "simple-vm-example" {
network_interfaces = [{ network_interfaces = [{
network = module.vpc.self_link network = module.vpc.self_link
subnetwork = try(module.vpc.subnet_self_links["${var.region}/${var.name}-default"], "") subnetwork = try(module.vpc.subnet_self_links["${var.region}/${var.name}-default"], "")
nat = false
addresses = null
}] }]
tags = ["${var.project_id}-test-feed", "shared-test-feed"] tags = ["${var.project_id}-test-feed", "shared-test-feed"]
} }

View File

@ -94,13 +94,9 @@ module "instance_template_ew1" {
network_interfaces = [{ network_interfaces = [{
network = module.vpc.self_link network = module.vpc.self_link
subnetwork = module.vpc.subnet_self_links["europe-west1/subnet-ew1"] subnetwork = module.vpc.subnet_self_links["europe-west1/subnet-ew1"]
nat = false
addresses = null
}] }]
boot_disk = { boot_disk = {
image = "projects/debian-cloud/global/images/family/debian-11" image = "projects/debian-cloud/global/images/family/debian-11"
type = "pd-ssd"
size = 10
} }
metadata = { metadata = {
startup-script-url = "gs://cloud-training/gcpnet/httplb/startup.sh" startup-script-url = "gs://cloud-training/gcpnet/httplb/startup.sh"
@ -119,13 +115,9 @@ module "instance_template_ue1" {
network_interfaces = [{ network_interfaces = [{
network = module.vpc.self_link network = module.vpc.self_link
subnetwork = module.vpc.subnet_self_links["us-east1/subnet-ue1"] subnetwork = module.vpc.subnet_self_links["us-east1/subnet-ue1"]
nat = false
addresses = null
}] }]
boot_disk = { boot_disk = {
image = "projects/debian-cloud/global/images/family/debian-11" image = "projects/debian-cloud/global/images/family/debian-11"
type = "pd-ssd"
size = 10
} }
metadata = { metadata = {
startup-script-url = "gs://cloud-training/gcpnet/httplb/startup.sh" startup-script-url = "gs://cloud-training/gcpnet/httplb/startup.sh"
@ -146,12 +138,9 @@ module "vm_siege" {
network = module.vpc.self_link network = module.vpc.self_link
subnetwork = module.vpc.subnet_self_links["us-west1/subnet-uw1"] subnetwork = module.vpc.subnet_self_links["us-west1/subnet-uw1"]
nat = true nat = true
addresses = null
}] }]
boot_disk = { boot_disk = {
image = "projects/debian-cloud/global/images/family/debian-11" image = "projects/debian-cloud/global/images/family/debian-11"
type = "pd-ssd"
size = 10
} }
metadata = { metadata = {
startup-script = <<EOT startup-script = <<EOT

View File

@ -155,13 +155,9 @@ module "squid-vm" {
network_interfaces = [{ network_interfaces = [{
network = module.vpc.self_link network = module.vpc.self_link
subnetwork = module.vpc.subnet_self_links["${var.region}/proxy"] subnetwork = module.vpc.subnet_self_links["${var.region}/proxy"]
nat = false
addresses = null
}] }]
boot_disk = { boot_disk = {
image = "cos-cloud/cos-stable" image = "cos-cloud/cos-stable"
type = "pd-standard"
size = 10
} }
service_account = module.service-account-squid.email service_account = module.service-account-squid.email
service_account_scopes = ["https://www.googleapis.com/auth/cloud-platform"] service_account_scopes = ["https://www.googleapis.com/auth/cloud-platform"]

View File

@ -33,8 +33,6 @@ module "vm-left" {
{ {
network = module.vpc-left.self_link network = module.vpc-left.self_link
subnetwork = values(module.vpc-left.subnet_self_links)[0] subnetwork = values(module.vpc-left.subnet_self_links)[0]
nat = false
addresses = null
} }
] ]
tags = ["ssh"] tags = ["ssh"]
@ -58,8 +56,6 @@ module "vm-right" {
{ {
network = module.vpc-right.self_link network = module.vpc-right.self_link
subnetwork = values(module.vpc-right.subnet_self_links)[0] subnetwork = values(module.vpc-right.subnet_self_links)[0]
nat = false
addresses = null
} }
] ]
tags = ["ssh"] tags = ["ssh"]

View File

@ -229,11 +229,9 @@ module "service-account-proxy" {
module "cos-nginx" { module "cos-nginx" {
count = !var.tls ? 1 : 0 count = !var.tls ? 1 : 0
source = "../../../modules/cloud-config-container/nginx" source = "../../../modules/cloud-config-container/nginx"
image = var.nginx_image image = var.nginx_image
files = local.nginx_files files = local.nginx_files
users = local.users users = local.users
runcmd_pre = ["sed -i \"s/HOSTNAME/$${HOSTNAME}/\" /etc/nginx/conf.d/default.conf"] runcmd_pre = ["sed -i \"s/HOSTNAME/$${HOSTNAME}/\" /etc/nginx/conf.d/default.conf"]
runcmd_post = ["systemctl start monitoring-agent"] runcmd_post = ["systemctl start monitoring-agent"]
} }
@ -241,28 +239,22 @@ module "cos-nginx" {
module "cos-nginx-tls" { module "cos-nginx-tls" {
count = var.tls ? 1 : 0 count = var.tls ? 1 : 0
source = "../../../modules/cloud-config-container/nginx-tls" source = "../../../modules/cloud-config-container/nginx-tls"
nginx_image = var.nginx_image nginx_image = var.nginx_image
files = local.nginx_files files = local.nginx_files
users = local.users users = local.users
runcmd_post = ["systemctl start monitoring-agent"] runcmd_post = ["systemctl start monitoring-agent"]
} }
module "mig-proxy" { module "mig-proxy" {
source = "../../../modules/compute-mig" source = "../../../modules/compute-mig"
project_id = module.project.project_id project_id = module.project.project_id
location = var.region location = var.region
regional = true regional = true
name = format("%sproxy-cluster", var.prefix) name = format("%sproxy-cluster", var.prefix)
named_ports = { named_ports = {
http = "80" http = "80"
https = "443" https = "443"
} }
autoscaler_config = var.autoscaling == null ? null : { autoscaler_config = var.autoscaling == null ? null : {
min_replicas = var.autoscaling.min_replicas min_replicas = var.autoscaling.min_replicas
max_replicas = var.autoscaling.max_replicas max_replicas = var.autoscaling.max_replicas
@ -271,7 +263,6 @@ module "mig-proxy" {
load_balancing_utilization_target = null load_balancing_utilization_target = null
metric = var.autoscaling_metric metric = var.autoscaling_metric
} }
update_policy = { update_policy = {
type = "PROACTIVE" type = "PROACTIVE"
minimal_action = "REPLACE" minimal_action = "REPLACE"
@ -281,12 +272,10 @@ module "mig-proxy" {
max_unavailable_type = null max_unavailable_type = null
max_unavailable = null max_unavailable = null
} }
default_version = { default_version = {
instance_template = module.proxy-vm.template.self_link instance_template = module.proxy-vm.template.self_link
name = "proxy-vm" name = "proxy-vm"
} }
health_check_config = { health_check_config = {
type = "http" type = "http"
check = { check = {
@ -309,33 +298,22 @@ module "mig-proxy" {
module "proxy-vm" { module "proxy-vm" {
source = "../../../modules/compute-vm" source = "../../../modules/compute-vm"
project_id = module.project.project_id project_id = module.project.project_id
zone = format("%s-c", var.region) zone = format("%s-c", var.region)
name = "nginx-test-vm" name = "nginx-test-vm"
instance_type = "e2-standard-2" instance_type = "e2-standard-2"
tags = ["proxy-cluster"] tags = ["proxy-cluster"]
network_interfaces = [{ network_interfaces = [{
network = module.vpc.self_link network = module.vpc.self_link
subnetwork = module.vpc.subnet_self_links[format("%s/%s", var.region, var.subnetwork)] subnetwork = module.vpc.subnet_self_links[format("%s/%s", var.region, var.subnetwork)]
nat = false
addresses = null
}] }]
boot_disk = { boot_disk = {
image = "projects/cos-cloud/global/images/family/cos-stable" image = "projects/cos-cloud/global/images/family/cos-stable"
type = "pd-ssd"
size = 10
} }
create_template = true create_template = true
metadata = { metadata = {
user-data = !var.tls ? module.cos-nginx.0.cloud_config : module.cos-nginx-tls.0.cloud_config user-data = !var.tls ? module.cos-nginx.0.cloud_config : module.cos-nginx-tls.0.cloud_config
} }
service_account = module.service-account-proxy.email service_account = module.service-account-proxy.email
service_account_create = false service_account_create = false
} }
@ -344,9 +322,7 @@ module "xlb" {
source = "../../../modules/net-glb" source = "../../../modules/net-glb"
name = format("%sreverse-proxy-xlb", var.prefix) name = format("%sreverse-proxy-xlb", var.prefix)
project_id = module.project.project_id project_id = module.project.project_id
reserve_ip_address = true reserve_ip_address = true
health_checks_config = { health_checks_config = {
format("%sreverse-proxy-hc", var.prefix) = { format("%sreverse-proxy-hc", var.prefix) = {
type = "http" type = "http"
@ -364,13 +340,11 @@ module "xlb" {
} }
} }
} }
backend_services_config = { backend_services_config = {
format("%sreverse-proxy-backend", var.prefix) = { format("%sreverse-proxy-backend", var.prefix) = {
bucket_config = null bucket_config = null
enable_cdn = false enable_cdn = false
cdn_config = null cdn_config = null
group_config = { group_config = {
backends = [ backends = [
{ {
@ -378,7 +352,6 @@ module "xlb" {
options = null options = null
} }
] ]
health_checks = [format("%sreverse-proxy-hc", var.prefix)] health_checks = [format("%sreverse-proxy-hc", var.prefix)]
log_config = null log_config = null
options = { options = {

View File

@ -237,8 +237,6 @@ module "vm-test1" {
network_interfaces = [{ network_interfaces = [{
network = module.vpc.self_link network = module.vpc.self_link
subnetwork = module.vpc.subnet_self_links["${var.region.gcp1}/subnet1"] subnetwork = module.vpc.subnet_self_links["${var.region.gcp1}/subnet1"]
nat = false
addresses = null
}] }]
metadata = { startup-script = local.vm-startup-script } metadata = { startup-script = local.vm-startup-script }
service_account = module.service-account-gce.email service_account = module.service-account-gce.email
@ -312,8 +310,6 @@ module "vm-onprem" {
name = "onprem" name = "onprem"
boot_disk = { boot_disk = {
image = "ubuntu-os-cloud/ubuntu-1804-lts" image = "ubuntu-os-cloud/ubuntu-1804-lts"
type = "pd-ssd"
size = 10
} }
metadata = { metadata = {
user-data = module.config-onprem.cloud_config user-data = module.config-onprem.cloud_config
@ -321,8 +317,6 @@ module "vm-onprem" {
network_interfaces = [{ network_interfaces = [{
network = module.vpc.name network = module.vpc.name
subnetwork = module.vpc.subnet_self_links["${var.region.gcp1}/subnet1"] subnetwork = module.vpc.subnet_self_links["${var.region.gcp1}/subnet1"]
nat = true
addresses = null
}] }]
service_account = module.service-account-onprem.email service_account = module.service-account-onprem.email
service_account_scopes = ["https://www.googleapis.com/auth/cloud-platform"] service_account_scopes = ["https://www.googleapis.com/auth/cloud-platform"]

View File

@ -178,12 +178,8 @@ module "test-vm" {
instance_type = "e2-micro" instance_type = "e2-micro"
boot_disk = { boot_disk = {
image = "projects/ubuntu-os-cloud/global/images/family/ubuntu-2104" image = "projects/ubuntu-os-cloud/global/images/family/ubuntu-2104"
type = "pd-balanced"
size = 10
} }
network_interfaces = [{ network_interfaces = [{
addresses = null
nat = false
network = module.vpc-onprem.self_link network = module.vpc-onprem.self_link
subnetwork = module.vpc-onprem.subnet_self_links["${var.region}/${var.name}-onprem"] subnetwork = module.vpc-onprem.subnet_self_links["${var.region}/${var.name}-onprem"]
}] }]

View File

@ -38,26 +38,18 @@ module "nva-template-ew1" {
{ {
network = module.landing-untrusted-vpc.self_link network = module.landing-untrusted-vpc.self_link
subnetwork = module.landing-untrusted-vpc.subnet_self_links["europe-west1/landing-untrusted-default-ew1"] subnetwork = module.landing-untrusted-vpc.subnet_self_links["europe-west1/landing-untrusted-default-ew1"]
nat = false
addresses = null
}, },
{ {
network = module.landing-trusted-vpc.self_link network = module.landing-trusted-vpc.self_link
subnetwork = module.landing-trusted-vpc.subnet_self_links["europe-west1/landing-trusted-default-ew1"] subnetwork = module.landing-trusted-vpc.subnet_self_links["europe-west1/landing-trusted-default-ew1"]
nat = false
addresses = null
} }
] ]
boot_disk = { boot_disk = {
image = "projects/debian-cloud/global/images/family/debian-10" image = "projects/debian-cloud/global/images/family/debian-10"
type = "pd-balanced"
size = 10
} }
create_template = true create_template = true
instance_type = "f1-micro" instance_type = "f1-micro"
options = { options = {
allow_stopping_for_update = true
deletion_protection = false
spot = true spot = true
termination_action = "STOP" termination_action = "STOP"
} }

View File

@ -26,20 +26,13 @@
# network_interfaces = [{ # network_interfaces = [{
# network = module.landing-untrusted-vpc.self_link # network = module.landing-untrusted-vpc.self_link
# subnetwork = module.landing-untrusted-vpc.subnet_self_links["europe-west1/landing-untrusted-default-ew1"] # subnetwork = module.landing-untrusted-vpc.subnet_self_links["europe-west1/landing-untrusted-default-ew1"]
# alias_ips = {}
# nat = false
# addresses = null
# }] # }]
# tags = ["ew1", "ssh"] # tags = ["ew1", "ssh"]
# service_account_create = true # service_account_create = true
# boot_disk = { # boot_disk = {
# image = "projects/debian-cloud/global/images/family/debian-10" # image = "projects/debian-cloud/global/images/family/debian-10"
# type = "pd-balanced"
# size = 10
# } # }
# options = { # options = {
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true # spot = true
# termination_action = "STOP" # termination_action = "STOP"
# } # }
@ -59,20 +52,13 @@
# network_interfaces = [{ # network_interfaces = [{
# network = module.landing-untrusted-vpc.self_link # network = module.landing-untrusted-vpc.self_link
# subnetwork = module.landing-untrusted-vpc.subnet_self_links["europe-west4/landing-untrusted-default-ew4"] # subnetwork = module.landing-untrusted-vpc.subnet_self_links["europe-west4/landing-untrusted-default-ew4"]
# alias_ips = {}
# nat = false
# addresses = null
# }] # }]
# tags = ["ew4", "ssh"] # tags = ["ew4", "ssh"]
# service_account_create = true # service_account_create = true
# boot_disk = { # boot_disk = {
# image = "projects/debian-cloud/global/images/family/debian-10" # image = "projects/debian-cloud/global/images/family/debian-10"
# type = "pd-balanced"
# size = 10
# } # }
# options = { # options = {
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true # spot = true
# termination_action = "STOP" # termination_action = "STOP"
# } # }
@ -94,20 +80,13 @@
# network_interfaces = [{ # network_interfaces = [{
# network = module.landing-trusted-vpc.self_link # network = module.landing-trusted-vpc.self_link
# subnetwork = module.landing-trusted-vpc.subnet_self_links["europe-west1/landing-trusted-default-ew1"] # subnetwork = module.landing-trusted-vpc.subnet_self_links["europe-west1/landing-trusted-default-ew1"]
# alias_ips = {}
# nat = false
# addresses = null
# }] # }]
# tags = ["ew1", "ssh"] # tags = ["ew1", "ssh"]
# service_account_create = true # service_account_create = true
# boot_disk = { # boot_disk = {
# image = "projects/debian-cloud/global/images/family/debian-10" # image = "projects/debian-cloud/global/images/family/debian-10"
# type = "pd-balanced"
# size = 10
# } # }
# options = { # options = {
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true # spot = true
# termination_action = "STOP" # termination_action = "STOP"
# } # }
@ -127,20 +106,13 @@
# network_interfaces = [{ # network_interfaces = [{
# network = module.landing-trusted-vpc.self_link # network = module.landing-trusted-vpc.self_link
# subnetwork = module.landing-trusted-vpc.subnet_self_links["europe-west4/landing-trusted-default-ew4"] # subnetwork = module.landing-trusted-vpc.subnet_self_links["europe-west4/landing-trusted-default-ew4"]
# alias_ips = {}
# nat = false
# addresses = null
# }] # }]
# tags = ["ew4", "ssh"] # tags = ["ew4", "ssh"]
# service_account_create = true # service_account_create = true
# boot_disk = { # boot_disk = {
# image = "projects/debian-cloud/global/images/family/debian-10" # image = "projects/debian-cloud/global/images/family/debian-10"
# type = "pd-balanced"
# size = 10
# } # }
# options = { # options = {
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true # spot = true
# termination_action = "STOP" # termination_action = "STOP"
# } # }
@ -163,20 +135,13 @@
# network = module.dev-spoke-vpc.self_link # network = module.dev-spoke-vpc.self_link
# # change the subnet name to match the values you are actually using # # change the subnet name to match the values you are actually using
# subnetwork = module.dev-spoke-vpc.subnet_self_links["europe-west1/dev-default-ew1"] # subnetwork = module.dev-spoke-vpc.subnet_self_links["europe-west1/dev-default-ew1"]
# alias_ips = {}
# nat = false
# addresses = null
# }] # }]
# tags = ["ew1", "ssh"] # tags = ["ew1", "ssh"]
# service_account_create = true # service_account_create = true
# boot_disk = { # boot_disk = {
# image = "projects/debian-cloud/global/images/family/debian-10" # image = "projects/debian-cloud/global/images/family/debian-10"
# type = "pd-balanced"
# size = 10
# } # }
# options = { # options = {
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true # spot = true
# termination_action = "STOP" # termination_action = "STOP"
# } # }
@ -197,20 +162,13 @@
# network = module.dev-spoke-vpc.self_link # network = module.dev-spoke-vpc.self_link
# # change the subnet name to match the values you are actually using # # change the subnet name to match the values you are actually using
# subnetwork = module.dev-spoke-vpc.subnet_self_links["europe-west4/dev-default-ew4"] # subnetwork = module.dev-spoke-vpc.subnet_self_links["europe-west4/dev-default-ew4"]
# alias_ips = {}
# nat = false
# addresses = null
# }] # }]
# tags = ["ew4", "ssh"] # tags = ["ew4", "ssh"]
# service_account_create = true # service_account_create = true
# boot_disk = { # boot_disk = {
# image = "projects/debian-cloud/global/images/family/debian-10" # image = "projects/debian-cloud/global/images/family/debian-10"
# type = "pd-balanced"
# size = 10
# } # }
# options = { # options = {
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true # spot = true
# termination_action = "STOP" # termination_action = "STOP"
# } # }
@ -233,9 +191,6 @@
# network = module.prod-spoke-vpc.self_link # network = module.prod-spoke-vpc.self_link
# # change the subnet name to match the values you are actually using # # change the subnet name to match the values you are actually using
# subnetwork = module.prod-spoke-vpc.subnet_self_links["europe-west1/prod-default-ew1"] # subnetwork = module.prod-spoke-vpc.subnet_self_links["europe-west1/prod-default-ew1"]
# alias_ips = {}
# nat = false
# addresses = null
# }] # }]
# tags = ["ew1", "ssh"] # tags = ["ew1", "ssh"]
# service_account_create = true # service_account_create = true
@ -245,8 +200,6 @@
# size = 10 # size = 10
# } # }
# options = { # options = {
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true # spot = true
# termination_action = "STOP" # termination_action = "STOP"
# } # }
@ -267,20 +220,13 @@
# network = module.prod-spoke-vpc.self_link # network = module.prod-spoke-vpc.self_link
# # change the subnet name to match the values you are actually using # # change the subnet name to match the values you are actually using
# subnetwork = module.prod-spoke-vpc.subnet_self_links["europe-west4/prod-default-ew4"] # subnetwork = module.prod-spoke-vpc.subnet_self_links["europe-west4/prod-default-ew4"]
# alias_ips = {}
# nat = false
# addresses = null
# }] # }]
# tags = ["ew4", "ssh"] # tags = ["ew4", "ssh"]
# service_account_create = true # service_account_create = true
# boot_disk = { # boot_disk = {
# image = "projects/debian-cloud/global/images/family/debian-10" # image = "projects/debian-cloud/global/images/family/debian-10"
# type = "pd-balanced"
# size = 10
# } # }
# options = { # options = {
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true # spot = true
# termination_action = "STOP" # termination_action = "STOP"
# } # }

View File

@ -24,20 +24,13 @@
# network_interfaces = [{ # network_interfaces = [{
# network = module.landing-vpc.self_link # network = module.landing-vpc.self_link
# subnetwork = module.landing-vpc.subnet_self_links["europe-west1/landing-default-ew1"] # subnetwork = module.landing-vpc.subnet_self_links["europe-west1/landing-default-ew1"]
# alias_ips = {}
# nat = false
# addresses = null
# }] # }]
# tags = ["ssh"] # tags = ["ssh"]
# service_account_create = true # service_account_create = true
# boot_disk = { # boot_disk = {
# image = "projects/debian-cloud/global/images/family/debian-10" # image = "projects/debian-cloud/global/images/family/debian-10"
# type = "pd-balanced"
# size = 10
# } # }
# options = { # options = {
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true # spot = true
# termination_action = "STOP" # termination_action = "STOP"
# } # }
@ -58,20 +51,13 @@
# network = module.dev-spoke-vpc.self_link # network = module.dev-spoke-vpc.self_link
# # change the subnet name to match the values you are actually using # # change the subnet name to match the values you are actually using
# subnetwork = module.dev-spoke-vpc.subnet_self_links["europe-west1/dev-default-ew1"] # subnetwork = module.dev-spoke-vpc.subnet_self_links["europe-west1/dev-default-ew1"]
# alias_ips = {}
# nat = false
# addresses = null
# }] # }]
# tags = ["ssh"] # tags = ["ssh"]
# service_account_create = true # service_account_create = true
# boot_disk = { # boot_disk = {
# image = "projects/debian-cloud/global/images/family/debian-10" # image = "projects/debian-cloud/global/images/family/debian-10"
# type = "pd-balanced"
# size = 10
# } # }
# options = { # options = {
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true # spot = true
# termination_action = "STOP" # termination_action = "STOP"
# } # }
@ -92,20 +78,13 @@
# network = module.prod-spoke-vpc.self_link # network = module.prod-spoke-vpc.self_link
# # change the subnet name to match the values you are actually using # # change the subnet name to match the values you are actually using
# subnetwork = module.prod-spoke-vpc.subnet_self_links["europe-west1/prod-default-ew1"] # subnetwork = module.prod-spoke-vpc.subnet_self_links["europe-west1/prod-default-ew1"]
# alias_ips = {}
# nat = false
# addresses = null
# }] # }]
# tags = ["ssh"] # tags = ["ssh"]
# service_account_create = true # service_account_create = true
# boot_disk = { # boot_disk = {
# image = "projects/debian-cloud/global/images/family/debian-10" # image = "projects/debian-cloud/global/images/family/debian-10"
# type = "pd-balanced"
# size = 10
# } # }
# options = { # options = {
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true # spot = true
# termination_action = "STOP" # termination_action = "STOP"
# } # }

View File

@ -24,20 +24,13 @@
# network_interfaces = [{ # network_interfaces = [{
# network = module.landing-vpc.self_link # network = module.landing-vpc.self_link
# subnetwork = module.landing-vpc.subnet_self_links["europe-west1/landing-default-ew1"] # subnetwork = module.landing-vpc.subnet_self_links["europe-west1/landing-default-ew1"]
# alias_ips = {}
# nat = false
# addresses = null
# }] # }]
# tags = ["ssh"] # tags = ["ssh"]
# service_account_create = true # service_account_create = true
# boot_disk = { # boot_disk = {
# image = "projects/debian-cloud/global/images/family/debian-10" # image = "projects/debian-cloud/global/images/family/debian-10"
# type = "pd-balanced"
# size = 10
# } # }
# options = { # options = {
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true # spot = true
# termination_action = "STOP" # termination_action = "STOP"
# } # }
@ -58,20 +51,13 @@
# network = module.dev-spoke-vpc.self_link # network = module.dev-spoke-vpc.self_link
# # change the subnet name to match the values you are actually using # # change the subnet name to match the values you are actually using
# subnetwork = module.dev-spoke-vpc.subnet_self_links["europe-west1/dev-default-ew1"] # subnetwork = module.dev-spoke-vpc.subnet_self_links["europe-west1/dev-default-ew1"]
# alias_ips = {}
# nat = false
# addresses = null
# }] # }]
# tags = ["ssh"] # tags = ["ssh"]
# service_account_create = true # service_account_create = true
# boot_disk = { # boot_disk = {
# image = "projects/debian-cloud/global/images/family/debian-10" # image = "projects/debian-cloud/global/images/family/debian-10"
# type = "pd-balanced"
# size = 10
# } # }
# options = { # options = {
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true # spot = true
# termination_action = "STOP" # termination_action = "STOP"
# } # }
@ -92,20 +78,13 @@
# network = module.prod-spoke-vpc.self_link # network = module.prod-spoke-vpc.self_link
# # change the subnet name to match the values you are actually using # # change the subnet name to match the values you are actually using
# subnetwork = module.prod-spoke-vpc.subnet_self_links["europe-west1/prod-default-ew1"] # subnetwork = module.prod-spoke-vpc.subnet_self_links["europe-west1/prod-default-ew1"]
# alias_ips = {}
# nat = false
# addresses = null
# }] # }]
# tags = ["ssh"] # tags = ["ssh"]
# service_account_create = true # service_account_create = true
# boot_disk = { # boot_disk = {
# image = "projects/debian-cloud/global/images/family/debian-10" # image = "projects/debian-cloud/global/images/family/debian-10"
# type = "pd-balanced"
# size = 10
# } # }
# options = { # options = {
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true # spot = true
# termination_action = "STOP" # termination_action = "STOP"
# } # }

View File

@ -22,8 +22,6 @@ module "simple-vm-example" {
network_interfaces = [{ network_interfaces = [{
network = var.vpc.self_link network = var.vpc.self_link
subnetwork = var.subnet.self_link subnetwork = var.subnet.self_link
nat = false
addresses = null
}] }]
service_account_create = true service_account_create = true
} }
@ -42,16 +40,12 @@ module "spot-vm-example" {
zone = "europe-west1-b" zone = "europe-west1-b"
name = "test" name = "test"
options = { options = {
allow_stopping_for_update = true
deletion_protection = false
spot = true spot = true
termination_action = "STOP" termination_action = "STOP"
} }
network_interfaces = [{ network_interfaces = [{
network = var.vpc.self_link network = var.vpc.self_link
subnetwork = var.subnet.self_link subnetwork = var.subnet.self_link
nat = false
addresses = null
}] }]
service_account_create = true service_account_create = true
} }
@ -79,18 +73,14 @@ module "simple-vm-example" {
network_interfaces = [{ network_interfaces = [{
network = var.vpc.self_link network = var.vpc.self_link
subnetwork = var.subnet.self_link subnetwork = var.subnet.self_link
nat = false
addresses = null
}] }]
attached_disks = [{ attached_disks = [{
name = "repd-1" name = "repd-1"
size = null size = 10
source_type = "attach" source_type = "attach"
source = "regions/${var.region}/disks/repd-test-1" source = "regions/${var.region}/disks/repd-test-1"
options = { options = {
mode = null
replica_zone = "${var.region}-c" replica_zone = "${var.region}-c"
type = null
} }
}] }]
service_account_create = true service_account_create = true
@ -109,18 +99,14 @@ module "simple-vm-example" {
network_interfaces = [{ network_interfaces = [{
network = var.vpc.self_link network = var.vpc.self_link
subnetwork = var.subnet.self_link subnetwork = var.subnet.self_link
nat = false
addresses = null
}] }]
attached_disks = [{ attached_disks = [{
name = "repd" name = "repd"
size = null size = 10
source_type = "attach" source_type = "attach"
source = "https://www.googleapis.com/compute/v1/projects/${var.project_id}/regions/${var.region}/disks/repd-test-1" source = "https://www.googleapis.com/compute/v1/projects/${var.project_id}/regions/${var.region}/disks/repd-test-1"
options = { options = {
mode = null
replica_zone = "${var.region}-c" replica_zone = "${var.region}-c"
type = null
} }
}] }]
service_account_create = true service_account_create = true
@ -142,27 +128,19 @@ module "kms-vm-example" {
network_interfaces = [{ network_interfaces = [{
network = var.vpc.self_link network = var.vpc.self_link
subnetwork = var.subnet.self_link subnetwork = var.subnet.self_link
nat = false
addresses = null
}] }]
attached_disks = [ attached_disks = [
{ {
name = "attached-disk" name = "attached-disk"
size = 10 size = 10
source = null
source_type = null
options = null
} }
] ]
service_account_create = true service_account_create = true
boot_disk = { boot_disk = {
image = "projects/debian-cloud/global/images/family/debian-10" image = "projects/debian-cloud/global/images/family/debian-10"
type = "pd-ssd"
size = 10
} }
encryption = { encryption = {
encrypt_boot = true encrypt_boot = true
disk_encryption_key_raw = null
kms_key_self_link = var.kms_key.self_link kms_key_self_link = var.kms_key.self_link
} }
} }
@ -182,17 +160,10 @@ module "vm-with-alias-ips" {
network_interfaces = [{ network_interfaces = [{
network = var.vpc.self_link network = var.vpc.self_link
subnetwork = var.subnet.self_link subnetwork = var.subnet.self_link
nat = false
addresses = null
}]
network_interface_options = {
0 = {
alias_ips = { alias_ips = {
alias1 = "10.16.0.10/32" alias1 = "10.16.0.10/32"
} }
nic_type = null }]
}
}
service_account_create = true service_account_create = true
} }
# tftest modules=1 resources=2 # tftest modules=1 resources=2
@ -231,20 +202,12 @@ module "vm-with-gvnic" {
boot_disk = { boot_disk = {
image = google_compute_image.cos-gvnic.self_link image = google_compute_image.cos-gvnic.self_link
type = "pd-ssd" type = "pd-ssd"
size = 10
} }
network_interfaces = [{ network_interfaces = [{
network = var.vpc.self_link network = var.vpc.self_link
subnetwork = var.subnet.self_link subnetwork = var.subnet.self_link
nat = false
addresses = null
}]
network_interface_options = {
0 = {
alias_ips = null
nic_type = "GVNIC" nic_type = "GVNIC"
} }]
}
service_account_create = true service_account_create = true
} }
# tftest modules=1 resources=3 # tftest modules=1 resources=3
@ -263,21 +226,14 @@ module "cos-test" {
network_interfaces = [{ network_interfaces = [{
network = var.vpc.self_link network = var.vpc.self_link
subnetwork = var.subnet.self_link subnetwork = var.subnet.self_link
nat = false
addresses = null
}] }]
boot_disk = { boot_disk = {
image = "projects/cos-cloud/global/images/family/cos-stable" image = "projects/cos-cloud/global/images/family/cos-stable"
type = "pd-ssd"
size = 10
} }
attached_disks = [ attached_disks = [
{ {
name = "disk-1" name = "disk-1"
size = 10 size = 10
source = null
source_type = null
options = null
} }
] ]
service_account = "vm-default@my-project.iam.gserviceaccount.com" service_account = "vm-default@my-project.iam.gserviceaccount.com"
@ -303,13 +259,9 @@ module "instance-group" {
network_interfaces = [{ network_interfaces = [{
network = var.vpc.self_link network = var.vpc.self_link
subnetwork = var.subnet.self_link subnetwork = var.subnet.self_link
nat = false
addresses = null
}] }]
boot_disk = { boot_disk = {
image = "projects/cos-cloud/global/images/family/cos-stable" image = "projects/cos-cloud/global/images/family/cos-stable"
type = "pd-ssd"
size = 10
} }
service_account = var.service_account.email service_account = var.service_account.email
service_account_scopes = ["https://www.googleapis.com/auth/cloud-platform"] service_account_scopes = ["https://www.googleapis.com/auth/cloud-platform"]
@ -326,36 +278,34 @@ module "instance-group" {
| name | description | type | required | default | | name | description | type | required | default |
|---|---|:---:|:---:|:---:| |---|---|:---:|:---:|:---:|
| [name](variables.tf#L160) | Instance name. | <code>string</code> | ✓ | | | [name](variables.tf#L163) | Instance name. | <code>string</code> | ✓ | |
| [network_interfaces](variables.tf#L174) | Network interfaces configuration. Use self links for Shared VPC, set addresses to null if not needed. | <code title="list&#40;object&#40;&#123;&#10; nat &#61; bool&#10; network &#61; string&#10; subnetwork &#61; string&#10; addresses &#61; object&#40;&#123;&#10; internal &#61; string&#10; external &#61; string&#10; &#125;&#41;&#10;&#125;&#41;&#41;">list&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | ✓ | | | [network_interfaces](variables.tf#L168) | Network interfaces configuration. Use self links for Shared VPC, set addresses to null if not needed. | <code title="list&#40;object&#40;&#123;&#10; nat &#61; optional&#40;bool, false&#41;&#10; network &#61; string&#10; subnetwork &#61; string&#10; addresses &#61; optional&#40;object&#40;&#123;&#10; internal &#61; string&#10; external &#61; string&#10; &#125;&#41;, null&#41;&#10; alias_ips &#61; optional&#40;map&#40;string&#41;, &#123;&#125;&#41;&#10; nic_type &#61; optional&#40;string&#41;&#10;&#125;&#41;&#41;">list&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | ✓ | |
| [project_id](variables.tf#L209) | Project id. | <code>string</code> | ✓ | | | [project_id](variables.tf#L205) | Project id. | <code>string</code> | ✓ | |
| [zone](variables.tf#L268) | Compute zone. | <code>string</code> | ✓ | | | [zone](variables.tf#L264) | Compute zone. | <code>string</code> | ✓ | |
| [attached_disk_defaults](variables.tf#L17) | Defaults for attached disks options. | <code title="object&#40;&#123;&#10; mode &#61; string&#10; replica_zone &#61; string&#10; type &#61; string&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code title="&#123;&#10; auto_delete &#61; true&#10; mode &#61; &#34;READ_WRITE&#34;&#10; replica_zone &#61; null&#10; type &#61; &#34;pd-balanced&#34;&#10;&#125;">&#123;&#8230;&#125;</code> | | [attached_disk_defaults](variables.tf#L17) | Defaults for attached disks options. | <code title="object&#40;&#123;&#10; mode &#61; string&#10; replica_zone &#61; string&#10; type &#61; string&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code title="&#123;&#10; mode &#61; &#34;READ_WRITE&#34;&#10; replica_zone &#61; null&#10; type &#61; &#34;pd-balanced&#34;&#10;&#125;">&#123;&#8230;&#125;</code> |
| [attached_disks](variables.tf#L32) | Additional disks, if options is null defaults will be used in its place. Source type is one of 'image' (zonal disks in vms and template), 'snapshot' (vm), 'existing', and null. | <code title="list&#40;object&#40;&#123;&#10; name &#61; string&#10; size &#61; string&#10; source &#61; string&#10; source_type &#61; string&#10; options &#61; object&#40;&#123;&#10; mode &#61; string&#10; replica_zone &#61; string&#10; type &#61; string&#10; &#125;&#41;&#10;&#125;&#41;&#41;">list&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#91;&#93;</code> | | [attached_disks](variables.tf#L31) | Additional disks, if options is null defaults will be used in its place. Source type is one of 'image' (zonal disks in vms and template), 'snapshot' (vm), 'existing', and null. | <code title="list&#40;object&#40;&#123;&#10; name &#61; string&#10; size &#61; string&#10; source &#61; optional&#40;string&#41;&#10; source_type &#61; optional&#40;string&#41;&#10; options &#61; optional&#40;&#10; object&#40;&#123;&#10; mode &#61; optional&#40;string, &#34;READ_WRITE&#34;&#41;&#10; replica_zone &#61; optional&#40;string&#41;&#10; type &#61; optional&#40;string, &#34;pd-balanced&#34;&#41;&#10; &#125;&#41;,&#10; &#123;&#10; mode &#61; &#34;READ_WRITE&#34;&#10; replica_zone &#61; null&#10; type &#61; &#34;pd-balanced&#34;&#10; &#125;&#10; &#41;&#10;&#125;&#41;&#41;">list&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#91;&#93;</code> |
| [boot_disk](variables.tf#L58) | Boot disk properties. | <code title="object&#40;&#123;&#10; image &#61; string&#10; size &#61; number&#10; type &#61; string&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code title="&#123;&#10; image &#61; &#34;projects&#47;debian-cloud&#47;global&#47;images&#47;family&#47;debian-11&#34;&#10; type &#61; &#34;pd-balanced&#34;&#10; size &#61; 10&#10;&#125;">&#123;&#8230;&#125;</code> | | [boot_disk](variables.tf#L64) | Boot disk properties. | <code title="object&#40;&#123;&#10; auto_delete &#61; optional&#40;bool, true&#41;&#10; image &#61; optional&#40;string, &#34;projects&#47;debian-cloud&#47;global&#47;images&#47;family&#47;debian-11&#34;&#41;&#10; size &#61; optional&#40;number, 10&#41;&#10; type &#61; optional&#40;string, &#34;pd-balanced&#34;&#41;&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code title="&#123;&#10; auto_delete &#61; true&#10; image &#61; &#34;projects&#47;debian-cloud&#47;global&#47;images&#47;family&#47;debian-11&#34;&#10; type &#61; &#34;pd-balanced&#34;&#10; size &#61; 10&#10;&#125;">&#123;&#8230;&#125;</code> |
| [boot_disk_delete](variables.tf#L72) | Auto delete boot disk. | <code>bool</code> | | <code>true</code> | | [can_ip_forward](variables.tf#L80) | Enable IP forwarding. | <code>bool</code> | | <code>false</code> |
| [can_ip_forward](variables.tf#L78) | Enable IP forwarding. | <code>bool</code> | | <code>false</code> | | [confidential_compute](variables.tf#L86) | Enable Confidential Compute for these instances. | <code>bool</code> | | <code>false</code> |
| [confidential_compute](variables.tf#L84) | Enable Confidential Compute for these instances. | <code>bool</code> | | <code>false</code> | | [create_template](variables.tf#L92) | Create instance template instead of instances. | <code>bool</code> | | <code>false</code> |
| [create_template](variables.tf#L90) | Create instance template instead of instances. | <code>bool</code> | | <code>false</code> | | [description](variables.tf#L97) | Description of a Compute Instance. | <code>string</code> | | <code>&#34;Managed by the compute-vm Terraform module.&#34;</code> |
| [description](variables.tf#L95) | Description of a Compute Instance. | <code>string</code> | | <code>&#34;Managed by the compute-vm Terraform module.&#34;</code> | | [enable_display](variables.tf#L103) | Enable virtual display on the instances. | <code>bool</code> | | <code>false</code> |
| [enable_display](variables.tf#L100) | Enable virtual display on the instances. | <code>bool</code> | | <code>false</code> | | [encryption](variables.tf#L109) | Encryption options. Only one of kms_key_self_link and disk_encryption_key_raw may be set. If needed, you can specify to encrypt or not the boot disk. | <code title="object&#40;&#123;&#10; encrypt_boot &#61; optional&#40;bool, false&#41;&#10; disk_encryption_key_raw &#61; optional&#40;string&#41;&#10; kms_key_self_link &#61; optional&#40;string&#41;&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>null</code> |
| [encryption](variables.tf#L106) | Encryption options. Only one of kms_key_self_link and disk_encryption_key_raw may be set. If needed, you can specify to encrypt or not the boot disk. | <code title="object&#40;&#123;&#10; encrypt_boot &#61; bool&#10; disk_encryption_key_raw &#61; string&#10; kms_key_self_link &#61; string&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>null</code> | | [group](variables.tf#L119) | Define this variable to create an instance group for instances. Disabled for template use. | <code title="object&#40;&#123;&#10; named_ports &#61; map&#40;number&#41;&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>null</code> |
| [group](variables.tf#L116) | Define this variable to create an instance group for instances. Disabled for template use. | <code title="object&#40;&#123;&#10; named_ports &#61; map&#40;number&#41;&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>null</code> | | [hostname](variables.tf#L127) | Instance FQDN name. | <code>string</code> | | <code>null</code> |
| [hostname](variables.tf#L124) | Instance FQDN name. | <code>string</code> | | <code>null</code> | | [iam](variables.tf#L133) | IAM bindings in {ROLE => [MEMBERS]} format. | <code>map&#40;list&#40;string&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [iam](variables.tf#L130) | IAM bindings in {ROLE => [MEMBERS]} format. | <code>map&#40;list&#40;string&#41;&#41;</code> | | <code>&#123;&#125;</code> | | [instance_type](variables.tf#L139) | Instance type. | <code>string</code> | | <code>&#34;f1-micro&#34;</code> |
| [instance_type](variables.tf#L136) | Instance type. | <code>string</code> | | <code>&#34;f1-micro&#34;</code> | | [labels](variables.tf#L145) | Instance labels. | <code>map&#40;string&#41;</code> | | <code>&#123;&#125;</code> |
| [labels](variables.tf#L142) | Instance labels. | <code>map&#40;string&#41;</code> | | <code>&#123;&#125;</code> | | [metadata](variables.tf#L151) | Instance metadata. | <code>map&#40;string&#41;</code> | | <code>&#123;&#125;</code> |
| [metadata](variables.tf#L148) | Instance metadata. | <code>map&#40;string&#41;</code> | | <code>&#123;&#125;</code> | | [min_cpu_platform](variables.tf#L157) | Minimum CPU platform. | <code>string</code> | | <code>null</code> |
| [min_cpu_platform](variables.tf#L154) | Minimum CPU platform. | <code>string</code> | | <code>null</code> | | [options](variables.tf#L183) | Instance options. | <code title="object&#40;&#123;&#10; allow_stopping_for_update &#61; optional&#40;bool, true&#41;&#10; deletion_protection &#61; optional&#40;bool, false&#41;&#10; spot &#61; optional&#40;bool, false&#41;&#10; termination_action &#61; optional&#40;string&#41;&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code title="&#123;&#10; allow_stopping_for_update &#61; true&#10; deletion_protection &#61; false&#10; spot &#61; false&#10; termination_action &#61; null&#10;&#125;">&#123;&#8230;&#125;</code> |
| [network_interface_options](variables.tf#L165) | Network interfaces extended options. The key is the index of the inteface to configure. The value is an object with alias_ips and nic_type. Set alias_ips or nic_type to null if you need only one of them. | <code title="map&#40;object&#40;&#123;&#10; alias_ips &#61; map&#40;string&#41;&#10; nic_type &#61; string&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> | | [scratch_disks](variables.tf#L210) | Scratch disks configuration. | <code title="object&#40;&#123;&#10; count &#61; number&#10; interface &#61; string&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code title="&#123;&#10; count &#61; 0&#10; interface &#61; &#34;NVME&#34;&#10;&#125;">&#123;&#8230;&#125;</code> |
| [options](variables.tf#L187) | Instance options. | <code title="object&#40;&#123;&#10; allow_stopping_for_update &#61; bool&#10; deletion_protection &#61; bool&#10; spot &#61; bool&#10; termination_action &#61; string&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code title="&#123;&#10; allow_stopping_for_update &#61; true&#10; deletion_protection &#61; false&#10; spot &#61; false&#10; termination_action &#61; null&#10;&#125;">&#123;&#8230;&#125;</code> | | [service_account](variables.tf#L222) | Service account email. Unused if service account is auto-created. | <code>string</code> | | <code>null</code> |
| [scratch_disks](variables.tf#L214) | Scratch disks configuration. | <code title="object&#40;&#123;&#10; count &#61; number&#10; interface &#61; string&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code title="&#123;&#10; count &#61; 0&#10; interface &#61; &#34;NVME&#34;&#10;&#125;">&#123;&#8230;&#125;</code> | | [service_account_create](variables.tf#L228) | Auto-create service account. | <code>bool</code> | | <code>false</code> |
| [service_account](variables.tf#L226) | Service account email. Unused if service account is auto-created. | <code>string</code> | | <code>null</code> | | [service_account_scopes](variables.tf#L236) | Scopes applied to service account. | <code>list&#40;string&#41;</code> | | <code>&#91;&#93;</code> |
| [service_account_create](variables.tf#L232) | Auto-create service account. | <code>bool</code> | | <code>false</code> | | [shielded_config](variables.tf#L242) | Shielded VM configuration of the instances. | <code title="object&#40;&#123;&#10; enable_secure_boot &#61; bool&#10; enable_vtpm &#61; bool&#10; enable_integrity_monitoring &#61; bool&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>null</code> |
| [service_account_scopes](variables.tf#L240) | Scopes applied to service account. | <code>list&#40;string&#41;</code> | | <code>&#91;&#93;</code> | | [tag_bindings](variables.tf#L252) | Tag bindings for this instance, in key => tag value id format. | <code>map&#40;string&#41;</code> | | <code>null</code> |
| [shielded_config](variables.tf#L246) | Shielded VM configuration of the instances. | <code title="object&#40;&#123;&#10; enable_secure_boot &#61; bool&#10; enable_vtpm &#61; bool&#10; enable_integrity_monitoring &#61; bool&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>null</code> | | [tags](variables.tf#L258) | Instance network tags for firewall rule targets. | <code>list&#40;string&#41;</code> | | <code>&#91;&#93;</code> |
| [tag_bindings](variables.tf#L256) | Tag bindings for this instance, in key => tag value id format. | <code>map&#40;string&#41;</code> | | <code>null</code> |
| [tags](variables.tf#L262) | Instance network tags for firewall rule targets. | <code>list&#40;string&#41;</code> | | <code>&#91;&#93;</code> |
## Outputs ## Outputs

View File

@ -29,12 +29,6 @@ locals {
for k, v in local.attached_disks : for k, v in local.attached_disks :
k => v if try(v.options.replica_zone, null) == null k => v if try(v.options.replica_zone, null) == null
} }
network_interface_options = {
for i, v in var.network_interfaces : i => lookup(var.network_interface_options, i, {
alias_ips = null,
nic_type = null
})
}
on_host_maintenance = ( on_host_maintenance = (
var.options.spot || var.confidential_compute var.options.spot || var.confidential_compute
? "TERMINATE" ? "TERMINATE"
@ -169,7 +163,7 @@ resource "google_compute_instance" "default" {
} }
boot_disk { boot_disk {
auto_delete = var.boot_disk_delete auto_delete = var.boot_disk.auto_delete
initialize_params { initialize_params {
type = var.boot_disk.type type = var.boot_disk.type
image = var.boot_disk.image image = var.boot_disk.image
@ -200,14 +194,14 @@ resource "google_compute_instance" "default" {
} }
} }
dynamic "alias_ip_range" { dynamic "alias_ip_range" {
for_each = local.network_interface_options[config.key].alias_ips != null ? local.network_interface_options[config.key].alias_ips : {} for_each = config.value.alias_ips
iterator = config_alias iterator = config_alias
content { content {
subnetwork_range_name = config_alias.key subnetwork_range_name = config_alias.key
ip_cidr_range = config_alias.value ip_cidr_range = config_alias.value
} }
} }
nic_type = local.network_interface_options[config.key].nic_type nic_type = config.value.nic_type
} }
} }
@ -272,7 +266,7 @@ resource "google_compute_instance_template" "default" {
labels = var.labels labels = var.labels
disk { disk {
auto_delete = var.boot_disk_delete auto_delete = var.boot_disk.auto_delete
boot = true boot = true
disk_size_gb = var.boot_disk.size disk_size_gb = var.boot_disk.size
disk_type = var.boot_disk.type disk_type = var.boot_disk.type
@ -334,14 +328,14 @@ resource "google_compute_instance_template" "default" {
} }
} }
dynamic "alias_ip_range" { dynamic "alias_ip_range" {
for_each = local.network_interface_options[config.key].alias_ips != null ? local.network_interface_options[config.key].alias_ips : {} for_each = config.value.alias_ips
iterator = config_alias iterator = config_alias
content { content {
subnetwork_range_name = config_alias.key subnetwork_range_name = config_alias.key
ip_cidr_range = config_alias.value ip_cidr_range = config_alias.value
} }
} }
nic_type = local.network_interface_options[config.key].nic_type nic_type = config.value.nic_type
} }
} }

View File

@ -22,7 +22,6 @@ variable "attached_disk_defaults" {
type = string type = string
}) })
default = { default = {
auto_delete = true
mode = "READ_WRITE" mode = "READ_WRITE"
replica_zone = null replica_zone = null
type = "pd-balanced" type = "pd-balanced"
@ -34,13 +33,20 @@ variable "attached_disks" {
type = list(object({ type = list(object({
name = string name = string
size = string size = string
source = string source = optional(string)
source_type = string source_type = optional(string)
options = object({ options = optional(
mode = string object({
replica_zone = string mode = optional(string, "READ_WRITE")
type = string replica_zone = optional(string)
}) type = optional(string, "pd-balanced")
}),
{
mode = "READ_WRITE"
replica_zone = null
type = "pd-balanced"
}
)
})) }))
default = [] default = []
validation { validation {
@ -58,23 +64,19 @@ variable "attached_disks" {
variable "boot_disk" { variable "boot_disk" {
description = "Boot disk properties." description = "Boot disk properties."
type = object({ type = object({
image = string auto_delete = optional(bool, true)
size = number image = optional(string, "projects/debian-cloud/global/images/family/debian-11")
type = string size = optional(number, 10)
type = optional(string, "pd-balanced")
}) })
default = { default = {
auto_delete = true
image = "projects/debian-cloud/global/images/family/debian-11" image = "projects/debian-cloud/global/images/family/debian-11"
type = "pd-balanced" type = "pd-balanced"
size = 10 size = 10
} }
} }
variable "boot_disk_delete" {
description = "Auto delete boot disk."
type = bool
default = true
}
variable "can_ip_forward" { variable "can_ip_forward" {
description = "Enable IP forwarding." description = "Enable IP forwarding."
type = bool type = bool
@ -97,6 +99,7 @@ variable "description" {
type = string type = string
default = "Managed by the compute-vm Terraform module." default = "Managed by the compute-vm Terraform module."
} }
variable "enable_display" { variable "enable_display" {
description = "Enable virtual display on the instances." description = "Enable virtual display on the instances."
type = bool type = bool
@ -106,9 +109,9 @@ variable "enable_display" {
variable "encryption" { variable "encryption" {
description = "Encryption options. Only one of kms_key_self_link and disk_encryption_key_raw may be set. If needed, you can specify to encrypt or not the boot disk." description = "Encryption options. Only one of kms_key_self_link and disk_encryption_key_raw may be set. If needed, you can specify to encrypt or not the boot disk."
type = object({ type = object({
encrypt_boot = bool encrypt_boot = optional(bool, false)
disk_encryption_key_raw = string disk_encryption_key_raw = optional(string)
kms_key_self_link = string kms_key_self_link = optional(string)
}) })
default = null default = null
} }
@ -162,35 +165,28 @@ variable "name" {
type = string type = string
} }
variable "network_interface_options" {
description = "Network interfaces extended options. The key is the index of the inteface to configure. The value is an object with alias_ips and nic_type. Set alias_ips or nic_type to null if you need only one of them."
type = map(object({
alias_ips = map(string)
nic_type = string
}))
default = {}
}
variable "network_interfaces" { variable "network_interfaces" {
description = "Network interfaces configuration. Use self links for Shared VPC, set addresses to null if not needed." description = "Network interfaces configuration. Use self links for Shared VPC, set addresses to null if not needed."
type = list(object({ type = list(object({
nat = bool nat = optional(bool, false)
network = string network = string
subnetwork = string subnetwork = string
addresses = object({ addresses = optional(object({
internal = string internal = string
external = string external = string
}) }), null)
alias_ips = optional(map(string), {})
nic_type = optional(string)
})) }))
} }
variable "options" { variable "options" {
description = "Instance options." description = "Instance options."
type = object({ type = object({
allow_stopping_for_update = bool allow_stopping_for_update = optional(bool, true)
deletion_protection = bool deletion_protection = optional(bool, false)
spot = bool spot = optional(bool, false)
termination_action = string termination_action = optional(string)
}) })
default = { default = {
allow_stopping_for_update = true allow_stopping_for_update = true

View File

@ -16,27 +16,13 @@
variable "attached_disks" { variable "attached_disks" {
description = "Additional disks, if options is null defaults will be used in its place. Source type is one of 'image' (zonal disks in vms and template), 'snapshot' (vm), 'existing', and null." description = "Additional disks, if options is null defaults will be used in its place. Source type is one of 'image' (zonal disks in vms and template), 'snapshot' (vm), 'existing', and null."
type = list(object({ type = any
name = string
size = string
source = string
source_type = string
options = object({
mode = string
replica_zone = string
type = string
})
}))
default = [] default = []
} }
variable "attached_disk_defaults" { variable "attached_disk_defaults" {
description = "Defaults for attached disks options." description = "Defaults for attached disks options."
type = object({ type = any
mode = string
replica_zone = string
type = string
})
default = { default = {
mode = "READ_WRITE" mode = "READ_WRITE"
replica_zone = null replica_zone = null
@ -70,31 +56,13 @@ variable "metadata" {
} }
variable "network_interfaces" { variable "network_interfaces" {
type = list(object({ type = any
nat = bool
network = string
subnetwork = string
addresses = object({
internal = string
external = string
})
}))
default = [{ default = [{
network = "https://www.googleapis.com/compute/v1/projects/my-project/global/networks/default", network = "https://www.googleapis.com/compute/v1/projects/my-project/global/networks/default",
subnetwork = "https://www.googleapis.com/compute/v1/projects/my-project/regions/europe-west1/subnetworks/default-default", subnetwork = "https://www.googleapis.com/compute/v1/projects/my-project/regions/europe-west1/subnetworks/default-default",
nat = false,
addresses = null
}] }]
} }
variable "network_interface_options" {
type = map(object({
alias_ips = map(string)
nic_type = string
}))
default = {}
}
variable "service_account_create" { variable "service_account_create" {
type = bool type = bool
default = false default = false