Closed jdomeracki closed 1 year ago
Hi @jdomeracki thank you for raising this, and the thorough explanation!
This issue has been addressed in https://github.com/sysdiglabs/terraform-google-secure-for-cloud/pull/145, and released in version v0.9.10
Please don't hesitate to re-open this issue if the latest version of the module does not work as expected.
Hi @nkraemer-sysdig, finally got around to testing the solution.
TL;DR It works ie. when a list of project IDs is provided the plan looks healthy 🎉
Having said that I do have a potential improvement to contribute. I timed the execution of the fetch-gcp-projects.sh script and it turned out to be painfully slow when run in an Org of our size:
> time ./fetch-gcp-projects.sh $ORG_ID
OMITTED
./fetch-gcp-projects.sh $ORG_ID 66.88s user 17.15s system 29% cpu 4:46.98 total
While it's pretty much a one time job and the logic looks fine there is an alternative Google API - Asset Inventory which makes the process of getting all Projects under given Org much easier. Listed below is an example gcloud query which achieves exactly that:
> time gcloud asset search-all-resources \
--scope="organizations/$ORG_ID" \
--asset-types="cloudresourcemanager.googleapis.com/Project" \
--format="value(additionalAttributes.projectId)"
OMITTED
gcloud asset search-all-resources --scope="organizations/$ORG_ID" 1.66s user 0.21s system 6% cpu 27.990 total
Not only is it much faster but also the complexity and readability of the script could be greatly improved.
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
Terraform Plan
Faulty logic
https://github.com/sysdiglabs/terraform-google-secure-for-cloud/blob/master/modules/services/cloud-bench-workload-identity/main.tf#L5-L15
data.google_projects.all_projects.projects
consist only of Projects whose direct parent is the Org itself (which in general is an antipattern)var.project_ids = benchmark_project_ids
isn't empty thenproject_ids = var.project_ids
(which I assume was meant as the workaround)project_id_to_number_map
operates on thedata.google_projects.all_projects.projects
list regardless wetherbenchmark_project_ids
was provided or notproject_ids != [for p in data.google_projects.all_projects.projects : p.project_id]
https://github.com/sysdiglabs/terraform-google-secure-for-cloud/blob/master/modules/services/cloud-bench-workload-identity/trust_relationship/main.tf#L25-L34