Skip to content

Commit

Permalink
fix: make project_id as required input and update apphub_workload_uri…
Browse files Browse the repository at this point in the history
… output
  • Loading branch information
q2w committed Dec 11, 2024
1 parent fa80759 commit ec68826
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 7 deletions.
2 changes: 1 addition & 1 deletion autogen/outputs.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
Expand Down
1 change: 0 additions & 1 deletion autogen/variables.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
variable "project_id" {
type = string
description = "The Google Cloud project ID"
default = null
}

variable "region" {
Expand Down
42 changes: 42 additions & 0 deletions docs/upgrading_to_mig_v13.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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/mig_with_percent.

For 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
}
```

For mig_with_percent,

```diff
module "mig_with_percent" {
source = "terraform-google-modules/vm/google//modules/mig_with_percent"
version = "~> 12.0"

+ project_id = var.project_id
region = var.region
target_size = 4
hostname = "mig-with-percent-simple"
instance_template_initial_version = module.preemptible_and_regular_instance_templates.regular_self_link
instance_template_next_version = module.preemptible_and_regular_instance_templates.preemptible_self_link
next_version_percent = 50
}
```
2 changes: 1 addition & 1 deletion modules/mig/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. | <pre>object({<br> create = string<br> update = string<br> delete = string<br> })</pre> | <pre>{<br> "create": "5m",<br> "delete": "15m",<br> "update": "5m"<br>}</pre> | 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 | <pre>list(object({<br> name = string<br> port = number<br> }))</pre> | `[]` | 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 | <pre>list(object({<br> disabled = bool<br> duration_sec = number<br> min_required_replicas = number<br> name = string<br> schedule = string<br> time_zone = string<br> }))</pre> | `[]` | 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 | <pre>list(object({<br> device_name = string<br> delete_rule = string<br> }))</pre> | `[]` | no |
Expand Down
1 change: 1 addition & 0 deletions modules/mig/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/mig/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
1 change: 0 additions & 1 deletion modules/mig/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
variable "project_id" {
type = string
description = "The Google Cloud project ID"
default = null
}

variable "region" {
Expand Down
2 changes: 1 addition & 1 deletion modules/mig_with_percent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ The current version is 2.X. The following guides are available to assist with up
| 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 | <pre>list(object({<br> name = string<br> port = number<br> }))</pre> | `[]` | no |
| next\_version\_percent | Percentage of instances defined in the second version | `number` | n/a | yes |
| 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 | <pre>list(object({<br> disabled = bool<br> duration_sec = number<br> min_required_replicas = number<br> name = string<br> schedule = string<br> time_zone = string<br> }))</pre> | `[]` | 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 | <pre>list(object({<br> device_name = string<br> delete_rule = string<br> }))</pre> | `[]` | no |
Expand Down
1 change: 1 addition & 0 deletions modules/mig_with_percent/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion modules/mig_with_percent/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
variable "project_id" {
type = string
description = "The Google Cloud project ID"
default = null
}

variable "region" {
Expand Down

0 comments on commit ec68826

Please sign in to comment.