Skip to content

Commit bac9a13

Browse files
committed
feat(helm): add helm template support
Signed-off-by: Frederic Leger <frederic@webofmars.com>
1 parent 67a5cff commit bac9a13

8 files changed

Lines changed: 216 additions & 0 deletions

File tree

k8s/helm-template/.tflint.hcl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
plugin "terraform" {
2+
enabled = true
3+
preset = "recommended"
4+
}

k8s/helm-template/.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
terraform 1.3.1

k8s/helm-template/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# helm template
2+
3+
Generates kubernetes YAML manifests through helm
4+
5+
<!-- BEGIN_TF_DOCS -->
6+
## Requirements
7+
8+
| Name | Version |
9+
|------|---------|
10+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.3 |
11+
| <a name="requirement_helm"></a> [helm](#requirement\_helm) | >= 2.17.0, < 3.0.0 |
12+
| <a name="requirement_time"></a> [time](#requirement\_time) | ~> 0.9.1 |
13+
14+
## Providers
15+
16+
| Name | Version |
17+
|------|---------|
18+
| <a name="provider_helm"></a> [helm](#provider\_helm) | >= 2.17.0, < 3.0.0 |
19+
| <a name="provider_time"></a> [time](#provider\_time) | ~> 0.9.1 |
20+
21+
## Modules
22+
23+
No modules.
24+
25+
## Resources
26+
27+
| Name | Type |
28+
|------|------|
29+
| [time_static.last_update](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/static) | resource |
30+
| [helm_template.main](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/data-sources/template) | data source |
31+
32+
## Inputs
33+
34+
| Name | Description | Type | Default | Required |
35+
|------|-------------|------|---------|:--------:|
36+
| <a name="input_atomic"></a> [atomic](#input\_atomic) | Atomic deployment | `bool` | `false` | no |
37+
| <a name="input_chart"></a> [chart](#input\_chart) | Chart to use for the current deployment | `string` | `""` | no |
38+
| <a name="input_chart_version"></a> [chart\_version](#input\_chart\_version) | Version of the chart to use for the current deployment | `string` | `""` | no |
39+
| <a name="input_create_namespace"></a> [create\_namespace](#input\_create\_namespace) | Create namespace | `bool` | `true` | no |
40+
| <a name="input_customer"></a> [customer](#input\_customer) | Customer for the current deployment | `string` | `""` | no |
41+
| <a name="input_kubeconfig_context"></a> [kubeconfig\_context](#input\_kubeconfig\_context) | Kubeconfig context to use for the current deployment | `string` | `null` | no |
42+
| <a name="input_kubeconfig_paths"></a> [kubeconfig\_paths](#input\_kubeconfig\_paths) | List of kubeconfig paths to use for the current deployment | `list(string)` | `[]` | no |
43+
| <a name="input_name"></a> [name](#input\_name) | The name of the helm release | `string` | n/a | yes |
44+
| <a name="input_namespace"></a> [namespace](#input\_namespace) | Namespace to use for the current deployment | `string` | `""` | no |
45+
| <a name="input_repository"></a> [repository](#input\_repository) | Repository to use for the current deployment | `string` | `""` | no |
46+
| <a name="input_sets"></a> [sets](#input\_sets) | List of sets to use for the current deployment | `list(map(string))` | `[]` | no |
47+
| <a name="input_tags"></a> [tags](#input\_tags) | Default tags to add to resources | `map(any)` | `{}` | no |
48+
| <a name="input_values"></a> [values](#input\_values) | List of values to use for the current deployment | `list(string)` | `[]` | no |
49+
| <a name="input_wait"></a> [wait](#input\_wait) | Wait for deployment to complete | `bool` | `true` | no |
50+
51+
## Outputs
52+
53+
| Name | Description |
54+
|------|-------------|
55+
| <a name="output_manifest"></a> [manifest](#output\_manifest) | Rendered Kubernetes manifests generated by Helm |
56+
| <a name="output_name"></a> [name](#output\_name) | The name of the helm release |
57+
| <a name="output_namespace"></a> [namespace](#output\_namespace) | The namespace of the helm release |
58+
<!-- END_TF_DOCS -->

k8s/helm-template/helm-template.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
data "helm_template" "main" {
2+
name = var.name
3+
repository = var.repository
4+
chart = var.chart
5+
version = var.chart_version
6+
namespace = var.namespace
7+
atomic = var.atomic
8+
create_namespace = var.create_namespace
9+
wait = var.wait
10+
11+
values = var.values
12+
13+
dynamic "set" {
14+
for_each = var.sets
15+
content {
16+
name = set.value["name"]
17+
value = set.value["value"]
18+
}
19+
}
20+
21+
}

k8s/helm-template/main.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
locals {
2+
# tflint-ignore: terraform_unused_declarations
3+
interpolated_tags = merge({
4+
"Name" = var.name,
5+
"Customer" = var.customer,
6+
"ManagedBy" = "Terraform",
7+
"LastModifiedAt" = time_static.last_update.rfc3339,
8+
},
9+
var.tags
10+
)
11+
}
12+
13+
resource "time_static" "last_update" {
14+
}

k8s/helm-template/outputs.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
output "name" {
2+
description = "The name of the helm release"
3+
value = data.helm_template.main.name
4+
}
5+
6+
output "namespace" {
7+
description = "The namespace of the helm release"
8+
value = data.helm_template.main.namespace
9+
}
10+
11+
output "manifest" {
12+
description = "Rendered Kubernetes manifests generated by Helm"
13+
sensitive = true
14+
value = data.helm_template.main.manifest
15+
}

k8s/helm-template/providers.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
terraform {
2+
required_version = "~> 1.3"
3+
required_providers {
4+
helm = {
5+
source = "hashicorp/helm",
6+
version = ">= 2.17.0, < 3.0.0"
7+
}
8+
time = {
9+
source = "hashicorp/time",
10+
version = "~> 0.9.1"
11+
}
12+
}
13+
}
14+
15+
provider "helm" {
16+
kubernetes {
17+
config_paths = var.kubeconfig_paths
18+
config_context = var.kubeconfig_context
19+
}
20+
}

k8s/helm-template/variables.tf

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
variable "name" {
2+
description = "The name of the helm release"
3+
type = string
4+
}
5+
6+
variable "customer" {
7+
description = "Customer for the current deployment"
8+
type = string
9+
default = ""
10+
}
11+
12+
variable "tags" {
13+
description = "Default tags to add to resources"
14+
type = map(any)
15+
default = {}
16+
}
17+
18+
# module specific variables
19+
variable "kubeconfig_paths" {
20+
description = "List of kubeconfig paths to use for the current deployment"
21+
type = list(string)
22+
default = []
23+
}
24+
25+
variable "kubeconfig_context" {
26+
description = "Kubeconfig context to use for the current deployment"
27+
type = string
28+
default = null
29+
}
30+
31+
variable "repository" {
32+
description = "Repository to use for the current deployment"
33+
type = string
34+
default = ""
35+
}
36+
37+
variable "chart" {
38+
description = "Chart to use for the current deployment"
39+
type = string
40+
default = ""
41+
}
42+
43+
variable "chart_version" {
44+
description = "Version of the chart to use for the current deployment"
45+
type = string
46+
default = ""
47+
}
48+
49+
variable "namespace" {
50+
description = "Namespace to use for the current deployment"
51+
type = string
52+
default = ""
53+
}
54+
55+
variable "sets" {
56+
description = "List of sets to use for the current deployment"
57+
type = list(map(string))
58+
default = []
59+
}
60+
61+
variable "values" {
62+
description = "List of values to use for the current deployment"
63+
type = list(string)
64+
default = []
65+
}
66+
67+
variable "atomic" {
68+
description = "Atomic deployment"
69+
type = bool
70+
default = false
71+
}
72+
73+
variable "create_namespace" {
74+
description = "Create namespace"
75+
type = bool
76+
default = true
77+
}
78+
79+
variable "wait" {
80+
description = "Wait for deployment to complete"
81+
type = bool
82+
default = true
83+
}

0 commit comments

Comments
 (0)