I am using terraform with helm provider to deploy a helm chart, everything works with terraform, the problem is when the application is already running and I changed the image tag from the gitlab pipeline.
So the next time that I run terraform the image tag deployed from gitlab will be change to the previous one.
I tried to use lifecycle, this is my terraform code:
resource "helm_release" "app1" {
name = "app1"
namespace = "money"
chart = "stable/perl"
set {
name = "image.repository"
value = "docker.registry.local/app1-api"
}
set {
name = "replicaCount"
value = "2"
}
set {
name = "image.tag"
value = "1.0.1"
}
set {
name = "image.pullPolicy"
value = "Always"
}
set {
name = "service.type"
value = "ClusterIP"
}
lifecycle {
ignore_changes = [for s in set : s.name if s.name == "image.tag"]
}
}
terraform apply:
A static list expression is required.
Specifically for the Helm resource, you can trick Terraform into ignoring all objects of the same "type", meaning you can use one of the three objects (
set
,set_sensitive
,set_string
) inside thelifecycle
and ignore them all.Is this ideal? Of course not, but it does work. The root cause for the why objects are not addressable is here.
In your example, it would be something like this:
Edit: Please note that
ignore_changes
is quite literal, since any update will enforce the old value to replace whatever is currently configured in Helm.Example: Terraform has the initial tag configured and the initial
replicaCount == 2
. Then the CI/CD system does its things and update the tag. Now, if you were to use Terraform to changereplicaCount
the initial tag would be re-applied since it's the one Terraform knows about...