Skip to content

Commit

Permalink
Merge pull request #9 from FriedCircuits/feature/Generic-Helm-Chart-M…
Browse files Browse the repository at this point in the history
…odule

Generic Helm Chart Module
  • Loading branch information
FriedCircuits authored Feb 16, 2022
2 parents 0df240f + c3c1ced commit 03ffce7
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 3 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Hodgepodge of Terraform modules.
* VM Clone (Create VMs from Templates (created by packer))

* K8S
* Get Join (Get join config from Kuberenetes control plane)
* K8s-At-Home (Deploy a chart from the k8s-at-home helm repo)
* Traefik Ingress (Creats Ingress CRDs for host based routing)
* Get Join - Get join config from Kuberenetes control plane
* K8s-At-Home - Deploy a chart from the k8s-at-home helm repo
* Traefik Ingress - Creats Ingress CRDs for host based routing
* Helm Chart - Deploy any helm chart
42 changes: 42 additions & 0 deletions modules/k8s/helm-chart/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
resource "kubernetes_namespace" "namespace" {
count = var.create_namespace ? 1 : 0
metadata {
name = var.namespace
}
}

locals {
values = yamlencode(
merge(var.persistence != {} ? tomap({
persistence = merge({
enabled = true
},
var.persistence)
}) : {}, var.ingress != {} ? tomap({
ingress = merge({
enabled = true
}, tomap({
annotations = var.ingress_annotations}),
var.ingress)
}) : {},
var.helm_envs,
var.helm_values
)
)
}

resource "helm_release" "k8s" {
repository = var.helm_repo
name = var.name
chart = var.chart
version = var.chart_version
namespace = var.namespace

values = [
local.values,
]

depends_on = [
kubernetes_namespace.namespace,
]
}
63 changes: 63 additions & 0 deletions modules/k8s/helm-chart/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
variable "chart_version" {
description = "The version of the helm chart to use. Note that this is different from the app/container version."
type = string
}

variable "create_namespace" {
description = "Create namespace or deploy to existing."
type = bool
default = true
}

variable "namespace" {
description = "Which Kubernetes Namespace to deploy the chart into."
type = string
default = "default"
}

variable "helm_repo" {
description = "Helm chart repo URL."
type = string
}

variable "name" {
description = "Name of chart deployment."
type = string
}

variable "chart" {
description = "Name of helm chart."
type = string
}

variable "persistence" {
description = "Configure persistence volume on this deployment."
type = any
default = {}
# Example
}

variable "ingress" {
description = "Configure ingress on this deployment."
type = any
default = {}
# Example
}

variable "ingress_annotations" {
description = "Configure ingress annotations on this deployment."
type = map(string)
default = {}
}

variable "helm_envs" {
description = "Map of envs for helm chart. Merged with timezone."
type = any
default = {}
}

variable "helm_values" {
description = "Additional helm values to pass in as a map. Timezone will be included already."
type = any
default = {}
}
18 changes: 18 additions & 0 deletions modules/k8s/helm-chart/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
terraform {
required_version = ">= 1.0"

required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = "~> 1.0"
}
helm = {
source = "hashicorp/helm"
version = "~> 2.0"
}
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}
}

0 comments on commit 03ffce7

Please sign in to comment.