-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor terraform and fix kafka authentication
- Loading branch information
Showing
13 changed files
with
279 additions
and
157 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
provider "google" { | ||
project = "platform-poc-407113" | ||
} | ||
|
||
module "shared_vars" { | ||
source = "../shared" | ||
} | ||
|
||
resource "google_container_cluster" "primary" { | ||
name = "${module.shared_vars.project_id}-cluster" | ||
location = module.shared_vars.region | ||
deletion_protection = false | ||
|
||
remove_default_node_pool = true | ||
initial_node_count = 1 | ||
|
||
workload_identity_config { | ||
workload_pool = "${module.shared_vars.project_id}.svc.id.goog" | ||
} | ||
} | ||
|
||
resource "google_container_node_pool" "primary_nodes" { | ||
name = "primary-node-pool" | ||
location = module.shared_vars.region | ||
cluster = google_container_cluster.primary.name | ||
node_count = 1 | ||
|
||
node_config { | ||
machine_type = "e2-standard-2" | ||
service_account = google_service_account.workload-identity-user-sa.email | ||
} | ||
} | ||
|
||
resource "google_service_account" "workload-identity-user-sa" { | ||
account_id = "cloud-sql-client-sa" | ||
display_name = "Cloud SQL Client Service Account" | ||
description = "Service account used for Cloud SQL Auth PRoxy" | ||
} | ||
|
||
resource "google_project_iam_member" "sql-client-role" { | ||
project = module.shared_vars.project_id | ||
role = "roles/cloudsql.client" | ||
member = "serviceAccount:${google_service_account.workload-identity-user-sa.email}" | ||
} | ||
|
||
resource "google_project_iam_member" "datastore-user-role" { | ||
project = module.shared_vars.project_id | ||
role = "roles/datastore.user" | ||
member = "serviceAccount:${google_service_account.workload-identity-user-sa.email}" | ||
} | ||
|
||
resource "google_project_iam_member" "storage-role" { | ||
project = module.shared_vars.project_id | ||
role = "roles/storage.admin" | ||
member = "serviceAccount:${google_service_account.workload-identity-user-sa.email}" | ||
} | ||
|
||
output "node_pool_service_account" { | ||
value = google_service_account.workload-identity-user-sa.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,10 @@ | ||
terraform { | ||
required_providers { | ||
google = { | ||
source = "hashicorp/google" | ||
version = "= 5.8.0" | ||
} | ||
} | ||
|
||
required_version = ">= 1.6.5" | ||
} |
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,55 @@ | ||
provider "kubernetes" { | ||
config_path = "~/.kube/config" | ||
config_context = module.shared_vars.kubernetes_context | ||
} | ||
|
||
module "shared_vars" { | ||
source = "../shared" | ||
} | ||
|
||
variable "pg_user" { | ||
description = "Username for Postgres Cloud SQL database" | ||
} | ||
|
||
variable "pg_password" { | ||
description = "password for Postgres Cloud SQL database" | ||
} | ||
|
||
variable "pg_database" { | ||
description = "Postgres Cloud SQL database name" | ||
} | ||
|
||
data "terraform_remote_state" "workload-identity-user-sa" { | ||
backend = "local" | ||
|
||
config = { | ||
path = "../cluster/terraform.tfstate" | ||
} | ||
} | ||
|
||
resource "google_project_iam_member" "workload_identity-role" { | ||
project = module.shared_vars.project_id | ||
role = "roles/iam.workloadIdentityUser" | ||
member = "serviceAccount:${module.shared_vars.project_id}.svc.id.goog[default/${kubernetes_service_account.ksa.metadata[0].name}]" | ||
} | ||
|
||
resource "kubernetes_service_account" "ksa" { | ||
metadata { | ||
name = "kubernetes-service-account" | ||
annotations = { | ||
"iam.gke.io/gcp-service-account" = data.terraform_remote_state.workload-identity-user-sa.outputs.node_pool_service_account | ||
} | ||
} | ||
} | ||
|
||
resource "kubernetes_secret" "db_secrets" { | ||
metadata { | ||
name = "postgres-db-secrets" | ||
} | ||
|
||
data = { | ||
username = var.pg_user | ||
password = var.pg_password | ||
database = var.pg_database | ||
} | ||
} |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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,17 @@ | ||
locals { | ||
project_id = "platform-poc-407113" | ||
region = "europe-west2" | ||
kubernetes_context = "gke_platform-poc-407113_europe-west2_platform-poc-407113-cluster" | ||
} | ||
|
||
output "project_id" { | ||
value = local.project_id | ||
} | ||
|
||
output "region" { | ||
value = local.region | ||
} | ||
|
||
output "kubernetes_context" { | ||
value = local.kubernetes_context | ||
} |
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,10 @@ | ||
terraform { | ||
required_providers { | ||
google = { | ||
source = "hashicorp/google" | ||
version = "= 5.8.0" | ||
} | ||
} | ||
|
||
required_version = ">= 1.6.5" | ||
} |
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,59 @@ | ||
provider "google" { | ||
project = "platform-poc-407113" | ||
} | ||
|
||
module "shared_vars" { | ||
source = "../shared" | ||
} | ||
|
||
variable "pg_user" { | ||
description = "Username for Postgres Cloud SQL database" | ||
} | ||
|
||
variable "pg_password" { | ||
description = "password for Postgres Cloud SQL database" | ||
} | ||
|
||
variable "pg_database" { | ||
description = "Postgres Cloud SQL database name" | ||
} | ||
|
||
resource "google_sql_database" "database_orders" { | ||
name = "order-service" | ||
instance = google_sql_database_instance.instance.name | ||
} | ||
|
||
resource "google_sql_database" "database_inventory" { | ||
name = "inventory-service" | ||
instance = google_sql_database_instance.instance.name | ||
} | ||
|
||
resource "google_sql_user" "user" { | ||
name = var.pg_user | ||
instance = google_sql_database_instance.instance.name | ||
password = var.pg_password | ||
} | ||
|
||
resource "google_sql_database_instance" "instance" { | ||
name = "${module.shared_vars.project_id}-pg" | ||
region = module.shared_vars.region | ||
database_version = "POSTGRES_15" | ||
settings { | ||
tier = "db-f1-micro" | ||
database_flags { | ||
name = "max_connections" | ||
value = "50" | ||
} | ||
} | ||
|
||
deletion_protection = "false" | ||
} | ||
|
||
resource "google_firestore_database" "datastore_database" { | ||
project = module.shared_vars.project_id | ||
name = "(default)" | ||
location_id = module.shared_vars.region | ||
type = "DATASTORE_MODE" | ||
delete_protection_state = "DELETE_PROTECTION_DISABLED" | ||
deletion_policy = "DELETE" | ||
} |
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,3 @@ | ||
terraform { | ||
required_version = ">= 1.6.5" | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.