feat: add Redis Terraform module

main v1.0.0
RaviAnand Mohabir 2 years ago
commit 860a20f1ac

@ -0,0 +1,86 @@
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = "2.13.1"
}
}
}
locals {
app = "redis"
match_labels = {
"app.kubernetes.io/name" = "redis"
"app.kubernetes.io/instance" = "redis"
}
labels = merge(local.match_labels, var.labels)
}
resource "kubernetes_stateful_set" "redis" {
metadata {
name = var.stateful_set_name
namespace = var.namespace
labels = local.labels
}
spec {
selector {
match_labels = local.match_labels
}
service_name = local.app
template {
metadata {
labels = local.match_labels
}
spec {
container {
image = var.image_registry == "" ? "${var.image_repository}:${var.image_tag}" : "${var.image_registry}/${var.image_repository}:${var.image_tag}"
name = var.container_name
command = ["redis-server"]
env {
name = "master"
value = "true"
}
port {
name = "redis"
container_port = 6379
}
volume_mount {
name = "data"
mount_path = "/data"
}
}
}
}
volume_claim_template {
metadata {
name = "data"
}
spec {
access_modes = ["ReadWriteOnce"]
resources {
requests = {
storage = var.storage_size
}
}
storage_class_name = var.storage_class_name
}
}
}
}
resource "kubernetes_service" "redis" {
metadata {
name = var.service_name
namespace = var.namespace
}
spec {
port {
name = "redis"
port = 6379
target_port = "redis"
}
type = "ClusterIP"
selector = local.match_labels
}
}

@ -0,0 +1,4 @@
output "redis_namespace_host" {
description = "Hostname of the Redis service in the namespace"
value = "${kubernetes_service.redis.metadata.0.name}"
}

@ -0,0 +1,65 @@
variable "namespace" {
description = "Namespace to deploy Redis to"
type = string
default = "default"
}
variable "labels" {
description = "Labels to add to the Redis deployment"
type = map(any)
default = {}
}
variable "stateful_set_name" {
description = "Name of StatefulSet"
type = string
default = "redis"
}
variable "storage_size" {
description = "Storage size for StatefulSet PVC"
type = string
default = "5Gi"
}
variable "storage_class_name" {
description = "Storage class to use for StatefulSet PVCs"
type = string
default = ""
}
variable "image_registry" {
description = "Image registry, e.g. gcr.io, docker.io"
type = string
default = ""
}
variable "image_repository" {
description = "Image to start for this pod"
type = string
default = "redis"
}
variable "image_tag" {
description = "Image tag to use"
type = string
default = "7.0.4"
}
variable "container_name" {
description = "Name of the Redis container"
type = string
default = "redis"
}
variable "service_name" {
description = "Name of service to deploy"
type = string
default = "redis"
}
variable "service_type" {
description = "Type of service to deploy"
type = string
default = "ClusterIP"
}
Loading…
Cancel
Save