Skip to content

Commit

Permalink
fix: empty project_id in google_project data source (#20)
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_gar.data.google_project.selected,
│   on .terraform/modules/gcp_project_gar/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 16, 2022
1 parent 0c1aee9 commit 387e1fe
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,6 +1,6 @@
locals {
resource_level = "PROJECT"
project_id = data.google_project.selected.project_id
project_id = length(var.project_id) > 0 ? var.project_id : data.google_project.selected.project_id
service_account_name = var.use_existing_service_account ? (
var.service_account_name
) : (
Expand All @@ -18,9 +18,7 @@ resource "random_id" "uniq" {
byte_length = 4
}

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

module "lacework_gar_svc_account" {
source = "lacework/service-account/gcp"
Expand Down
2 changes: 1 addition & 1 deletion versions.tf
Expand Up @@ -2,7 +2,7 @@ terraform {
required_version = ">= 0.14"

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

0 comments on commit 387e1fe

Please sign in to comment.