Skip to content

Commit 7001a69

Browse files
feat: add backend.tf instructions and cluster service accounts output (#219)
1 parent 58e500e commit 7001a69

File tree

10 files changed

+57
-0
lines changed

10 files changed

+57
-0
lines changed

1-bootstrap/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,29 @@ You can now deploy the common environment for these pipelines.
6161

6262
If you receive any errors or made any changes to the Terraform config or `terraform.tfvars`, re-run `terraform plan` before you run `terraform apply`.
6363

64+
### Updating `backend.tf` files on the repository
65+
66+
Within the repository, you'll find `backend.tf` files that define the GCS bucket for storing the Terraform state. By running the commands below, instances of `UPDATE_ME` placeholders in these files will be automatically replaced with the actual name of your GCS bucket.
67+
68+
1. Running the series of commands below will update the remote state bucket for `backend.tf` files on the repository.
69+
70+
```bash
71+
export backend_bucket=$(terraform output -raw state_bucket)
72+
echo "backend_bucket = ${backend_bucket}"
73+
74+
cp backend.tf.example backend.tf
75+
cd ..
76+
77+
for i in `find . -name 'backend.tf'`; do sed -i'' -e "s/UPDATE_ME/${backend_bucket}/" $i; done
78+
```
79+
80+
1. Re-run `terraform init`. When you're prompted, agree to copy Terraform state to Cloud Storage.
81+
82+
```bash
83+
cd 1-bootstrap
84+
85+
terraform init
86+
```
6487

6588
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
6689
## Inputs

2-multitenant/envs/development/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
| cluster\_membership\_ids | GKE cluster membership IDs |
1616
| cluster\_project\_id | Cluster Project ID |
1717
| cluster\_regions | Regions with clusters |
18+
| cluster\_service\_accounts | The default service accounts used for nodes, if not overridden in node\_pools. |
1819
| cluster\_type | Cluster type |
1920
| env | Environment |
2021
| fleet\_project\_id | Fleet Project ID |

2-multitenant/envs/development/outputs.tf

+5
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,8 @@ output "cluster_type" {
5858
description = "Cluster type"
5959
value = module.env.cluster_type
6060
}
61+
62+
output "cluster_service_accounts" {
63+
description = "The default service accounts used for nodes, if not overridden in node_pools."
64+
value = module.env.cluster_service_accounts
65+
}

2-multitenant/envs/nonproduction/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
| cluster\_membership\_ids | GKE cluster membership IDs |
1616
| cluster\_project\_id | Cluster Project ID |
1717
| cluster\_regions | Regions with clusters |
18+
| cluster\_service\_accounts | The default service accounts used for nodes, if not overridden in node\_pools. |
1819
| cluster\_type | Cluster type |
1920
| env | Environment |
2021
| fleet\_project\_id | Fleet Project ID |

2-multitenant/envs/nonproduction/outputs.tf

+5
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,8 @@ output "cluster_type" {
5858
description = "Cluster type"
5959
value = module.env.cluster_type
6060
}
61+
62+
output "cluster_service_accounts" {
63+
description = "The default service accounts used for nodes, if not overridden in node_pools."
64+
value = module.env.cluster_service_accounts
65+
}

2-multitenant/envs/production/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
| cluster\_membership\_ids | GKE cluster membership IDs |
1616
| cluster\_project\_id | Cluster Project ID |
1717
| cluster\_regions | Regions with clusters |
18+
| cluster\_service\_accounts | The default service accounts used for nodes, if not overridden in node\_pools. |
1819
| cluster\_type | Cluster type |
1920
| env | Environment |
2021
| fleet\_project\_id | Fleet Project ID |

2-multitenant/envs/production/outputs.tf

+5
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,8 @@ output "cluster_type" {
5858
description = "Cluster type"
5959
value = module.env.cluster_type
6060
}
61+
62+
output "cluster_service_accounts" {
63+
description = "The default service accounts used for nodes, if not overridden in node_pools."
64+
value = module.env.cluster_service_accounts
65+
}

2-multitenant/modules/env_baseline/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ The following resources are created:
3636
| cluster\_membership\_ids | GKE cluster membership IDs |
3737
| cluster\_project\_id | Cluster Project ID |
3838
| cluster\_regions | Regions with clusters |
39+
| cluster\_service\_accounts | The default service accounts used for nodes, if not overridden in node\_pools. |
3940
| cluster\_type | Cluster type |
4041
| fleet\_project\_id | Fleet Project ID |
4142
| network\_project\_id | Network Project ID |

2-multitenant/modules/env_baseline/outputs.tf

+7
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,10 @@ output "cluster_type" {
6464
description = "Cluster type"
6565
value = var.cluster_type
6666
}
67+
68+
output "cluster_service_accounts" {
69+
description = "The default service accounts used for nodes, if not overridden in node_pools."
70+
value = [
71+
for value in merge(module.gke-standard, module.gke-autopilot) : value.service_account
72+
]
73+
}

test/integration/multitenant/multitenant_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@ func TestMultitenant(t *testing.T) {
199199
})
200200
}
201201

202+
cluster_service_accounts := multitenant.GetJsonOutput("cluster_service_accounts").Array()
203+
204+
assert.Greater(len(cluster_service_accounts), 0, "The terraform output must contain more than 0 service accounts.")
205+
// create regex to validate service accounts emails
206+
saRegex := `^[a-zA-Z0-9_+-]+@[a-zA-Z0-9-]+.iam.gserviceaccount.com$`
207+
for _, sa := range cluster_service_accounts {
208+
assert.Regexp(saRegex, sa.String(), "The cluster SA value must be a Google Service Account")
209+
}
202210
})
203211

204212
multitenant.Test()

0 commit comments

Comments
 (0)