Skip to content

Commit

Permalink
fix: Grant role browser to the terraform service account for running …
Browse files Browse the repository at this point in the history
…gcloud beta terraform vet (#818)

* grant role browser to the terraform service account for running glcoud beta terraform vet

* fix linting error

* add role browser in test validation for step 0-bootstrap

* add common_roles in SA creation
  • Loading branch information
daniel-cit authored Sep 23, 2022
1 parent 383eb06 commit e80a504
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
20 changes: 13 additions & 7 deletions 0-bootstrap/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,30 @@ locals {
"proj" = "Foundation Projects SA. Managed by Terraform.",
}

common_roles = [
"roles/browser", // Required for gcloud beta terraform vet to be able to read the ancestry of folders
]

granular_sa_org_level_roles = {
"org" = [
"org" = distinct(concat([
"roles/orgpolicy.policyAdmin",
"roles/logging.configWriter",
"roles/resourcemanager.organizationAdmin",
"roles/securitycenter.notificationConfigEditor",
"roles/resourcemanager.organizationViewer",
"roles/accesscontextmanager.policyAdmin",
"roles/essentialcontacts.admin",
],
"net" = [
], local.common_roles)),
"env" = distinct(concat([
], local.common_roles)),
"net" = distinct(concat([
"roles/accesscontextmanager.policyAdmin",
"roles/compute.xpnAdmin",
],
"proj" = [
], local.common_roles)),
"proj" = distinct(concat([
"roles/accesscontextmanager.policyAdmin",
"roles/serviceusage.serviceUsageConsumer"
],
"roles/serviceusage.serviceUsageConsumer",
], local.common_roles)),
}

granular_sa_parent_level_roles = {
Expand Down
6 changes: 6 additions & 0 deletions test/integration/bootstrap/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,22 @@ func TestBootstrap(t *testing.T) {
orgRoles: []string{
"roles/accesscontextmanager.policyAdmin",
"roles/serviceusage.serviceUsageConsumer",
"roles/browser",
},
},
{
output: "networks_step_terraform_service_account_email",
orgRoles: []string{
"roles/accesscontextmanager.policyAdmin",
"roles/compute.xpnAdmin",
"roles/browser",
},
},
{
output: "environment_step_terraform_service_account_email",
orgRoles: []string{
"roles/browser",
},
},
{
output: "organization_step_terraform_service_account_email",
Expand All @@ -224,6 +229,7 @@ func TestBootstrap(t *testing.T) {
"roles/securitycenter.notificationConfigEditor",
"roles/resourcemanager.organizationViewer",
"roles/accesscontextmanager.policyAdmin",
"roles/browser",
},
},
} {
Expand Down

0 comments on commit e80a504

Please sign in to comment.