terraform-arm-k8s-core is a Terraform module that deploys core Kubernetes platform services on an existing Kubernetes cluster (AKS or bare metal) using Helm and Kubernetes manifests.
It integrates with Azure Storage remote state to read cluster/network inputs (DNS, public IP, cluster metadata) and then installs and configures a set of operational components such as:
- cert-manager (with optional Let’s Encrypt issuer/certificates)
- ingress-nginx
- kube-prometheus-stack (Prometheus + Grafana, etc.)
- Loki stack
- HashiCorp Vault (with automated init/unseal + optional scheduled re-unseal)
- Velero backup
- StorageClass provisioning helper (Azure disk/file)
The repository also includes helper shell scripts to initialize Terraform backend, plan/apply, and export Terraform outputs as environment variables.
flowchart TD
A[terraform apply] --> RS1[remote state: core_ip_dns]
A --> RS2[remote state: core_infra]
A --> M1[module deploy-storageclass]
M1 --> SC[create-storageclass: StorageClass resources]
A --> M2[module create-prometheus-stack]
M2 --> PROM[create-prometheus-stack: kube-prometheus-stack Helm release]
A --> M3[module deploy-pvc-prometheus-stack]
M3 --> PVCG[persistence-claim-prometheus-stack: Grafana PVC]
A --> M4[module loki]
M4 --> LOKI[create-loki: Loki stack Helm release]
A --> M5[module deploy-pvc-loki-stack]
M5 --> PVCL[persistence-claim-loki-stack: Loki PVC]
A --> M6[module create-ingress-nginx]
M6 --> NGINX[create-ingress-nginx: ingress-nginx Helm release]
A --> M7[module cert-manager]
M7 --> CM[create-cert-manager: cert-manager + issuer + certificate]
A --> M8[module create_vault]
M8 --> VAULT[create_vault: Vault Helm release + init/unseal jobs]
A --> M9[module deploy_velero]
M9 --> VELERO[create_velero: Velero Helm release]
A --> OUT[output rendered: summary.tpl.md]
- Deploys Kubernetes “core services” via Terraform + Helm
- Supports multiple optional components toggled by Terraform booleans
- Supports both “bare metal” and “Azure” (AKS) modes for some charts/templates
- TLS options:
let_s_encrypt: installs cert-manager and creates ClusterIssuer/Certificate resourcescustom: creates a Kubernetes TLS secret from provided cert/key contentnone: no cert/issuer creation
- Generates a human-readable summary (
summary.tpl.md) via Terraformtemplate_file - Vault automation:
- init + unseal job that stores unseal keys + root token in a Kubernetes Secret
- optional CronJob to re-unseal after scheduled cluster restarts
- optional “enable auth” job (script-based)
- Terraform
>= 1.13.0 - Terraform providers:
hashicorp/kubernetes2.38.0hashicorp/helm2.17.0alekc/kubectl2.1.3hashicorp/template2.2.0
- Azure backend: Terraform
azurermbackend (remote state in Azure Storage) - Shell tooling (helper scripts):
bash/sh - External CLIs used by scripts:
terraformaz(Azure CLI)
main.tf: reads remote state (core_ip_dns,core_infra) and renders the summary templatemodules.*.tf: wires submodules for each component (cert-manager, nginx, loki, prometheus, vault, velero, storageclass)providers.tf: provider versions + provider configuration (uses~/.kube/config)variables.*.tf: input variables grouped by componentoutputs.tf: outputsrenderedsummary contentsummary.tpl.md: Markdown template rendered with values from remote states and module variablesterraform.tfvars,terraform.auto.tfvars: example/default variable values
create-cert-manager/: Helm release + ClusterIssuer/Certificate manifests + optional TLS secretcreate-ingress-nginx/: ingress-nginx Helm chart with Azure/bare-metal valuescreate-prometheus-stack/: kube-prometheus-stack Helm chartpersistence-claim-prometheus-stack/: PVC deployment for Grafana storagecreate-loki/: Loki stack Helm chart + optional bare-metal PV/PVC conceptspersistence-claim-loki-stack/: PVC deployment for Loki stackcreate_vault/: Vault Helm chart + RBAC + init/unseal jobs + optional cron unseal + enable auth jobcreate_velero/: Velero Helm chart configuration for Azurecreate-storageclass/: StorageClass provisioning helper (Azure disk/file provisioners)
_run-terraform.sh: convenience wrapper (init + plan; apply is commented)_run-init.sh: initializes Terraform backend (Azure Storage) and exports access key_run-plan.sh: runsterraform plan -out=tfplan -var-file=..._run-apply.sh: runsterraform apply tfplan_export_tfvars.sh: exports Terraform outputs asTF_VAR_*environment variables
- Terraform
>= 1.13.0 - Azure CLI (
az) authenticated with rights to read the Terraform backend storage account keys - Access to the target Kubernetes cluster via
~/.kube/config(this repo’s providers useconfig_path = "~/.kube/config")
This repository is configured to use the azurerm backend (see providers.tf).
The helper script _run-init.sh expects a “state key” argument and uses fixed backend names:
- Resource group:
cosmotechstates - Storage account:
cosmotechstates - Container:
cosmotechstates
If your backend differs, update _run-init.sh accordingly.
- Create or edit your variable file (
terraform.tfvarsor another*.tfvars). - Initialize the backend.
- Plan and apply.
This repo provides scripts that encode that flow:
./_run-init.sh <state_key>
./_run-plan.sh <var-file>
./_run-apply.shOr, simply run the _run-terraform.sh script to execute all three steps (init, plan, apply) in sequence. The script will stop if any step fails.
./_run-terraform.shThe root module renders summary.tpl.md through data.template_file.example and exposes it via:
output "rendered"inoutputs.tf
See LICENSE.
Made with ❤️ by Cosmo Tech DevOps team