Skip to content

Commit 0c9d75b

Browse files
authored
fix!: make project_id as required input for modules/mig and update apphub_workload_uri… (#453)
1 parent fa80759 commit 0c9d75b

File tree

11 files changed

+49
-7
lines changed

11 files changed

+49
-7
lines changed

autogen/outputs.tf.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ output "health_check_self_links" {
4040
output "apphub_workload_uri" {
4141
value = {
4242
workload_uri = "//compute.googleapis.com/projects${element(split("/projects", google_compute_region_instance_group_manager.mig.instance_group), 1)}"
43-
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)
43+
workload_id = substr(join("-", [tostring(google_compute_region_instance_group_manager.mig.name), md5(join("-", [var.region, var.project_id]))]), 0, 63)
4444
}
4545
description = "Workload URI in CAIS style to be used by Apphub."
4646
}

autogen/variables.tf.tmpl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
variable "project_id" {
2020
type = string
2121
description = "The Google Cloud project ID"
22-
default = null
2322
}
2423

2524
variable "region" {

docs/upgrading_to_mig_v13.0.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Upgrading to MIG v13.0
2+
3+
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`.
4+
Users might be bypassing this by setting project at provider level and not providing `project_id` for mig module.
5+
6+
## Migration Instructions
7+
8+
### Explicitly provide project_id as input to the MIG module
9+
10+
Users would need to provide project_id explicitly while using v13.0 of mig/mig_with_percent.
11+
12+
For mig,
13+
14+
```diff
15+
module "mig" {
16+
source = "terraform-google-modules/vm/google//modules/mig"
17+
version = "~> 12.0"
18+
19+
+ project_id = var.project_id
20+
region = var.region
21+
target_size = var.target_size
22+
hostname = "mig-simple"
23+
instance_template = module.instance_template.self_link
24+
}
25+
```
26+
27+
For mig_with_percent,
28+
29+
```diff
30+
module "mig_with_percent" {
31+
source = "terraform-google-modules/vm/google//modules/mig_with_percent"
32+
version = "~> 12.0"
33+
34+
+ project_id = var.project_id
35+
region = var.region
36+
target_size = 4
37+
hostname = "mig-with-percent-simple"
38+
instance_template_initial_version = module.preemptible_and_regular_instance_templates.regular_self_link
39+
instance_template_next_version = module.preemptible_and_regular_instance_templates.preemptible_self_link
40+
next_version_percent = 50
41+
}
42+
```

examples/mig_with_percent/simple/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module "mig_with_percent" {
3838
source = "terraform-google-modules/vm/google//modules/mig_with_percent"
3939
version = "~> 12.0"
4040

41+
project_id = var.project_id
4142
region = var.region
4243
target_size = 4
4344
hostname = "mig-with-percent-simple"

modules/mig/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ The current version is 2.X. The following guides are available to assist with up
3838
| 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 |
3939
| min\_replicas | The minimum number of replicas that the autoscaler can scale down to. This cannot be less than 0. | `number` | `2` | no |
4040
| 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 |
41-
| project\_id | The Google Cloud project ID | `string` | `null` | no |
41+
| project\_id | The Google Cloud project ID | `string` | n/a | yes |
4242
| region | The Google Cloud region where the managed instance group resides. | `string` | n/a | yes |
4343
| 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 |
4444
| 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 |

modules/mig/metadata.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ spec:
8383
- name: project_id
8484
description: The Google Cloud project ID
8585
varType: string
86+
required: true
8687
- name: region
8788
description: The Google Cloud region where the managed instance group resides.
8889
varType: string

modules/mig/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ output "health_check_self_links" {
3939
output "apphub_workload_uri" {
4040
value = {
4141
workload_uri = "//compute.googleapis.com/projects${element(split("/projects", google_compute_region_instance_group_manager.mig.instance_group), 1)}"
42-
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)
42+
workload_id = substr(join("-", [tostring(google_compute_region_instance_group_manager.mig.name), md5(join("-", [var.region, var.project_id]))]), 0, 63)
4343
}
4444
description = "Workload URI in CAIS style to be used by Apphub."
4545
}

modules/mig/variables.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
variable "project_id" {
2020
type = string
2121
description = "The Google Cloud project ID"
22-
default = null
2322
}
2423

2524
variable "region" {

modules/mig_with_percent/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ The current version is 2.X. The following guides are available to assist with up
3939
| min\_replicas | The minimum number of replicas that the autoscaler can scale down to. This cannot be less than 0. | `number` | `2` | no |
4040
| 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 |
4141
| next\_version\_percent | Percentage of instances defined in the second version | `number` | n/a | yes |
42-
| project\_id | The Google Cloud project ID | `string` | `null` | no |
42+
| project\_id | The Google Cloud project ID | `string` | n/a | yes |
4343
| region | The Google Cloud region where the managed instance group resides. | `string` | n/a | yes |
4444
| 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 |
4545
| 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 |

modules/mig_with_percent/metadata.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ spec:
8383
- name: project_id
8484
description: The Google Cloud project ID
8585
varType: string
86+
required: true
8687
- name: region
8788
description: The Google Cloud region where the managed instance group resides.
8889
varType: string

0 commit comments

Comments
 (0)