Skip to content

Commit

Permalink
fix!: make project_id and region as required input for instance_templ…
Browse files Browse the repository at this point in the history
…ate (#455)
  • Loading branch information
q2w authored Dec 17, 2024
1 parent 0c9d75b commit 2b8b2b3
Show file tree
Hide file tree
Showing 22 changed files with 87 additions and 11 deletions.
59 changes: 54 additions & 5 deletions docs/upgrading_to_mig_v13.0.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
# Upgrading to MIG v13.0
# Upgrading to 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`.
The v13.0 release of MIG and instance_template is a backwards incompatible release.

## `modules/mig` and `modules/mig_with_percent`

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.

## `modules/instance_template` and `modules/preemptible_and_regular_instance_templates`

* Now the `project_id` and `region` is required input variable. Earlier it was set to `null` by default.


## Migration Instructions

### Explicitly provide project_id as input to the MIG module
### Explicitly provide project_id as input to the MIG modules

Users would need to provide project_id explicitly while using v13.0 of mig/mig_with_percent.

Expand All @@ -14,7 +23,7 @@ For mig,
```diff
module "mig" {
source = "terraform-google-modules/vm/google//modules/mig"
version = "~> 12.0"
version = "~> 13.0"

+ project_id = var.project_id
region = var.region
Expand All @@ -29,7 +38,7 @@ For mig_with_percent,
```diff
module "mig_with_percent" {
source = "terraform-google-modules/vm/google//modules/mig_with_percent"
version = "~> 12.0"
version = "~> 13.0"

+ project_id = var.project_id
region = var.region
Expand All @@ -40,3 +49,43 @@ module "mig_with_percent" {
next_version_percent = 50
}
```

### Explicitly provide project_id/region as input to the instance_template modules

For instance_template,

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

+ project_id = var.project_id
+ region = var.region
subnetwork = var.subnetwork
stack_type = "IPV4_ONLY"
service_account = var.service_account
name_prefix = "simple"
tags = var.tags
labels = var.labels
access_config = [local.access_config]
enable_nested_virtualization = var.enable_nested_virtualization
threads_per_core = var.threads_per_core
}
```

For preemptible_and_regular_instance_templates

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

subnetwork = var.subnetwork
+ project_id = var.project_id
+ region = var.region
service_account = var.service_account
name_prefix = "pvm-and-regular-simple"
tags = var.tags
labels = var.labels
}
```
1 change: 1 addition & 0 deletions examples/instance_template/additional_disks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions examples/instance_template/alias_ip_range/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions examples/instance_template/encrypted_disks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,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"
Expand Down
1 change: 1 addition & 0 deletions examples/instance_template/simple/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/mig/autoscaler/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions examples/mig/full/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module "instance_template" {

name_prefix = "${var.hostname}-instance-template"
project_id = var.project_id
region = var.region
machine_type = var.machine_type
tags = var.tags
labels = var.labels
Expand Down
1 change: 1 addition & 0 deletions examples/mig/healthcheck/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions examples/mig/simple/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions examples/mig_with_percent/simple/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ module "preemptible_and_regular_instance_templates" {
source = "terraform-google-modules/vm/google//modules/preemptible_and_regular_instance_templates"
version = "~> 12.0"

project_id = var.project_id
region = var.region
subnetwork = var.subnetwork
service_account = var.service_account
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module "preemptible_and_regular_instance_templates" {

subnetwork = var.subnetwork
project_id = var.project_id
region = var.region
service_account = var.service_account
name_prefix = "pvm-and-regular-simple"
tags = var.tags
Expand Down
1 change: 1 addition & 0 deletions examples/umig/full/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module "instance_template" {
name_prefix = "${var.hostname}-instance-template"
machine_type = var.machine_type
project_id = var.project_id
region = var.region
tags = var.tags
labels = var.labels
startup_script = var.startup_script
Expand Down
1 change: 1 addition & 0 deletions examples/umig/named_ports/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions examples/umig/simple/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/umig/static_ips/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions modules/instance_template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. | <pre>object({<br> email = string<br> scopes = optional(set(string), ["cloud-platform"])<br> })</pre> | n/a | yes |
| shielded\_instance\_config | Not used unless enable\_shielded\_vm is true. Shielded VM configuration for the instance. | <pre>object({<br> enable_secure_boot = bool<br> enable_vtpm = bool<br> enable_integrity_monitoring = bool<br> })</pre> | <pre>{<br> "enable_integrity_monitoring": true,<br> "enable_secure_boot": true,<br> "enable_vtpm": true<br>}</pre> | no |
Expand Down
2 changes: 2 additions & 0 deletions modules/instance_template/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions modules/instance_template/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
3 changes: 2 additions & 1 deletion modules/preemptible_and_regular_instance_templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. | <pre>object({<br> email = string<br> scopes = set(string)<br> })</pre> | 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 |
Expand Down
2 changes: 2 additions & 0 deletions modules/preemptible_and_regular_instance_templates/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down

0 comments on commit 2b8b2b3

Please sign in to comment.