@@ -59,8 +59,48 @@ Specifically it must have the `container.clusters.get` permission. This can be
5959given with the _ Kubernetes Engine Cluster Viewer_ role
6060(` roles/container.clusterViewer ` ).
6161
62- A sample Terraform project can be found at
63- [ ` ./deployment/terraform/gke-datagatherer/ ` ] ( deployment/terraform/gke-datagatherer ) .
64- This can be used to create a GCP service account called ` preflight ` which
65- is then bound to a custom role of the same name
66- with the minimum required permissions.
62+ ### Sample Terraform Configuration
63+
64+ This can be used to create a GCP service account called ` preflight ` which is
65+ then bound to a custom role of the same name with the minimum required
66+ permissions.
67+
68+
69+ ``` hcl
70+ terraform {
71+ required_version = "~> 0.12"
72+ }
73+
74+ variable "project_id" {
75+ type = string
76+ description = "The ID of the project where the cluster Preflight is going to check is."
77+ }
78+
79+ # https://www.terraform.io/docs/providers/google/index.html
80+ provider "google" {
81+ version = "2.5.1"
82+ project = var.project_id
83+ }
84+
85+ # https://www.terraform.io/docs/providers/google/r/google_service_account.html
86+ resource "google_service_account" "preflight_agent_service_account" {
87+ project = var.project_id
88+ account_id = "preflight-agent"
89+ display_name = "Service account for Preflight Agent"
90+ }
91+
92+ # https://www.terraform.io/docs/providers/google/r/google_project_iam_custom_role.html
93+ resource "google_project_iam_member" "preflight_agent_cluster_viewer" {
94+ project = var.project_id
95+ role = "roles/container.clusterViewer" # allows getting of credentials, all other permissions handled in k8s RBAC
96+ member = "serviceAccount:${google_service_account.preflight_agent_service_account.email}"
97+ }
98+
99+ # if using workload identity in GKE, use the following binding to allow the
100+ # agent to use the service account
101+ resource "google_project_iam_binding" "preflight_agent_workload_identity" {
102+ project = var.project_id
103+ role = "roles/iam.workloadIdentityUser"
104+ members = "serviceAccount:${var.project_id}.svc.id.goog[preflight/default]"
105+ }
106+ ```
0 commit comments