Repository navigation
feat!: ssm integration - #227
Calvin-Cheng1 wants to merge 4 commits into
Conversation
108087f to
6ec56b6
Compare
6ec56b6 to
1a8d166
Compare
aghassemlouei
left a comment
There was a problem hiding this comment.
Thanks for putting together this draft to migrate CI/CD from Cloud Source Repositories to Secure Source Manager for #198. Because the branch is behind main and has a few structural and API issues, this review flags the main items to address before taking it out of draft, with click-to-apply suggestions on the inline threads.
-
Rebase and drop upstream module changes: This branch is 83 commits behind
mainand conflicts infast/stages-aw/0-bootstrap/automation.tf,modules/secure-source-manager-instance/main.tf, andmodules/secure-source-manager-instance/versions.tf. The module refresh commit synced CFF v58.0.0 with>= 6.21.0, < 7.0.0, whereasmainalready syncedmodules/secure-source-manager-instanceto CFF v60.0.0 in #311 with>= 8.10.0, < 9.0.0. Dropping the edits undermodules/secure-source-manager-instancekeeps the PR aligned withdocs/upstream-sync.mdand clears those module conflicts. -
Update CI/CD workflow templates and coordinate with #419:
fast/stages-aw/0-bootstrap/templates/workflow-ssm.yamlandfast/stages-aw/1-resman/templates/workflow-ssm.yamlwere renamed unchanged fromworkflow-sourcerepo.yaml. Both still pin_TF_VERSIONto1.7.6despiteversions.tfrequiring>= 1.12.2, invokegsutilinstead ofgcloud storage, and apply on push without a read-only plan flow. Consider aligning the template inputs with theservice_accountsandtf_providers_fileschanges in #419 and checkingfast/assets/templates/workflow-sourcerepo.yaml. -
Complete
sourcerepocleanup and PR metadata: Remaining Cloud Source Repositories references exist inmodules/source-repository/,modules/README.md,docs/tdd.md,fast/docs/0-cicd-plan-sa.md,fast/stages-aw/0-bootstrap/README.md,fast/stages-aw/0-bootstrap/data/org-policies/cloudbuild_policy.yaml, and thesource.developers.google.com.DNS entries in Stage 2terraform.tfvars.sample. In the PR description, remove the space in "Fixes # 198" so GitHub links #198, add a breaking-change upgrade note, updatefast/stages-aw/0-bootstrap/README.md, fill in "Testing Performed", and remove the unrelated "Scope - Blueprint" label and duplicate "FedRAMP Moderate" checkbox.
| "roles/securesourcemanager.instanceAccessor" = [ | ||
| module.automation-tf-resman-sa.iam_email, | ||
| module.automation-tf-resman-r-sa.iam_email | ||
| ] |
There was a problem hiding this comment.
Replacing roles/source.admin with roles/securesourcemanager.instanceAccessor on automation-tf-resman-sa has two consequences. First, every cicd-*.tf file in fast/stages-aw/1-resman still uses modules/source-repository, so removing roles/source.admin here breaks Stage 1 apply until those files are migrated. Second, once Stage 1 migrates to modules/secure-source-manager-instance, automation-tf-resman-sa needs repository-creation roles in addition to instance read access, specifically roles/securesourcemanager.instanceRepositoryCreator and roles/securesourcemanager.repoCreator on the automation project.
| "roles/securesourcemanager.instanceAccessor" = [ | |
| module.automation-tf-resman-sa.iam_email, | |
| module.automation-tf-resman-r-sa.iam_email | |
| ] | |
| "roles/securesourcemanager.instanceAccessor" = [ | |
| module.automation-tf-resman-sa.iam_email, | |
| module.automation-tf-resman-r-sa.iam_email | |
| ] | |
| "roles/securesourcemanager.instanceRepositoryCreator" = [ | |
| module.automation-tf-resman-sa.iam_email | |
| ] | |
| "roles/securesourcemanager.repoCreator" = [ | |
| module.automation-tf-resman-sa.iam_email | |
| ] |
| source = "../../../modules/secure-source-manager-instance" | ||
| project_id = module.automation-project.project_id | ||
| location = "us-east1" #us-central1, us-east1 | ||
| instance_id = "ssm-instance" | ||
|
|
||
| repositories = { | ||
| for k, v in local.cicd_repositories : v.name => { | ||
| description = "FAST Secure Source Manager repository for ${k} stage." | ||
| initial_config = { | ||
| default_branch = coalesce(v.branch, "main") | ||
| } | ||
| iam = { | ||
| "roles/securesourcemanager.repoAdmin" = [ | ||
| k == "bootstrap" | ||
| ? module.automation-tf-bootstrap-sa.iam_email | ||
| : module.automation-tf-resman-sa.iam_email | ||
| ] | ||
| "roles/securesourcemanager.repoReader" = concat( | ||
| [module.automation-tf-cicd-sa[k].iam_email], | ||
| k == "bootstrap" | ||
| ? [module.automation-tf-bootstrap-r-sa.iam_email] | ||
| : [module.automation-tf-resman-r-sa.iam_email] | ||
| ) | ||
| } | ||
| } if v.type == "ssm" | ||
| } | ||
| project_id = module.automation-project.project_id | ||
| name = each.value.name | ||
| iam = { | ||
| "roles/source.admin" = [ | ||
| each.key == "bootstrap" | ||
| ? module.automation-tf-bootstrap-sa.iam_email | ||
| : module.automation-tf-resman-sa.iam_email | ||
| ] | ||
| "roles/source.reader" = concat( | ||
| [module.automation-tf-cicd-sa[each.key].iam_email], | ||
| each.key == "bootstrap" | ||
| ? [module.automation-tf-bootstrap-r-sa.iam_email] | ||
| : [module.automation-tf-resman-r-sa.iam_email] | ||
| ) | ||
| } |
There was a problem hiding this comment.
module "automation-tf-cicd-repo" needs a conditional instance_create guard, configurable region and instance ID, and instance-level plus repository-level read access for both the apply and plan CI/CD service accounts. Because instance_create defaults to true, omitting it provisions an SSM instance on every Stage 0 deployment even when cicd_repositories is null or uses GitHub. Also note that var.regions.primary must be set to a supported SSM region when SSM is enabled, and DoD IL4 does not support SSM.
| source = "../../../modules/secure-source-manager-instance" | |
| project_id = module.automation-project.project_id | |
| location = "us-east1" #us-central1, us-east1 | |
| instance_id = "ssm-instance" | |
| repositories = { | |
| for k, v in local.cicd_repositories : v.name => { | |
| description = "FAST Secure Source Manager repository for ${k} stage." | |
| initial_config = { | |
| default_branch = coalesce(v.branch, "main") | |
| } | |
| iam = { | |
| "roles/securesourcemanager.repoAdmin" = [ | |
| k == "bootstrap" | |
| ? module.automation-tf-bootstrap-sa.iam_email | |
| : module.automation-tf-resman-sa.iam_email | |
| ] | |
| "roles/securesourcemanager.repoReader" = concat( | |
| [module.automation-tf-cicd-sa[k].iam_email], | |
| k == "bootstrap" | |
| ? [module.automation-tf-bootstrap-r-sa.iam_email] | |
| : [module.automation-tf-resman-r-sa.iam_email] | |
| ) | |
| } | |
| } if v.type == "ssm" | |
| } | |
| project_id = module.automation-project.project_id | |
| name = each.value.name | |
| iam = { | |
| "roles/source.admin" = [ | |
| each.key == "bootstrap" | |
| ? module.automation-tf-bootstrap-sa.iam_email | |
| : module.automation-tf-resman-sa.iam_email | |
| ] | |
| "roles/source.reader" = concat( | |
| [module.automation-tf-cicd-sa[each.key].iam_email], | |
| each.key == "bootstrap" | |
| ? [module.automation-tf-bootstrap-r-sa.iam_email] | |
| : [module.automation-tf-resman-r-sa.iam_email] | |
| ) | |
| } | |
| source = "../../../modules/secure-source-manager-instance" | |
| project_id = module.automation-project.project_id | |
| location = var.regions.primary | |
| instance_id = "${local.prefix}-ssm-instance" | |
| instance_create = anytrue([for k, v in local.cicd_repositories : v.type == "ssm"]) | |
| iam = anytrue([for k, v in local.cicd_repositories : v.type == "ssm"]) ? { | |
| "roles/securesourcemanager.instanceAccessor" = flatten([ | |
| for k, v in local.cicd_repositories : [ | |
| module.automation-tf-cicd-sa[k].iam_email, | |
| module.automation-tf-cicd-r-sa[k].iam_email | |
| ] if v.type == "ssm" | |
| ]) | |
| } : {} | |
| repositories = { | |
| for k, v in local.cicd_repositories : v.name => { | |
| description = "FAST Secure Source Manager repository for ${k} stage." | |
| initial_config = { | |
| default_branch = coalesce(v.branch, "main") | |
| } | |
| iam = { | |
| "roles/securesourcemanager.repoAdmin" = [ | |
| k == "bootstrap" | |
| ? module.automation-tf-bootstrap-sa.iam_email | |
| : module.automation-tf-resman-sa.iam_email | |
| ] | |
| "roles/securesourcemanager.repoReader" = [ | |
| module.automation-tf-cicd-sa[k].iam_email, | |
| module.automation-tf-cicd-r-sa[k].iam_email, | |
| k == "bootstrap" | |
| ? module.automation-tf-bootstrap-r-sa.iam_email | |
| : module.automation-tf-resman-r-sa.iam_email | |
| ] | |
| } | |
| } if v.type == "ssm" | |
| } | |
| } |
| resource "google_cloudbuild_trigger" "automation-tf-cicd-trigger" { | ||
| for_each = { | ||
| for k, v in local.cicd_repositories : k => v if v.type == "ssm" | ||
| } | ||
| triggers = { | ||
| "fast-0-${each.key}" = { | ||
| filename = ".cloudbuild/workflow.yaml" | ||
| included_files = ["**/*tf", ".cloudbuild/workflow.yaml"] | ||
| service_account = module.automation-tf-cicd-sa[each.key].id | ||
| substitutions = {} | ||
| template = { | ||
| project_id = null | ||
| branch_name = each.value.branch | ||
| repo_name = each.value.name | ||
| tag_name = null | ||
| } | ||
| project = module.automation-project.project_id | ||
| name = "fast-0-${each.key}" | ||
|
|
||
| repository_event_config { | ||
| repository = module.automation-tf-cicd-repo.repositories[each.value.name].id | ||
| push { | ||
| branch = "^${coalesce(each.value.branch, "main")}$" | ||
| } | ||
| } | ||
|
|
||
| filename = ".cloudbuild/workflow.yaml" | ||
| service_account = module.automation-tf-cicd-sa[each.key].id | ||
| } |
There was a problem hiding this comment.
google_cloudbuild_trigger with repository_event_config does not work with Secure Source Manager repositories and fails tflint.
-
repository_event_config.repositoryexpects a Cloud Build 2nd-genRepositoryresource formatted asprojects/*/locations/*/connections/*/repositories/*, not a Secure Source Manager repository ID. Native SSM integration triggers Cloud Build from an in-repo.cloudbuild/triggers.yamlfile and requires granting the SSM service agentroles/cloudbuild.builds.editorandroles/serviceusage.serviceUsageConsumeron the build project plusroles/iam.serviceAccountUseron the custom Cloud Build service account. Note as well thatfast/stages-aw/0-bootstrap/automation.tfonly enablescloudbuild.googleapis.comwhenbootstrap_userisnull, andfast/stages-aw/0-bootstrap/data/org-policies/cloudbuild_policy.yamlrestrictscloudbuild.allowedIntegrationstogithub.com. -
tools/tflint.shfails on"automation-tf-cicd-trigger"becauseterraform_naming_conventionenforcessnake_caseresource names.
| resource "google_cloudbuild_trigger" "automation-tf-cicd-trigger" { | |
| for_each = { | |
| for k, v in local.cicd_repositories : k => v if v.type == "ssm" | |
| } | |
| triggers = { | |
| "fast-0-${each.key}" = { | |
| filename = ".cloudbuild/workflow.yaml" | |
| included_files = ["**/*tf", ".cloudbuild/workflow.yaml"] | |
| service_account = module.automation-tf-cicd-sa[each.key].id | |
| substitutions = {} | |
| template = { | |
| project_id = null | |
| branch_name = each.value.branch | |
| repo_name = each.value.name | |
| tag_name = null | |
| } | |
| project = module.automation-project.project_id | |
| name = "fast-0-${each.key}" | |
| repository_event_config { | |
| repository = module.automation-tf-cicd-repo.repositories[each.value.name].id | |
| push { | |
| branch = "^${coalesce(each.value.branch, "main")}$" | |
| } | |
| } | |
| filename = ".cloudbuild/workflow.yaml" | |
| service_account = module.automation-tf-cicd-sa[each.key].id | |
| } | |
| resource "google_project_iam_member" "ssm_service_agent_cloudbuild" { | |
| for_each = toset( | |
| anytrue([for k, v in local.cicd_repositories : v.type == "ssm"]) | |
| ? ["roles/cloudbuild.builds.editor", "roles/serviceusage.serviceUsageConsumer"] | |
| : [] | |
| ) | |
| project = module.automation-project.project_id | |
| role = each.value | |
| member = "serviceAccount:service-${module.automation-project.number}@gcp-sa-sourcemanager.iam.gserviceaccount.com" | |
| } | |
| resource "google_service_account_iam_member" "ssm_service_agent_cicd_sa_user" { | |
| for_each = { | |
| for k, v in local.cicd_repositories : k => v if v.type == "ssm" | |
| } | |
| service_account_id = module.automation-tf-cicd-sa[each.key].name | |
| role = "roles/iam.serviceAccountUser" | |
| member = "serviceAccount:service-${module.automation-project.number}@gcp-sa-sourcemanager.iam.gserviceaccount.com" | |
| } |
| module "branch-network-cicd-repo" { | ||
| source = "../../../modules/source-repository" | ||
| for_each = ( | ||
| try(local.cicd_repositories.networking.type, null) == "sourcerepo" | ||
| try(local.cicd_repositories.networking.type, null) == "ssm" | ||
| ? { 0 = local.cicd_repositories.networking } | ||
| : {} | ||
| ) |
There was a problem hiding this comment.
All seven fast/stages-aw/1-resman/cicd-*.tf files (cicd-data-platform.tf, cicd-gcve.tf, cicd-gke.tf, cicd-networking.tf, cicd-project-factory.tf, cicd-security.tf, and cicd-teams.tf) switched "sourcerepo" to "ssm" while keeping source = "../../../modules/source-repository", roles/source.admin, roles/source.reader, and Cloud Source Repository triggers. Each block needs to move to ../../../modules/secure-source-manager-instance with instance_create = false and updated SSM IAM roles. Because GitHub restricts suggestions to lines inside the diff hunk (21..27), remove the legacy source-repository arguments on lines 28..49 immediately below after applying this suggestion, and apply the same pattern across the remaining six 1-resman/cicd-*.tf files.
| module "branch-network-cicd-repo" { | |
| source = "../../../modules/source-repository" | |
| for_each = ( | |
| try(local.cicd_repositories.networking.type, null) == "sourcerepo" | |
| try(local.cicd_repositories.networking.type, null) == "ssm" | |
| ? { 0 = local.cicd_repositories.networking } | |
| : {} | |
| ) | |
| module "branch-network-cicd-repo" { | |
| source = "../../../modules/secure-source-manager-instance" | |
| for_each = ( | |
| try(local.cicd_repositories.networking.type, null) == "ssm" | |
| ? { 0 = local.cicd_repositories.networking } | |
| : {} | |
| ) | |
| project_id = var.automation.project_id | |
| location = var.regions.primary | |
| instance_id = "${var.prefix}-prod-ssm-instance" | |
| instance_create = false | |
| repositories = { | |
| (each.value.name) = { | |
| description = "FAST Secure Source Manager repository for networking stage." | |
| initial_config = { | |
| default_branch = coalesce(each.value.branch, "main") | |
| } | |
| iam = { | |
| "roles/securesourcemanager.repoAdmin" = [ | |
| module.branch-network-sa.iam_email | |
| ] | |
| "roles/securesourcemanager.repoReader" = [ | |
| module.branch-network-sa-cicd[0].iam_email, | |
| module.branch-network-r-sa-cicd[0].iam_email | |
| ] | |
| } | |
| } | |
| } | |
| depends_on = [ | |
| module.branch-network-sa-cicd, | |
| module.branch-network-r-sa-cicd | |
| ] | |
| } |
… IAM roles to include Secure Source Manager accessors
…e Secure Source Manager API
1a8d166 to
37c2450
Compare
Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context.
Fixes # 198
Type of Change
Deployment & Compliance Impact
Checklist
Code Quality & Reusability
modules/orfast/can be leveraged for this change.documentation/naming-convention.md.Documentation
README.mdof the modified module or blueprint.Security
Testing
Testing Performed
Please describe the tests that you ran to verify your changes.