Skip to content

Commit 13f383d

Browse files
Merge pull request #4 from sizzldev/redis-updates
fix: Redis updates and sa cluster permissions
2 parents 18e4f2a + ad2c0a4 commit 13f383d

File tree

8 files changed

+50
-18
lines changed

8 files changed

+50
-18
lines changed

main.tf

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ module "project_factory_project_services" {
55
disable_dependent_services = false
66
disable_services_on_destroy = false
77
activate_apis = [
8-
"sqladmin.googleapis.com", // Database
9-
"networkmanagement.googleapis.com", // Networking
10-
"servicenetworking.googleapis.com", // Networking
8+
"iam.googleapis.com",
9+
"sqladmin.googleapis.com",
10+
"networkmanagement.googleapis.com",
11+
"servicenetworking.googleapis.com",
12+
"redis.googleapis.com",
1113
]
1214
}
1315

@@ -36,8 +38,9 @@ module "redis" {
3638
source = "./modules/redis"
3739
namespace = var.namespace
3840

39-
tier = var.redis_tier
40-
memory_size_gb = var.redis_memory_size_gb
41+
tier = var.redis_tier
42+
memory_size_gb = var.redis_memory_size_gb
43+
rdb_snapshot_period = var.redis_rdb_snapshot_period
4144

4245
network_id = module.networking.network_id
4346
}

modules/gke/main.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
data "google_client_config" "current" {}
2+
3+
locals {
4+
project_id = data.google_client_config.current.project
5+
}
6+
17
resource "google_container_cluster" "this" {
28
name = "${var.namespace}-cluster"
39

@@ -8,8 +14,8 @@ resource "google_container_cluster" "this" {
814

915
deletion_protection = var.deletion_protection
1016

11-
node_config {
12-
service_account = var.service_account_email
17+
workload_identity_config {
18+
workload_pool = "${local.project_id}.svc.id.goog"
1319
}
1420

1521
release_channel {

modules/redis/main.tf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,12 @@ resource "google_redis_instance" "this" {
99

1010
auth_enabled = true
1111

12-
transit_encryption_mode = "SERVER_AUTHENTICATION"
12+
redis_configs = {
13+
maxmemory-policy = "noeviction"
14+
}
15+
16+
persistence_config {
17+
persistence_mode = "RDB"
18+
rdb_snapshot_period = var.rdb_snapshot_period
19+
}
1320
}

modules/redis/outputs.tf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
output "redis_ca_cert" {
2-
value = google_redis_instance.this.server_ca_certs[0].cert
3-
}
4-
51
output "redis_auth_string" {
62
value = google_redis_instance.this.auth_string
73
}

modules/redis/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ variable "memory_size_gb" {
1717
description = "The memory size for the Redis instance."
1818
type = number
1919
}
20+
21+
variable "rdb_snapshot_period" {
22+
description = "The snapshot period for the Redis instance."
23+
type = string
24+
}

modules/service_accounts/main.tf

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,22 @@ locals {
1616
project_id = data.google_client_config.current.project
1717
}
1818

19-
resource "google_project_iam_member" "this" {
19+
resource "google_project_iam_member" "cloudsql_client" {
2020
project = local.project_id
2121
role = "roles/cloudsql.client"
2222
member = local.sa_member
2323
}
24+
25+
resource "google_project_iam_member" "sa_creator" {
26+
project = local.project_id
27+
role = "roles/iam.serviceAccountCreator"
28+
member = local.sa_member
29+
}
30+
31+
resource "google_service_account_iam_binding" "this" {
32+
service_account_id = google_service_account.this.id
33+
role = "roles/iam.workloadIdentityUser"
34+
members = [
35+
"serviceAccount:${local.project_id}.svc.id.goog[default/ctrlplane-${var.namespace}-sa]"
36+
]
37+
}

outputs.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ output "database_instance_private_ip_address" {
1818
description = "The private IP address of the database instance."
1919
}
2020

21-
output "redis_ca_cert" {
22-
value = module.redis.redis_ca_cert
23-
description = "The CA certificate of the Redis instance."
24-
}
25-
2621
output "redis_auth_string" {
2722
value = module.redis.redis_auth_string
2823
description = "The authentication string of the Redis instance."

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ variable "redis_memory_size_gb" {
2727
default = 1
2828
}
2929

30+
variable "redis_rdb_snapshot_period" {
31+
description = "The snapshot period for the Redis instance."
32+
type = string
33+
default = "ONE_HOUR"
34+
}
35+
3036
variable "deletion_protection" {
3137
description = "Whether to enable deletion protection for the resources."
3238
type = bool

0 commit comments

Comments
 (0)