From 5d621234b3fdf18a5fd638a32403a3f470b945a3 Mon Sep 17 00:00:00 2001 From: Abhishek Tiwari Date: Wed, 11 Dec 2024 11:35:54 +0000 Subject: [PATCH] fix: make project_id as required input and update apphub_workload_uri output --- autogen/outputs.tf.tmpl | 2 +- autogen/variables.tf.tmpl | 1 - docs/upgrading_to_mig_v13.0.md | 23 +++++++++++++++++++++++ modules/mig/README.md | 2 +- modules/mig/metadata.yaml | 1 + modules/mig/outputs.tf | 2 +- modules/mig/variables.tf | 1 - 7 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 docs/upgrading_to_mig_v13.0.md diff --git a/autogen/outputs.tf.tmpl b/autogen/outputs.tf.tmpl index 5abb642e..f43d0a9a 100644 --- a/autogen/outputs.tf.tmpl +++ b/autogen/outputs.tf.tmpl @@ -40,7 +40,7 @@ output "health_check_self_links" { output "apphub_workload_uri" { value = { workload_uri = "//compute.googleapis.com/projects${element(split("/projects", google_compute_region_instance_group_manager.mig.instance_group), 1)}" - workload_id = substr(join("-", [tostring(google_compute_region_instance_group_manager.mig.name), md5(tostring(google_compute_region_instance_group_manager.mig.self_link))]), 0, 63) + workload_id = substr(join("-", [tostring(google_compute_region_instance_group_manager.mig.name), md5(join("-", [var.region, var.project_id]))]), 0, 63) } description = "Workload URI in CAIS style to be used by Apphub." } diff --git a/autogen/variables.tf.tmpl b/autogen/variables.tf.tmpl index 76e395c1..0fb09e83 100644 --- a/autogen/variables.tf.tmpl +++ b/autogen/variables.tf.tmpl @@ -19,7 +19,6 @@ variable "project_id" { type = string description = "The Google Cloud project ID" - default = null } variable "region" { diff --git a/docs/upgrading_to_mig_v13.0.md b/docs/upgrading_to_mig_v13.0.md new file mode 100644 index 00000000..7a245cb0 --- /dev/null +++ b/docs/upgrading_to_mig_v13.0.md @@ -0,0 +1,23 @@ +# Upgrading to MIG v13.0 + +The v13.0 release of MIG is a backwards incompatible release. Now the `project_id` is required input variable. Earlier it was set to `null` by default. But the `terraform plan` would fail because `google_compute_zones` data block requires a non-null `project_id`. +Users might be bypassing this by setting project at provider level and not providing `project_id` for mig module. + +## Migration Instructions + +### Explicitly provide project_id as input to the MIG module + +Users would need to provide project_id explicitly while using v13.0 of MIG. + +```diff +module "mig" { + source = "terraform-google-modules/vm/google//modules/mig" + version = "~> 12.0" + ++ project_id = var.project_id + region = var.region + target_size = var.target_size + hostname = "mig-simple" + instance_template = module.instance_template.self_link +} +``` diff --git a/modules/mig/README.md b/modules/mig/README.md index 62be74c7..9d54b711 100644 --- a/modules/mig/README.md +++ b/modules/mig/README.md @@ -38,7 +38,7 @@ The current version is 2.X. The following guides are available to assist with up | mig\_timeouts | Times for creation, deleting and updating the MIG resources. Can be helpful when using wait\_for\_instances to allow a longer VM startup time. |
object({
create = string
update = string
delete = string
})
|
{
"create": "5m",
"delete": "15m",
"update": "5m"
}
| no | | min\_replicas | The minimum number of replicas that the autoscaler can scale down to. This cannot be less than 0. | `number` | `2` | no | | named\_ports | Named name and named port. https://cloud.google.com/load-balancing/docs/backend-service#named_ports |
list(object({
name = string
port = number
}))
| `[]` | no | -| project\_id | The Google Cloud project ID | `string` | `null` | no | +| project\_id | The Google Cloud project ID | `string` | n/a | yes | | region | The Google Cloud region where the managed instance group resides. | `string` | n/a | yes | | scaling\_schedules | Autoscaling, scaling schedule block. https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_autoscaler#scaling_schedules |
list(object({
disabled = bool
duration_sec = number
min_required_replicas = number
name = string
schedule = string
time_zone = string
}))
| `[]` | no | | stateful\_disks | Disks created on the instances that will be preserved on instance delete. https://cloud.google.com/compute/docs/instance-groups/configuring-stateful-disks-in-migs |
list(object({
device_name = string
delete_rule = string
}))
| `[]` | no | diff --git a/modules/mig/metadata.yaml b/modules/mig/metadata.yaml index 72505e25..7e666612 100644 --- a/modules/mig/metadata.yaml +++ b/modules/mig/metadata.yaml @@ -83,6 +83,7 @@ spec: - name: project_id description: The Google Cloud project ID varType: string + required: true - name: region description: The Google Cloud region where the managed instance group resides. varType: string diff --git a/modules/mig/outputs.tf b/modules/mig/outputs.tf index d5aecf35..28570b66 100644 --- a/modules/mig/outputs.tf +++ b/modules/mig/outputs.tf @@ -39,7 +39,7 @@ output "health_check_self_links" { output "apphub_workload_uri" { value = { workload_uri = "//compute.googleapis.com/projects${element(split("/projects", google_compute_region_instance_group_manager.mig.instance_group), 1)}" - workload_id = substr(join("-", [tostring(google_compute_region_instance_group_manager.mig.name), md5(tostring(google_compute_region_instance_group_manager.mig.self_link))]), 0, 63) + workload_id = substr(join("-", [tostring(google_compute_region_instance_group_manager.mig.name), md5(join("-", [var.region, var.project_id]))]), 0, 63) } description = "Workload URI in CAIS style to be used by Apphub." } diff --git a/modules/mig/variables.tf b/modules/mig/variables.tf index 2c093049..3ce60742 100644 --- a/modules/mig/variables.tf +++ b/modules/mig/variables.tf @@ -19,7 +19,6 @@ variable "project_id" { type = string description = "The Google Cloud project ID" - default = null } variable "region" {