Skip to content

Commit

Permalink
Merge pull request #4 from sizzldev/redis-updates
Browse files Browse the repository at this point in the history
fix: Redis updates and sa cluster permissions
  • Loading branch information
adityachoudhari26 authored Aug 28, 2024
2 parents 18e4f2a + ad2c0a4 commit 13f383d
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 18 deletions.
13 changes: 8 additions & 5 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ module "project_factory_project_services" {
disable_dependent_services = false
disable_services_on_destroy = false
activate_apis = [
"sqladmin.googleapis.com", // Database
"networkmanagement.googleapis.com", // Networking
"servicenetworking.googleapis.com", // Networking
"iam.googleapis.com",
"sqladmin.googleapis.com",
"networkmanagement.googleapis.com",
"servicenetworking.googleapis.com",
"redis.googleapis.com",
]
}

Expand Down Expand Up @@ -36,8 +38,9 @@ module "redis" {
source = "./modules/redis"
namespace = var.namespace

tier = var.redis_tier
memory_size_gb = var.redis_memory_size_gb
tier = var.redis_tier
memory_size_gb = var.redis_memory_size_gb
rdb_snapshot_period = var.redis_rdb_snapshot_period

network_id = module.networking.network_id
}
Expand Down
10 changes: 8 additions & 2 deletions modules/gke/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
data "google_client_config" "current" {}

locals {
project_id = data.google_client_config.current.project
}

resource "google_container_cluster" "this" {
name = "${var.namespace}-cluster"

Expand All @@ -8,8 +14,8 @@ resource "google_container_cluster" "this" {

deletion_protection = var.deletion_protection

node_config {
service_account = var.service_account_email
workload_identity_config {
workload_pool = "${local.project_id}.svc.id.goog"
}

release_channel {
Expand Down
9 changes: 8 additions & 1 deletion modules/redis/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,12 @@ resource "google_redis_instance" "this" {

auth_enabled = true

transit_encryption_mode = "SERVER_AUTHENTICATION"
redis_configs = {
maxmemory-policy = "noeviction"
}

persistence_config {
persistence_mode = "RDB"
rdb_snapshot_period = var.rdb_snapshot_period
}
}
4 changes: 0 additions & 4 deletions modules/redis/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
output "redis_ca_cert" {
value = google_redis_instance.this.server_ca_certs[0].cert
}

output "redis_auth_string" {
value = google_redis_instance.this.auth_string
}
Expand Down
5 changes: 5 additions & 0 deletions modules/redis/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ variable "memory_size_gb" {
description = "The memory size for the Redis instance."
type = number
}

variable "rdb_snapshot_period" {
description = "The snapshot period for the Redis instance."
type = string
}
16 changes: 15 additions & 1 deletion modules/service_accounts/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,22 @@ locals {
project_id = data.google_client_config.current.project
}

resource "google_project_iam_member" "this" {
resource "google_project_iam_member" "cloudsql_client" {
project = local.project_id
role = "roles/cloudsql.client"
member = local.sa_member
}

resource "google_project_iam_member" "sa_creator" {
project = local.project_id
role = "roles/iam.serviceAccountCreator"
member = local.sa_member
}

resource "google_service_account_iam_binding" "this" {
service_account_id = google_service_account.this.id
role = "roles/iam.workloadIdentityUser"
members = [
"serviceAccount:${local.project_id}.svc.id.goog[default/ctrlplane-${var.namespace}-sa]"
]
}
5 changes: 0 additions & 5 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ output "database_instance_private_ip_address" {
description = "The private IP address of the database instance."
}

output "redis_ca_cert" {
value = module.redis.redis_ca_cert
description = "The CA certificate of the Redis instance."
}

output "redis_auth_string" {
value = module.redis.redis_auth_string
description = "The authentication string of the Redis instance."
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ variable "redis_memory_size_gb" {
default = 1
}

variable "redis_rdb_snapshot_period" {
description = "The snapshot period for the Redis instance."
type = string
default = "ONE_HOUR"
}

variable "deletion_protection" {
description = "Whether to enable deletion protection for the resources."
type = bool
Expand Down

0 comments on commit 13f383d

Please sign in to comment.