This repository has been archived by the owner on Mar 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from gruntwork-io/byo-service-account
BYO Service Accounts
- Loading branch information
Showing
10 changed files
with
139 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,9 +66,6 @@ module "gke_cluster" { | |
|
||
name = "${var.cluster_name}" | ||
|
||
// TODO(rileykarson): Update this when a new version comes out | ||
kubernetes_version = "1.12.5-gke.5" | ||
|
||
project = "${var.project}" | ||
location = "${var.location}" | ||
network = "${google_compute_network.main.name}" | ||
|
@@ -112,6 +109,8 @@ resource "google_container_node_pool" "node_pool" { | |
disk_type = "pd-standard" | ||
preemptible = false | ||
|
||
service_account = "${module.gke_service_account.email}" | ||
|
||
oauth_scopes = [ | ||
"https://www.googleapis.com/auth/cloud-platform", | ||
] | ||
|
@@ -128,6 +127,21 @@ resource "google_container_node_pool" "node_pool" { | |
} | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# CREATE A CUSTOM SERVICE ACCOUNT TO USE WITH THE GKE CLUSTER | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
module "gke_service_account" { | ||
# When using these modules in your own templates, you will need to use a Git URL with a ref attribute that pins you | ||
# to a specific version of the modules, such as the following example: | ||
# source = "git::[email protected]:gruntwork-io/gke-cluster.git//modules/gke-service-account?ref=v0.0.1" | ||
source = "../../modules/gke-service-account" | ||
|
||
name = "${var.cluster_service_account_name}" | ||
project = "${var.project}" | ||
description = "${var.cluster_service_account_description}" | ||
} | ||
|
||
# TODO(rileykarson): Add proper VPC network config once we've made a VPC module | ||
resource "random_string" "suffix" { | ||
length = 4 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,9 +30,6 @@ module "gke_cluster" { | |
|
||
name = "${var.cluster_name}" | ||
|
||
// TODO(rileykarson): Update this when a new version comes out | ||
kubernetes_version = "1.12.5-gke.5" | ||
|
||
project = "${var.project}" | ||
location = "${var.location}" | ||
network = "${google_compute_network.main.name}" | ||
|
@@ -77,6 +74,8 @@ resource "google_container_node_pool" "node_pool" { | |
disk_type = "pd-standard" | ||
preemptible = false | ||
|
||
service_account = "${module.gke_service_account.email}" | ||
|
||
oauth_scopes = [ | ||
"https://www.googleapis.com/auth/cloud-platform", | ||
] | ||
|
@@ -93,6 +92,21 @@ resource "google_container_node_pool" "node_pool" { | |
} | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# CREATE A CUSTOM SERVICE ACCOUNT TO USE WITH THE GKE CLUSTER | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
module "gke_service_account" { | ||
# When using these modules in your own templates, you will need to use a Git URL with a ref attribute that pins you | ||
# to a specific version of the modules, such as the following example: | ||
# source = "git::[email protected]:gruntwork-io/gke-cluster.git//modules/gke-service-account?ref=v0.0.1" | ||
source = "../../modules/gke-service-account" | ||
|
||
name = "${var.cluster_service_account_name}" | ||
project = "${var.project}" | ||
description = "${var.cluster_service_account_description}" | ||
} | ||
|
||
# TODO(rileykarson): Add proper VPC network config once we've made a VPC module | ||
resource "random_string" "suffix" { | ||
length = 4 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# GKE Service Account Module | ||
|
||
The GKE Service Account module is used to create a GCP service account for use with a GKE cluster. It is based on | ||
the best practices referenced in this article: | ||
https://cloud.google.com/kubernetes-engine/docs/tutorials/authenticating-to-cloud-platform. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
resource "google_service_account" "service_account" { | ||
project = "${var.project}" | ||
account_id = "${var.name}" | ||
display_name = "${var.description}" | ||
} | ||
|
||
# Grant the service account the minimum necessary roles and permissions in order to run the GKE cluster | ||
resource "google_project_iam_member" "service_account-log_writer" { | ||
project = "${google_service_account.service_account.project}" | ||
role = "roles/logging.logWriter" | ||
member = "serviceAccount:${google_service_account.service_account.email}" | ||
} | ||
|
||
resource "google_project_iam_member" "service_account-metric_writer" { | ||
project = "${google_project_iam_member.service_account-log_writer.project}" | ||
role = "roles/monitoring.metricWriter" | ||
member = "serviceAccount:${google_service_account.service_account.email}" | ||
} | ||
|
||
resource "google_project_iam_member" "service_account-monitoring_viewer" { | ||
project = "${google_project_iam_member.service_account-metric_writer.project}" | ||
role = "roles/monitoring.viewer" | ||
member = "serviceAccount:${google_service_account.service_account.email}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
output "email" { | ||
# This may seem redundant with the `name` input, but it serves an important | ||
# purpose. Terraform won't establish a dependency graph without this to interpolate on. | ||
description = "The email address of the custom service account." | ||
|
||
value = "${google_service_account.service_account.email}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
# REQUIRED MODULE PARAMETERS | ||
# These parameters must be supplied when consuming this module. | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
variable "project" { | ||
description = "The name of the GCP Project where all resources will be launched." | ||
} | ||
|
||
variable "name" { | ||
description = "The name of the custom service account. This parameter is limited to a maximum of 28 characters." | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# OPTIONAL MODULE PARAMETERS | ||
# These parameters have reasonable defaults. | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
variable "description" { | ||
description = "The description of the custom service account." | ||
default = "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters