From 1df13fff1238fc63f920f78609ddaa65c63cb99b Mon Sep 17 00:00:00 2001 From: Abhishek Tiwari Date: Fri, 13 Dec 2024 21:08:48 +0000 Subject: [PATCH] fix: make project_id and region as required input for instance_template --- examples/instance_template/additional_disks/main.tf | 1 + examples/instance_template/alias_ip_range/main.tf | 1 + examples/instance_template/simple/main.tf | 1 + examples/mig/autoscaler/main.tf | 1 + examples/mig/healthcheck/main.tf | 1 + examples/mig/simple/main.tf | 1 + examples/umig/named_ports/main.tf | 1 + examples/umig/simple/main.tf | 1 + examples/umig/static_ips/main.tf | 1 + modules/instance_template/README.md | 4 ++-- modules/instance_template/metadata.yaml | 2 ++ modules/instance_template/variables.tf | 2 -- .../preemptible_and_regular_instance_templates/README.md | 3 ++- modules/preemptible_and_regular_instance_templates/main.tf | 2 ++ .../metadata.yaml | 5 +++++ .../preemptible_and_regular_instance_templates/variables.tf | 6 +++++- 16 files changed, 27 insertions(+), 6 deletions(-) diff --git a/examples/instance_template/additional_disks/main.tf b/examples/instance_template/additional_disks/main.tf index dd03111c..d57f2fca 100644 --- a/examples/instance_template/additional_disks/main.tf +++ b/examples/instance_template/additional_disks/main.tf @@ -25,6 +25,7 @@ module "instance_template" { version = "~> 12.0" project_id = var.project_id + region = var.region subnetwork = var.subnetwork service_account = var.service_account name_prefix = "additional-disks" diff --git a/examples/instance_template/alias_ip_range/main.tf b/examples/instance_template/alias_ip_range/main.tf index c9cb989c..48a4656a 100644 --- a/examples/instance_template/alias_ip_range/main.tf +++ b/examples/instance_template/alias_ip_range/main.tf @@ -29,6 +29,7 @@ module "instance_template" { version = "~> 12.0" project_id = var.project_id + region = var.region subnetwork = var.subnetwork service_account = var.service_account name_prefix = "alias-ip-range" diff --git a/examples/instance_template/simple/main.tf b/examples/instance_template/simple/main.tf index 69d468cd..1b804abb 100644 --- a/examples/instance_template/simple/main.tf +++ b/examples/instance_template/simple/main.tf @@ -36,6 +36,7 @@ module "instance_template" { version = "~> 12.0" project_id = var.project_id + region = var.region subnetwork = var.subnetwork stack_type = "IPV4_ONLY" service_account = var.service_account diff --git a/examples/mig/autoscaler/main.tf b/examples/mig/autoscaler/main.tf index a5de5599..c3f95e4a 100644 --- a/examples/mig/autoscaler/main.tf +++ b/examples/mig/autoscaler/main.tf @@ -31,6 +31,7 @@ module "instance_template" { version = "~> 12.0" project_id = var.project_id + region = var.region subnetwork = var.subnetwork service_account = var.service_account } diff --git a/examples/mig/healthcheck/main.tf b/examples/mig/healthcheck/main.tf index b14cbf56..a9f2ed07 100644 --- a/examples/mig/healthcheck/main.tf +++ b/examples/mig/healthcheck/main.tf @@ -55,6 +55,7 @@ module "instance_template" { version = "~> 12.0" project_id = var.project_id + region = var.region subnetwork = google_compute_subnetwork.main.name service_account = var.service_account } diff --git a/examples/mig/simple/main.tf b/examples/mig/simple/main.tf index 3eafbfb0..da03a435 100644 --- a/examples/mig/simple/main.tf +++ b/examples/mig/simple/main.tf @@ -29,6 +29,7 @@ module "instance_template" { version = "~> 12.0" project_id = var.project_id + region = var.region subnetwork = var.subnetwork service_account = var.service_account subnetwork_project = var.project_id diff --git a/examples/umig/named_ports/main.tf b/examples/umig/named_ports/main.tf index 04674aaf..309b46df 100644 --- a/examples/umig/named_ports/main.tf +++ b/examples/umig/named_ports/main.tf @@ -25,6 +25,7 @@ module "instance_template" { version = "~> 12.0" project_id = var.project_id + region = var.region subnetwork = var.subnetwork service_account = var.service_account } diff --git a/examples/umig/simple/main.tf b/examples/umig/simple/main.tf index ae491cfc..2a5d0d95 100644 --- a/examples/umig/simple/main.tf +++ b/examples/umig/simple/main.tf @@ -25,6 +25,7 @@ module "instance_template" { version = "~> 12.0" project_id = var.project_id + region = var.region subnetwork = var.subnetwork subnetwork_project = var.project_id service_account = var.service_account diff --git a/examples/umig/static_ips/main.tf b/examples/umig/static_ips/main.tf index 7d494c6b..1a5b4cfd 100644 --- a/examples/umig/static_ips/main.tf +++ b/examples/umig/static_ips/main.tf @@ -25,6 +25,7 @@ module "instance_template" { version = "~> 12.0" project_id = var.project_id + region = var.region subnetwork = var.subnetwork subnetwork_project = var.project_id service_account = var.service_account diff --git a/modules/instance_template/README.md b/modules/instance_template/README.md index 0127382c..5d3dd7a9 100644 --- a/modules/instance_template/README.md +++ b/modules/instance_template/README.md @@ -44,8 +44,8 @@ See the [simple](../../examples/instance_template/simple) for a usage example. | nic\_type | Valid values are "VIRTIO\_NET", "GVNIC" or set to null to accept API default behavior. | `string` | `null` | no | | on\_host\_maintenance | Instance availability Policy | `string` | `"MIGRATE"` | no | | preemptible | Allow the instance to be preempted | `bool` | `false` | no | -| project\_id | The GCP project ID | `string` | `null` | no | -| region | Region where the instance template should be created. | `string` | `null` | no | +| project\_id | The GCP project ID | `string` | n/a | yes | +| region | Region where the instance template should be created. | `string` | n/a | yes | | resource\_policies | A list of self\_links of resource policies to attach to the instance. Modifying this list will cause the instance to recreate. Currently a max of 1 resource policy is supported. | `list(string)` | `[]` | no | | service\_account | Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template#service_account. |
object({
email = string
scopes = optional(set(string), ["cloud-platform"])
})
| n/a | yes | | shielded\_instance\_config | Not used unless enable\_shielded\_vm is true. Shielded VM configuration for the instance. |
object({
enable_secure_boot = bool
enable_vtpm = bool
enable_integrity_monitoring = bool
})
|
{
"enable_integrity_monitoring": true,
"enable_secure_boot": true,
"enable_vtpm": true
}
| no | diff --git a/modules/instance_template/metadata.yaml b/modules/instance_template/metadata.yaml index 4064f403..ba72ce94 100644 --- a/modules/instance_template/metadata.yaml +++ b/modules/instance_template/metadata.yaml @@ -83,9 +83,11 @@ spec: - name: project_id description: The GCP project ID varType: string + required: true - name: region description: Region where the instance template should be created. varType: string + required: true - name: name_prefix description: Name prefix for the instance template varType: string diff --git a/modules/instance_template/variables.tf b/modules/instance_template/variables.tf index a7162fcb..f15468df 100644 --- a/modules/instance_template/variables.tf +++ b/modules/instance_template/variables.tf @@ -17,13 +17,11 @@ variable "project_id" { type = string description = "The GCP project ID" - default = null } variable "region" { type = string description = "Region where the instance template should be created." - default = null } variable "name_prefix" { diff --git a/modules/preemptible_and_regular_instance_templates/README.md b/modules/preemptible_and_regular_instance_templates/README.md index fce29084..344e25cb 100644 --- a/modules/preemptible_and_regular_instance_templates/README.md +++ b/modules/preemptible_and_regular_instance_templates/README.md @@ -24,7 +24,8 @@ See the [simple](../../examples/preemptible_and_regular_instance_templates/simpl | metadata | Metadata, provided as a map | `map(string)` | `{}` | no | | name\_prefix | Name prefix for the instance template | `string` | `"default-it"` | no | | 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 | -| project\_id | The GCP project ID | `string` | `null` | no | +| project\_id | The GCP project ID | `string` | n/a | yes | +| region | Region where the instance template should be created. | `string` | n/a | yes | | service\_account | Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template#service_account. |
object({
email = string
scopes = set(string)
})
| n/a | yes | | source\_image | Source disk image. If neither source\_image nor source\_image\_family is specified, defaults to the latest public Rocky Linux 9 optimized for GCP image. | `string` | `""` | no | | source\_image\_family | Source image family. If neither source\_image nor source\_image\_family is specified, defaults to the latest public Rocky Linux 9 optimized for GCP image. | `string` | `""` | no | diff --git a/modules/preemptible_and_regular_instance_templates/main.tf b/modules/preemptible_and_regular_instance_templates/main.tf index 523ab69b..da2a91bd 100644 --- a/modules/preemptible_and_regular_instance_templates/main.tf +++ b/modules/preemptible_and_regular_instance_templates/main.tf @@ -22,6 +22,7 @@ module "preemptible" { source = "../../modules/instance_template" name_prefix = "${var.name_prefix}-preemptible" project_id = var.project_id + region = var.region machine_type = var.machine_type labels = var.labels metadata = var.metadata @@ -48,6 +49,7 @@ module "regular" { source = "../../modules/instance_template" name_prefix = "${var.name_prefix}-regular" project_id = var.project_id + region = var.region machine_type = var.machine_type labels = var.labels metadata = var.metadata diff --git a/modules/preemptible_and_regular_instance_templates/metadata.yaml b/modules/preemptible_and_regular_instance_templates/metadata.yaml index bee9b70b..9cd8a37c 100644 --- a/modules/preemptible_and_regular_instance_templates/metadata.yaml +++ b/modules/preemptible_and_regular_instance_templates/metadata.yaml @@ -83,6 +83,11 @@ spec: - name: project_id description: The GCP project ID varType: string + required: true + - name: region + description: Region where the instance template should be created. + varType: string + required: true - name: name_prefix description: Name prefix for the instance template varType: string diff --git a/modules/preemptible_and_regular_instance_templates/variables.tf b/modules/preemptible_and_regular_instance_templates/variables.tf index a6973954..a6bb685d 100644 --- a/modules/preemptible_and_regular_instance_templates/variables.tf +++ b/modules/preemptible_and_regular_instance_templates/variables.tf @@ -17,7 +17,11 @@ variable "project_id" { type = string description = "The GCP project ID" - default = null +} + +variable "region" { + type = string + description = "Region where the instance template should be created." } variable "name_prefix" {