Skip to content

Commit 8c97ac1

Browse files
Merge pull request #8 from samcre/feature/add-local-exec
Add variable to manage repo lifecycle within TF
2 parents ad8979a + b773508 commit 8c97ac1

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,21 @@ module jenkins {
8888
|------|---------|
8989
| terraform | >= 0.13 |
9090
| helm | >= 2.0 |
91+
| null | >= 3.0 |
9192

9293
## Providers
9394

9495
| Name | Version |
9596
|------|---------|
9697
| helm | >= 2.0 |
98+
| null | >= 3.0 |
9799

98100
## Inputs
99101

100102
| Name | Description | Type | Default | Required |
101103
|------|-------------|------|---------|:--------:|
102104
| app | an application to deploy | `map(any)` | n/a | yes |
105+
| manage\_repo | Whether Helm repo should be added, updated and removed during Terraform execution | `bool` | `false` | no |
103106
| namespace | namespace where to deploy an application | `string` | n/a | yes |
104107
| repository | Helm repository | `string` | n/a | yes |
105108
| repository\_config | repository configuration | `map(any)` | n/a | yes |

main.tf

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
resource "null_resource" "repo_add" {
2+
count = var.manage_repo ? 1 : 0
3+
4+
triggers = {
5+
always_run = "${timestamp()}"
6+
}
7+
8+
provisioner "local-exec" {
9+
command = "helm repo add ${var.app["chart"]} ${var.repository}"
10+
}
11+
}
12+
13+
resource "null_resource" "repo_update" {
14+
count = var.manage_repo ? 1 : 0
15+
16+
triggers = {
17+
always_run = "${timestamp()}"
18+
}
19+
20+
provisioner "local-exec" {
21+
command = "helm repo update ${var.app["chart"]}"
22+
}
23+
24+
depends_on = [
25+
resource.null_resource.repo_add[0]
26+
]
27+
}
28+
129
resource "helm_release" "this" {
230
count = var.app["deploy"] ? 1 : 0
331
namespace = var.namespace
@@ -49,4 +77,25 @@ resource "helm_release" "this" {
4977
value = item.value.value
5078
}
5179
}
80+
81+
depends_on = [
82+
resource.null_resource.repo_update
83+
]
84+
}
85+
86+
resource "null_resource" "repo_delete" {
87+
count = var.manage_repo ? 1 : 0
88+
89+
triggers = {
90+
always_run = "${timestamp()}"
91+
}
92+
93+
provisioner "local-exec" {
94+
command = "helm repo remove ${var.app["chart"]}"
95+
}
96+
97+
depends_on = [
98+
resource.null_resource.repo_add[0],
99+
resource.helm_release.this
100+
]
52101
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,9 @@ variable "repository" {
4242
description = "Helm repository"
4343
type = string
4444
}
45+
46+
variable "manage_repo" {
47+
description = "Whether Helm repo should be added, updated and removed during Terraform execution"
48+
default = false
49+
type = bool
50+
}

versions.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ terraform {
33

44
required_providers {
55
helm = ">= 2.0"
6+
null = ">= 3.0"
67
}
78
}

0 commit comments

Comments
 (0)