Relative path for helm charts with terragrunt

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?

Unfortunately, there isn’t going to be a clean solution here precisely because of what the docs highlight. Relative paths are going to be messy because you are effectively tying your implementation to the internals of terragrunt and how it unpacks the terraform modules.

The only alternative I can think of is to use before_hooks to move the helm chart to a consistent known absolute path, like /tmp/charts and pass that path to terraform. That way, it is not tied to where the repo is checked out. This has its own downsides (e.g., you have a copy of all the charts somewhere you might not be looking/managing closely, you might not have permissions to write to that path, etc), but at least should avoid the diff problem.

Hope this helps!
Yori

Sorry for the very belated reply:
Your proposal helped a lot: I now have a working solution, which implements, what i wanted to achieve.
I did not use /tmp/charts, because i can not be 100% sure, that it is really available for everyone. I rather choosed a relative path which works inside the copied cache directory. It works like a charm locally and on our CI.
Thanks a lot yoriy! :+1: :+1: :+1:

Great to hear you got something working! Thanks for closing the loop.