Skip to content

Commit 33a6619

Browse files
authored
feat: Inline App Infra Pipeline sa_roles (#867)
* inline sa_roles in to the example base shared vpc project creation * add explanation regarding sa_roles usage
1 parent 6e9c575 commit 33a6619

File tree

10 files changed

+34
-46
lines changed

10 files changed

+34
-46
lines changed

3-networks-dual-svpc/shared.auto.example.tfvars

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
// List of IPv4 address of target name servers for the forwarding zone configuration.
1818
// See https://cloud.google.com/dns/docs/overview#dns-forwarding-zones
1919
target_name_server_addresses = [
20-
{
21-
ipv4_address = "192.168.0.1",
22-
forwarding_path = "default"
23-
},
24-
{
25-
ipv4_address = "192.168.0.2",
26-
forwarding_path = "default"
27-
}
28-
]
20+
{
21+
ipv4_address = "192.168.0.1",
22+
forwarding_path = "default"
23+
},
24+
{
25+
ipv4_address = "192.168.0.2",
26+
forwarding_path = "default"
27+
}
28+
]

3-networks-hub-and-spoke/shared.auto.example.tfvars

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
// List of IPv4 address of target name servers for the forwarding zone configuration.
1818
// See https://cloud.google.com/dns/docs/overview#dns-forwarding-zones
1919
target_name_server_addresses = [
20-
{
21-
ipv4_address = "192.168.0.1",
22-
forwarding_path = "default"
23-
},
24-
{
25-
ipv4_address = "192.168.0.2",
26-
forwarding_path = "default"
27-
}
28-
]
20+
{
21+
ipv4_address = "192.168.0.1",
22+
forwarding_path = "default"
23+
},
24+
{
25+
ipv4_address = "192.168.0.2",
26+
forwarding_path = "default"
27+
}
28+
]

4-projects/business_unit_1/shared/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
| enable\_cloudbuild\_deploy | Enable infra deployment using Cloud Build. |
1919
| plan\_triggers\_id | CB plan triggers |
2020
| repos | CSRs to store source code |
21-
| sa\_roles | A list of roles to give the Service Accounts from App Infra Pipeline by workspace repository. |
2221
| state\_buckets | GCS Buckets to store TF state |
2322
| terraform\_service\_accounts | APP Infra Pipeline Terraform Accounts. |
2423

4-projects/business_unit_1/shared/example_infra_pipeline.tf

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@
1515
*/
1616

1717
locals {
18-
sa_roles = {
19-
"bu1-example-app" = [
20-
"roles/compute.instanceAdmin.v1",
21-
"roles/iam.serviceAccountAdmin",
22-
"roles/iam.serviceAccountUser",
23-
]
24-
}
2518
repo_names = ["bu1-example-app"]
2619
}
2720

4-projects/business_unit_1/shared/outputs.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ output "repos" {
3333
value = try(module.infra_pipelines[0].repos, toset([]))
3434
}
3535

36-
output "sa_roles" {
37-
description = "A list of roles to give the Service Accounts from App Infra Pipeline by workspace repository."
38-
value = local.enable_cloudbuild_deploy ? local.sa_roles : {}
39-
}
40-
4136
output "artifact_buckets" {
4237
description = "GCS Buckets to store Cloud Build Artifacts"
4338
value = try(module.infra_pipelines[0].artifact_buckets, {})

4-projects/business_unit_2/shared/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
| enable\_cloudbuild\_deploy | Enable infra deployment using Cloud Build. |
1919
| plan\_triggers\_id | CB plan triggers |
2020
| repos | CSRs to store source code |
21-
| sa\_roles | A list of roles to give the Service Accounts from App Infra Pipeline by workspace repository. |
2221
| state\_buckets | GCS Buckets to store TF state |
2322
| terraform\_service\_accounts | APP Infra Pipeline Terraform Accounts. |
2423

4-projects/business_unit_2/shared/example_infra_pipeline.tf

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@
1515
*/
1616

1717
locals {
18-
sa_roles = {
19-
"bu2-example-app" = [
20-
"roles/compute.instanceAdmin.v1",
21-
"roles/iam.serviceAccountAdmin",
22-
"roles/iam.serviceAccountUser",
23-
]
24-
}
2518
repo_names = ["bu2-example-app"]
2619
}
2720

4-projects/business_unit_2/shared/outputs.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ output "repos" {
3333
value = try(module.infra_pipelines[0].repos, toset([]))
3434
}
3535

36-
output "sa_roles" {
37-
description = "A list of roles to give the Service Accounts from App Infra Pipeline by workspace repository."
38-
value = local.enable_cloudbuild_deploy ? local.sa_roles : {}
39-
}
40-
4136
output "artifact_buckets" {
4237
description = "GCS Buckets to store Cloud Build Artifacts"
4338
value = try(module.infra_pipelines[0].artifact_buckets, {})

4-projects/modules/base_env/example_base_shared_vpc_project.tf

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,24 @@ module "base_shared_vpc_project" {
2727
project_budget = var.project_budget
2828
project_prefix = local.project_prefix
2929
enable_cloudbuild_deploy = local.enable_cloudbuild_deploy
30-
sa_roles = local.sa_roles
3130
app_infra_pipeline_service_accounts = local.app_infra_pipeline_service_accounts
3231

32+
// The roles defined in "sa_roles" will be used to grant the necessary permissions
33+
// to deploy the resources, a Compute Engine instance for each environment, defined
34+
// in 5-app-infra step (5-app-infra/modules/env_base/main.tf).
35+
// The roles are grouped by the repository name ("${var.business_code}-example-app") used to create the Cloud Build workspace
36+
// (https://github.com/terraform-google-modules/terraform-google-bootstrap/tree/master/modules/tf_cloudbuild_workspace)
37+
// in the 4-projects shared environment of each business unit.
38+
// the repository name is the same key used for the app_infra_pipeline_service_accounts map and the
39+
// roles will be granted to the service account with the same key.
40+
sa_roles = {
41+
"${var.business_code}-example-app" = [
42+
"roles/compute.instanceAdmin.v1",
43+
"roles/iam.serviceAccountAdmin",
44+
"roles/iam.serviceAccountUser",
45+
]
46+
}
47+
3348
activate_apis = [
3449
"iam.googleapis.com",
3550
"cloudresourcemanager.googleapis.com"

4-projects/modules/base_env/main.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ locals {
3232
access_context_manager_policy_id = data.terraform_remote_state.network_env.outputs.access_context_manager_policy_id
3333
env_folder_name = data.terraform_remote_state.environments_env.outputs.env_folder
3434
app_infra_pipeline_service_accounts = data.terraform_remote_state.business_unit_shared.outputs.terraform_service_accounts
35-
sa_roles = data.terraform_remote_state.business_unit_shared.outputs.sa_roles
3635
enable_cloudbuild_deploy = data.terraform_remote_state.business_unit_shared.outputs.enable_cloudbuild_deploy
3736
}
3837

0 commit comments

Comments
 (0)