Skip to content

Commit

Permalink
fix: empty project_id in google_project data source (#77)
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_audit_log.data.google_project.selected,
│   on .terraform/modules/gcp_project_audit_log/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>

Signed-off-by: Salim Afiune Maya <afiune@lacework.net>
  • Loading branch information
afiune committed Nov 15, 2022
1 parent 91fae7a commit 92261b8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 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_at_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

bucket_name = length(var.existing_bucket_name) > 0 ? var.existing_bucket_name : (
length(google_storage_bucket.lacework_bucket) > 0 ? google_storage_bucket.lacework_bucket[0].name : var.existing_bucket_name
Expand Down Expand Up @@ -102,9 +102,7 @@ resource "random_id" "uniq" {
byte_length = 4
}

data "google_project" "selected" {
project_id = var.project_id
}
data "google_project" "selected" {}

data "google_folders" "my-org-folders" {
count = (var.org_integration && local.exclude_folders) ? 1 : 0
Expand Down
2 changes: 1 addition & 1 deletion versions.tf
Expand Up @@ -2,7 +2,7 @@ terraform {
required_version = ">= 0.15.1"

required_providers {
google = ">= 4.4.0, < 4.41.0"
google = ">= 4.4.0, < 5.0.0"
time = "~> 0.6"
lacework = {
source = "lacework/lacework"
Expand Down

0 comments on commit 92261b8

Please sign in to comment.