diff --git a/k8s/helm-template/.tflint.hcl b/k8s/helm-template/.tflint.hcl new file mode 100644 index 0000000..427121c --- /dev/null +++ b/k8s/helm-template/.tflint.hcl @@ -0,0 +1,4 @@ +plugin "terraform" { + enabled = true + preset = "recommended" +} diff --git a/k8s/helm-template/.tool-versions b/k8s/helm-template/.tool-versions new file mode 100644 index 0000000..843e1f5 --- /dev/null +++ b/k8s/helm-template/.tool-versions @@ -0,0 +1 @@ +terraform 1.3.1 diff --git a/k8s/helm-template/README.md b/k8s/helm-template/README.md new file mode 100644 index 0000000..e020215 --- /dev/null +++ b/k8s/helm-template/README.md @@ -0,0 +1,58 @@ +# helm template + +Generates kubernetes YAML manifests through helm + + +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | ~> 1.3 | +| [helm](#requirement\_helm) | >= 2.17.0, < 3.0.0 | +| [time](#requirement\_time) | ~> 0.9.1 | + +## Providers + +| Name | Version | +|------|---------| +| [helm](#provider\_helm) | >= 2.17.0, < 3.0.0 | +| [time](#provider\_time) | ~> 0.9.1 | + +## Modules + +No modules. + +## Resources + +| Name | Type | +|------|------| +| [time_static.last_update](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/static) | resource | +| [helm_template.main](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/data-sources/template) | data source | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [atomic](#input\_atomic) | Atomic deployment | `bool` | `false` | no | +| [chart](#input\_chart) | Chart to use for the current deployment | `string` | `""` | no | +| [chart\_version](#input\_chart\_version) | Version of the chart to use for the current deployment | `string` | `""` | no | +| [create\_namespace](#input\_create\_namespace) | Create namespace | `bool` | `true` | no | +| [customer](#input\_customer) | Customer for the current deployment | `string` | `""` | no | +| [kubeconfig\_context](#input\_kubeconfig\_context) | Kubeconfig context to use for the current deployment | `string` | `null` | no | +| [kubeconfig\_paths](#input\_kubeconfig\_paths) | List of kubeconfig paths to use for the current deployment | `list(string)` | `[]` | no | +| [name](#input\_name) | The name of the helm release | `string` | n/a | yes | +| [namespace](#input\_namespace) | Namespace to use for the current deployment | `string` | `""` | no | +| [repository](#input\_repository) | Repository to use for the current deployment | `string` | `""` | no | +| [sets](#input\_sets) | List of sets to use for the current deployment | `list(map(string))` | `[]` | no | +| [tags](#input\_tags) | Default tags to add to resources | `map(any)` | `{}` | no | +| [values](#input\_values) | List of values to use for the current deployment | `list(string)` | `[]` | no | +| [wait](#input\_wait) | Wait for deployment to complete | `bool` | `true` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| [manifest](#output\_manifest) | Rendered Kubernetes manifests generated by Helm | +| [name](#output\_name) | The name of the helm release | +| [namespace](#output\_namespace) | The namespace of the helm release | + diff --git a/k8s/helm-template/helm-template.tf b/k8s/helm-template/helm-template.tf new file mode 100644 index 0000000..75a49fc --- /dev/null +++ b/k8s/helm-template/helm-template.tf @@ -0,0 +1,21 @@ +data "helm_template" "main" { + name = var.name + repository = var.repository + chart = var.chart + version = var.chart_version + namespace = var.namespace + atomic = var.atomic + create_namespace = var.create_namespace + wait = var.wait + + values = var.values + + dynamic "set" { + for_each = var.sets + content { + name = set.value["name"] + value = set.value["value"] + } + } + +} diff --git a/k8s/helm-template/main.tf b/k8s/helm-template/main.tf new file mode 100644 index 0000000..b5f8ba8 --- /dev/null +++ b/k8s/helm-template/main.tf @@ -0,0 +1,14 @@ +locals { + # tflint-ignore: terraform_unused_declarations + interpolated_tags = merge({ + "Name" = var.name, + "Customer" = var.customer, + "ManagedBy" = "Terraform", + "LastModifiedAt" = time_static.last_update.rfc3339, + }, + var.tags + ) +} + +resource "time_static" "last_update" { +} diff --git a/k8s/helm-template/outputs.tf b/k8s/helm-template/outputs.tf new file mode 100644 index 0000000..2967185 --- /dev/null +++ b/k8s/helm-template/outputs.tf @@ -0,0 +1,15 @@ +output "name" { + description = "The name of the helm release" + value = data.helm_template.main.name +} + +output "namespace" { + description = "The namespace of the helm release" + value = data.helm_template.main.namespace +} + +output "manifest" { + description = "Rendered Kubernetes manifests generated by Helm" + sensitive = true + value = data.helm_template.main.manifest +} diff --git a/k8s/helm-template/providers.tf b/k8s/helm-template/providers.tf new file mode 100644 index 0000000..2317337 --- /dev/null +++ b/k8s/helm-template/providers.tf @@ -0,0 +1,20 @@ +terraform { + required_version = "~> 1.3" + required_providers { + helm = { + source = "hashicorp/helm", + version = ">= 2.17.0, < 3.0.0" + } + time = { + source = "hashicorp/time", + version = "~> 0.9.1" + } + } +} + +provider "helm" { + kubernetes { + config_paths = var.kubeconfig_paths + config_context = var.kubeconfig_context + } +} diff --git a/k8s/helm-template/variables.tf b/k8s/helm-template/variables.tf new file mode 100644 index 0000000..6d69cac --- /dev/null +++ b/k8s/helm-template/variables.tf @@ -0,0 +1,83 @@ +variable "name" { + description = "The name of the helm release" + type = string +} + +variable "customer" { + description = "Customer for the current deployment" + type = string + default = "" +} + +variable "tags" { + description = "Default tags to add to resources" + type = map(any) + default = {} +} + +# module specific variables +variable "kubeconfig_paths" { + description = "List of kubeconfig paths to use for the current deployment" + type = list(string) + default = [] +} + +variable "kubeconfig_context" { + description = "Kubeconfig context to use for the current deployment" + type = string + default = null +} + +variable "repository" { + description = "Repository to use for the current deployment" + type = string + default = "" +} + +variable "chart" { + description = "Chart to use for the current deployment" + type = string + default = "" +} + +variable "chart_version" { + description = "Version of the chart to use for the current deployment" + type = string + default = "" +} + +variable "namespace" { + description = "Namespace to use for the current deployment" + type = string + default = "" +} + +variable "sets" { + description = "List of sets to use for the current deployment" + type = list(map(string)) + default = [] +} + +variable "values" { + description = "List of values to use for the current deployment" + type = list(string) + default = [] +} + +variable "atomic" { + description = "Atomic deployment" + type = bool + default = false +} + +variable "create_namespace" { + description = "Create namespace" + type = bool + default = true +} + +variable "wait" { + description = "Wait for deployment to complete" + type = bool + default = true +}