Skip to content

Commit e322413

Browse files
authored
feat!: add project_id as explicit input to compute_instance module (#554)
Co-authored-by: UMM KULSUM <kulsumeumm@google.com>
1 parent e668ae9 commit e322413

File tree

9 files changed

+19
-3
lines changed

9 files changed

+19
-3
lines changed

examples/compute_instance/disk_snapshot/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ module "compute_instance" {
6161
source = "terraform-google-modules/vm/google//modules/compute_instance"
6262
version = "~> 13.0"
6363

64+
project_id = var.project_id
6465
region = var.region
6566
subnetwork = var.subnetwork
6667
num_instances = 1

examples/compute_instance/simple/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module "compute_instance" {
2929
source = "terraform-google-modules/vm/google//modules/compute_instance"
3030
version = "~> 13.0"
3131

32+
project_id = var.project_id
3233
region = var.region
3334
zone = var.zone
3435
subnetwork = var.subnetwork

examples/confidential_computing/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ module "compute_instance" {
9191
source = "terraform-google-modules/vm/google//modules/compute_instance"
9292
version = "~> 13.0"
9393

94+
project_id = var.project_id
9495
region = var.region
9596
subnetwork = var.subnetwork
9697
hostname = "confidential-encrypted-instance"

examples/confidential_computing_intel/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ module "compute_instance" {
9191
source = "terraform-google-modules/vm/google//modules/compute_instance"
9292
version = "~> 13.0"
9393

94+
project_id = var.project_id
9495
region = var.region
9596
subnetwork = var.subnetwork
9697
hostname = "confidential-intel-encrypted"

modules/compute_instance/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ See the [simple](https://github.com/terraform-google-modules/terraform-google-vm
2626
| labels | (Optional) Labels to override those from the template, provided as a map | `map(string)` | `null` | no |
2727
| network | Network to deploy to. Only one of network or subnetwork should be specified. | `string` | `""` | no |
2828
| num\_instances | Number of instances to create. This value is ignored if static\_ips is provided. | `number` | `"1"` | no |
29+
| project\_id | The ID of the project in which the compute instance will be created. | `string` | n/a | yes |
2930
| region | Region where the instances should be created. | `string` | `null` | no |
3031
| resource\_manager\_tags | (Optional) A tag is a key-value pair that can be attached to a Google Cloud resource. You can use tags to conditionally allow or deny policies based on whether a resource has a specific tag. This value is not returned by the API. In Terraform, this value cannot be updated and changing it will recreate the resource. | `map(string)` | `null` | no |
3132
| resource\_policies | (Optional) A list of short names or 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 |

modules/compute_instance/main.tf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ locals {
2222
# at the end of the list to work around "list does not have any elements so cannot
2323
# determine type" error when var.static_ips is empty
2424
static_ips = concat(var.static_ips, ["NOT_AN_IP"])
25-
project_id = length(regexall("/projects/([^/]*)", var.instance_template)) > 0 ? flatten(regexall("/projects/([^/]*)", var.instance_template))[0] : null
2625

2726
# When no network or subnetwork has been defined, we want to use the settings from
2827
# the template instead.
@@ -34,7 +33,7 @@ locals {
3433
###############
3534

3635
data "google_compute_zones" "available" {
37-
project = local.project_id
36+
project = var.project_id
3837
region = var.region
3938
}
4039

@@ -46,7 +45,7 @@ resource "google_compute_instance_from_template" "compute_instance" {
4645
provider = google
4746
count = local.num_instances
4847
name = var.add_hostname_suffix ? format("%s%s%s", local.hostname, var.hostname_suffix_separator, format("%03d", count.index + 1)) : local.hostname
49-
project = local.project_id
48+
project = var.project_id
5049
zone = var.zone == null ? data.google_compute_zones.available.names[count.index % length(data.google_compute_zones.available.names)] : var.zone
5150
deletion_protection = var.deletion_protection
5251
resource_policies = var.resource_policies

modules/compute_instance/metadata.display.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ spec:
6363
name: num_instances
6464
title: Num Instances
6565
level: 1
66+
project_id:
67+
name: project_id
68+
title: Project Id
6669
region:
6770
name: region
6871
title: Region

modules/compute_instance/metadata.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ spec:
8282
location: examples/compute_instance/tags
8383
interfaces:
8484
variables:
85+
- name: project_id
86+
description: The ID of the project in which the compute instance will be created.
87+
varType: string
88+
required: true
8589
- name: network
8690
description: Network to deploy to. Only one of network or subnetwork should be specified.
8791
varType: string

modules/compute_instance/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17+
variable "project_id" {
18+
description = "The ID of the project in which the compute instance will be created."
19+
type = string
20+
}
21+
1722
variable "network" {
1823
description = "Network to deploy to. Only one of network or subnetwork should be specified."
1924
type = string

0 commit comments

Comments
 (0)