Skip to content

Commit

Permalink
fix: empty project_id in google_project data source
Browse files Browse the repository at this point in the history
A validation change hashicorp/terraform-provider-google#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 <afiune@lacework.net>
  • Loading branch information
afiune committed Nov 14, 2022
1 parent 6456f16 commit f1a584d
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions 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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit f1a584d

Please sign in to comment.