I try to get relative pathes for helm charts. But first for explanation my structure:
Directory structure is like this:
├── helm-charts
│ └── selfmadehelmchart
└── terraform
└── dev
├── terragrunt.hcl
├── environments
│ └── foobar
│ └── terragrunt.hcl
├── environments_terragrunt
│ ├── helm_releases.tf
│ └── vars.tf
└── vpc
└── terragrunt.hcl
Following files are stripped to only the content needed for the question, real content is much more.
terraform/dev/environments/foobar/terragrunt.hcl looks like this:
inputs = {
helm_charts_path = "${get_terragrunt_dir()}/../../../../helm-charts"
}
terraform {
source = "../..//environments_terragrunt"
}
terraform/dev/environments_terragrunt/vars.tf looks like this:
variable "helm_charts_path" {
type = string
description = "where to find the helm charts"
}
terraform/dev/environments_terragrunt/helm_release.tf looks like this:
resource "helm_release" "selfmadehelmchart" {
chart = "${var.helm_charts_path}/selfmadehelmchart"
}
This works, terraform finds the helm charts and can apply it. The very annoying thing is, that it sets the absolute path (because i am using “get_terragrunt_dir”) in the state. And everytime someone else does terragrunt apply’s that path changes. So my terragrunt apply (or plan) tells me to change x resources only to change the path of the chart. Nothing else happens. It also still works, but sometimes it is hard to find out, if something really changes or only the path to the helm chart changes.
Is there any possibility how i can get relative pathes for the helm charts? The path_relative_ functions are only for the terraform {} section and a test with path_relative_from_include in the input section did not really work out well: It gives the path relative from the terragrunt.hcl file and not from the (caching) directory terragrunt creates for the terragrunt run.
Yes, docs tell to use get_terragrunt_dir, because you never know where the caching dir really is and how many path levels it may get (correct), but is there really no other chance?