Skip to content

Commit 75f0a06

Browse files
chroe: add gcp standalone infra example
1 parent 79b5858 commit 75f0a06

5 files changed

Lines changed: 63 additions & 9 deletions

File tree

examples/standalone-infra/iam.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
resource "google_service_account" "ctrlplane" {
2+
account_id = "${var.name}-ctrlplane"
3+
display_name = "Ctrlplane ${var.name}"
4+
project = var.project_id
5+
}
6+
7+
resource "google_project_iam_member" "kafka_client" {
8+
project = var.project_id
9+
role = "roles/managedkafka.client"
10+
member = "serviceAccount:${google_service_account.ctrlplane.email}"
11+
}
12+
13+
resource "google_project_iam_member" "cloudsql_client" {
14+
project = var.project_id
15+
role = "roles/cloudsql.client"
16+
member = "serviceAccount:${google_service_account.ctrlplane.email}"
17+
}
18+
19+
resource "google_service_account_iam_member" "workload_identity" {
20+
service_account_id = google_service_account.ctrlplane.name
21+
role = "roles/iam.workloadIdentityUser"
22+
member = "serviceAccount:${var.project_id}.svc.id.goog[ctrlplane/ctrlplane]"
23+
}

examples/standalone-infra/network.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ resource "google_service_networking_connection" "private_vpc" {
4343
service = "servicenetworking.googleapis.com"
4444
reserved_peering_ranges = [google_compute_global_address.private_ip_range.name]
4545

46+
deletion_policy = "ABANDON"
47+
4648
depends_on = [google_project_service.apis]
4749
}
4850

@@ -55,3 +57,19 @@ resource "google_compute_global_address" "ingress" {
5557

5658
depends_on = [google_project_service.apis]
5759
}
60+
61+
# -----------------------------------------------------------------------------
62+
# Google-Managed SSL Certificate
63+
# -----------------------------------------------------------------------------
64+
65+
resource "google_compute_managed_ssl_certificate" "ingress" {
66+
name = "${var.name}-ssl-cert"
67+
68+
managed {
69+
domains = [var.domain]
70+
}
71+
72+
lifecycle {
73+
create_before_destroy = true
74+
}
75+
}

examples/standalone-infra/outputs.tf

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,30 @@ output "ingress_static_ip_name" {
7171
value = google_compute_global_address.ingress.name
7272
}
7373

74+
output "ssl_certificate_name" {
75+
description = "Google-managed SSL certificate name (use in ingress annotations)"
76+
value = google_compute_managed_ssl_certificate.ingress.name
77+
}
78+
79+
# -----------------------------------------------------------------------------
80+
# IAM
81+
# -----------------------------------------------------------------------------
82+
83+
output "service_account_email" {
84+
description = "GCP service account email for Workload Identity"
85+
value = google_service_account.ctrlplane.email
86+
}
87+
7488
# -----------------------------------------------------------------------------
7589
# Helm Values
7690
# -----------------------------------------------------------------------------
7791

7892
output "helm_values" {
79-
description = "Paste this into your values.yaml override (fill in fqdn + ingress class)"
93+
description = "Helm values.yaml override for the ctrlplane chart"
8094
sensitive = true
8195
value = yamlencode({
8296
global = {
83-
fqdn = "REPLACE_WITH_YOUR_DOMAIN"
97+
fqdn = "https://${var.domain}"
8498
postgresql = {
8599
user = google_sql_user.ctrlplane.name
86100
password = random_password.postgres.result
@@ -99,6 +113,7 @@ output "helm_values" {
99113
class = "gce"
100114
annotations = {
101115
"kubernetes.io/ingress.global-static-ip-name" = google_compute_global_address.ingress.name
116+
"networking.gke.io/managed-certificates" = google_compute_managed_ssl_certificate.ingress.name
102117
}
103118
}
104119
})

examples/standalone-infra/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,8 @@ variable "kafka_memory_bytes" {
4444
type = number
4545
default = 3221225472 # 3 GiB
4646
}
47+
48+
variable "domain" {
49+
description = "Domain name for the ingress (used for managed SSL cert)"
50+
type = string
51+
}
Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
terraform {
22
required_version = ">= 1.5"
33

4-
backend "gcs" {}
5-
64
required_providers {
75
google = {
86
source = "hashicorp/google"
@@ -14,8 +12,3 @@ terraform {
1412
}
1513
}
1614
}
17-
18-
provider "google" {
19-
project = var.project_id
20-
region = var.region
21-
}

0 commit comments

Comments
 (0)