Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for tenant factory CI/CD #2297

Merged
merged 3 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions fast/stages/0-bootstrap/README.md

Large diffs are not rendered by default.

22 changes: 18 additions & 4 deletions fast/stages/0-bootstrap/automation.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
# tfdoc:file:description Automation project and resources.

locals {
cicd_resman_sa = try(module.automation-tf-cicd-sa["resman"].iam_email, "")
cicd_resman_r_sa = try(module.automation-tf-cicd-r-sa["resman"].iam_email, "")
cicd_resman_sa = try(module.automation-tf-cicd-sa["resman"].iam_email, "")
cicd_resman_r_sa = try(module.automation-tf-cicd-r-sa["resman"].iam_email, "")
cicd_tenants_sa = try(module.automation-tf-cicd-sa["tenants"].iam_email, "")
cicd_tenants_r_sa = try(module.automation-tf-cicd-r-sa["tenants"].iam_email, "")
}

module "automation-project" {
Expand Down Expand Up @@ -269,12 +271,18 @@ module "automation-tf-resman-sa" {
prefix = local.prefix
# allow SA used by CI/CD workflow to impersonate this SA
# we use additive IAM to allow tenant CI/CD SAs to impersonate it
iam_bindings_additive = (
iam_bindings_additive = merge(
local.cicd_resman_sa == "" ? {} : {
cicd_token_creator = {
member = local.cicd_resman_sa
role = "roles/iam.serviceAccountTokenCreator"
}
},
local.cicd_tenants_sa == "" ? {} : {
cicd_token_creator = {
member = local.cicd_tenants_sa
role = "roles/iam.serviceAccountTokenCreator"
}
}
)
iam_storage_roles = {
Expand All @@ -290,12 +298,18 @@ module "automation-tf-resman-r-sa" {
prefix = local.prefix
# allow SA used by CI/CD workflow to impersonate this SA
# we use additive IAM to allow tenant CI/CD SAs to impersonate it
iam_bindings_additive = (
iam_bindings_additive = merge(
local.cicd_resman_r_sa == "" ? {} : {
cicd_token_creator = {
member = local.cicd_resman_r_sa
role = "roles/iam.serviceAccountTokenCreator"
}
},
local.cicd_tenants_r_sa == "" ? {} : {
cicd_token_creator = {
member = local.cicd_tenants_r_sa
role = "roles/iam.serviceAccountTokenCreator"
}
}
)
# we grant organization roles here as IAM bindings have precedence over
Expand Down
6 changes: 6 additions & 0 deletions fast/stages/0-bootstrap/cicd.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,19 @@ locals {
bootstrap_r = "0-bootstrap-r-providers.tf"
resman = "1-resman-providers.tf"
resman_r = "1-resman-r-providers.tf"
tenants = "1-tenant-factory-providers.tf"
tenants_r = "1-tenant-factory-r-providers.tf"
}
cicd_workflow_var_files = {
bootstrap = []
resman = [
"0-bootstrap.auto.tfvars.json",
"0-globals.auto.tfvars.json"
]
tenants = [
"0-bootstrap.auto.tfvars.json",
"0-globals.auto.tfvars.json"
]
}
}

Expand Down
2 changes: 1 addition & 1 deletion fast/stages/0-bootstrap/organization-iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ locals {
(module.automation-tf-bootstrap-sa.iam_email) = {
authoritative = [
"roles/essentialcontacts.admin",
"roles/iam.workforcePoolAdmin",
"roles/logging.admin",
"roles/resourcemanager.organizationAdmin",
"roles/resourcemanager.projectCreator",
Expand All @@ -108,7 +109,6 @@ locals {
additive = concat(
[
"roles/iam.organizationRoleAdmin",
"roles/iam.workforcePoolAdmin",
"roles/orgpolicy.policyAdmin"
],
local.billing_mode != "org" ? [] : [
Expand Down
14 changes: 5 additions & 9 deletions fast/stages/0-bootstrap/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,11 @@ locals {
name = "tenant-factory"
sa = module.automation-tf-resman-sa.email
})
"0-bootstrap-tenant" = templatefile(local._tpl_providers, {
backend_extra = join("\n", [
"# remove the newline between quotes and set the tenant name as prefix",
"prefix = \"",
"\""
])
bucket = module.automation-tf-resman-gcs.name
name = "bootstrap-tenant"
sa = module.automation-tf-resman-sa.email
"1-tenant-factory-r" = templatefile(local._tpl_providers, {
backend_extra = "prefix = \"tenant-factory\""
bucket = module.automation-tf-resman-gcs.name
name = "tenant-factory"
sa = module.automation-tf-resman-r-sa.email
})
}
tfvars = {
Expand Down
6 changes: 6 additions & 0 deletions fast/stages/0-bootstrap/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ variable "cicd_repositories" {
branch = optional(string)
identity_provider = optional(string)
}))
tenants = optional(object({
name = string
type = string
branch = optional(string)
identity_provider = optional(string)
}))
})
default = null
validation {
Expand Down
10 changes: 3 additions & 7 deletions tests/fast/stages/s0_bootstrap/checklist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ values:
condition: [ ]
members:
- group:[email protected]
- serviceAccount:fast-prod-bootstrap-0@fast-prod-iac-core-0.iam.gserviceaccount.com
org_id: '123456789012'
role: roles/iam.workforcePoolAdmin
module.organization.google_organization_iam_binding.authoritative["roles/logging.admin"]:
Expand Down Expand Up @@ -301,11 +302,6 @@ values:
member: serviceAccount:fast-prod-bootstrap-0r@fast-prod-iac-core-0.iam.gserviceaccount.com
org_id: '123456789012'
role: roles/iam.organizationRoleViewer
? module.organization.google_organization_iam_member.bindings["roles/iam.workforcePoolAdmin-serviceAccount:fast-prod-bootstrap-0@fast-prod-iac-core-0.iam.gserviceaccount.com"]
: condition: [ ]
member: serviceAccount:fast-prod-bootstrap-0@fast-prod-iac-core-0.iam.gserviceaccount.com
org_id: '123456789012'
role: roles/iam.workforcePoolAdmin
? module.organization.google_organization_iam_member.bindings["roles/iam.workforcePoolViewer-serviceAccount:fast-prod-bootstrap-0r@fast-prod-iac-core-0.iam.gserviceaccount.com"]
: condition: [ ]
member: serviceAccount:fast-prod-bootstrap-0r@fast-prod-iac-core-0.iam.gserviceaccount.com
Expand Down Expand Up @@ -382,7 +378,7 @@ counts:
google_org_policy_policy: 22
google_organization_iam_binding: 28
google_organization_iam_custom_role: 7
google_organization_iam_member: 38
google_organization_iam_member: 37
google_project: 3
google_project_iam_audit_config: 1
google_project_iam_binding: 19
Expand All @@ -399,4 +395,4 @@ counts:
google_tags_tag_key: 1
google_tags_tag_value: 1
modules: 18
resources: 207
resources: 206
4 changes: 2 additions & 2 deletions tests/fast/stages/s0_bootstrap/simple.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ counts:
google_org_policy_policy: 22
google_organization_iam_binding: 28
google_organization_iam_custom_role: 7
google_organization_iam_member: 25
google_organization_iam_member: 24
google_project: 3
google_project_iam_audit_config: 1
google_project_iam_binding: 19
Expand All @@ -63,7 +63,7 @@ counts:
google_tags_tag_value: 1
local_file: 8
modules: 17
resources: 199
resources: 198

outputs:
custom_roles:
Expand Down
Loading