From 976ac9dc1af46197c7eb2100ec12adf6abe3aa4b Mon Sep 17 00:00:00 2001 From: Salim Afiune Date: Tue, 15 Nov 2022 08:00:36 -0800 Subject: [PATCH] fix: empty project_id in google_project data source (#75) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A validation change https://github.com/hashicorp/terraform-provider-google/pull/12846 was introduced in version `4.42.0` of the google provider. This validation makes all our GCP modules to fail with: ``` │ Error: "" project_id must be 6 to 30 with lowercase letters, digits, hyphens and start with a letter. Trailing hyphens are prohibited. │ │ with module.gcp_project_config.data.google_project.selected, │ on .terraform/modules/gcp_project_config/main.tf line 96, in data "google_project" "selected": │ 96: project_id = var.project_id ``` To solve this issue we are avoiding using the `google_project` data source when we know the `project_id` that was provided by the user. If the user does not provide a `project_id`, then we use the data source to discover the project from the google provider. Signed-off-by: Salim Afiune Maya Signed-off-by: Salim Afiune Maya --- main.tf | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/main.tf b/main.tf index e48f0ad..96aceaa 100644 --- a/main.tf +++ b/main.tf @@ -1,7 +1,7 @@ locals { resource_level = var.org_integration ? "ORGANIZATION" : "PROJECT" resource_id = var.org_integration ? var.organization_id : module.lacework_cfg_svc_account.project_id - project_id = data.google_project.selected.project_id + project_id = length(var.project_id) > 0 ? var.project_id : data.google_project.selected.project_id exclude_folders = length(var.folders_to_exclude) != 0 explicit_folders = length(var.folders_to_include) != 0 @@ -92,9 +92,7 @@ resource "random_id" "uniq" { byte_length = 4 } -data "google_project" "selected" { - project_id = var.project_id -} +data "google_project" "selected" {} module "lacework_cfg_svc_account" { source = "lacework/service-account/gcp"