-
Notifications
You must be signed in to change notification settings - Fork 11
Closed
Description
Hi Team, I'm 90% sure that I found a logic bug in the cloud-bench Terraform module which fails when using the organization-org_compliance example.
TL;DR The workaround proposed in the FAQ doesn't seem to work
Example instance of the module
locals {
projects = ["ABC", "DEF"]
}
# Based on: https://registry.terraform.io/modules/sysdiglabs/secure-for-cloud/google/latest/examples/organization-org_compliance
provider "sysdig" {
sysdig_secure_url = "https://sample.sysdig.com"
}
provider "google" {
alias = "multiproject"
project = "sysdig-pov"
region = "us-central1"
}
provider "google-beta" {
alias = "multiproject"
project = "sysdig-pov"
region = "us-central1"
}
module "secure-for-cloud_example_organization-org_compliance" {
providers = {
google.multiproject = google.multiproject
google-beta.multiproject = google-beta.multiproject
}
source = "sysdiglabs/secure-for-cloud/google//examples/organization-org_compliance"
version = "0.9.9"
organization_domain = "sample.com"
deploy_benchmark = true
benchmark_project_ids = local.projects
}Terraform Plan
│ Error: Invalid index
│
│ on .terraform/modules/secure-for-cloud_example_organization-org_compliance/modules/services/cloud-bench-workload-identity/trust_relationship/main.tf line 27, in resource "sysdig_secure_cloud_account" "cloud_account":
│ 27: account_id = var.project_id_number_map[each.key]
│ ├────────────────
│ │ each.key is "ABC"
│ │ var.project_id_number_map is map of string with 1 element
│
│ The given key does not identify an element in this collection value.
Faulty logic
data "google_projects" "all_projects" {
filter = "parent.id:${data.google_organization.org.org_id} parent.type:organization lifecycleState:ACTIVE"
}
locals {
# If specific projects are specified, use that list. Otherwise, use all active projects in the org
project_ids = length(var.project_ids) == 0 ? [for p in data.google_projects.all_projects.projects : p.project_id] : var.project_ids
# Fetch both the project ID and project number (Needed by Workload Identity Federation)
project_id_to_number_map = { for p in data.google_projects.all_projects.projects : p.project_id => p.number }
}- The list
data.google_projects.all_projects.projectsconsist only of Projects whose direct parent is the Org itself (which in general is an antipattern) - If
var.project_ids = benchmark_project_idsisn't empty thenproject_ids = var.project_ids(which I assume was meant as the workaround) - The issue stems from the fact that
project_id_to_number_mapoperates on thedata.google_projects.all_projects.projectslist regardless wetherbenchmark_project_idswas provided or not - This in consequence makes the project_number lookup fail since
project_ids != [for p in data.google_projects.all_projects.projects : p.project_id]
resource "sysdig_secure_cloud_account" "cloud_account" {
for_each = toset(local.project_ids)
account_id = var.project_id_number_map[each.key]
alias = each.key
cloud_provider = "gcp"
role_enabled = "true"
role_name = var.role_name
workload_identity_account_id = var.project_id_number_map[var.project_id]
workload_identity_account_alias = var.project_id
}
Metadata
Metadata
Assignees
Labels
No labels