terragrunt icon indicating copy to clipboard operation
terragrunt copied to clipboard

Terragrunt converts absolute paths into relative paths that breaks functionality

Open SrinivasanSundaram-HO opened this issue 6 months ago • 1 comments

Describe the bug

Terragrunt converts absolute file paths into relative paths that breaks functionality.

Steps To Reproduce

# main.tf
variable "myabsolutepath"{
  type = string
}

output "varOut"{
  value = var.myabsolutepath
}
#terragrunt.hcl
inputs = {
  myabsolutepath = "/workspace/modules"
}

Running terragrunt plan results in:

.
.
.
10:04:07.731 STDOUT terraform: Changes to Outputs:
10:04:07.731 STDOUT terraform:   + varOut = "./modules" <== !! Converted to relative path
10:04:07.732 STDOUT terraform: You can apply this plan to save these new output values to the Terraform
10:04:07.732 STDOUT terraform: state, without changing any real infrastructure.
.
.
.

Running terraform plan results in:

Changes to Outputs:
  + varOut = "/workspace/modules" <== !! Renders correctly

You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure.
.
.
.

Note: In the above terragrunt.hcl if I remove the leading '/', it does not convert the string (and renders it as 'workspace/modules').

Expected behavior

I expect the absolute path preserved

Versions

terragrunt version v0.78.4 Terraform v1.12.0 Ubuntu 22.04.5 LTS

Additional context

This relative path breaks some local-exec provisioners inside the terraform as the meaning of the relative paths change at the time of terraform execution (as the current directory is different at the run time).

Please let me know if you need more information in this regard.

Thanks

SrinivasanSundaram-HO avatar May 16 '25 10:05 SrinivasanSundaram-HO

Maybe what you see in the logs is not the reality. Take a look in the statefile how the path is stored

try terragrunt run apply --all --log-show-abs-paths

this my also help https://github.com/gruntwork-io/terragrunt/issues/4255#issuecomment-2880948409 but that did not help for me. I was already using a absolute path. It was just converted to a relative path in the logs

mark854542 avatar May 16 '25 13:05 mark854542

hey @SrinivasanSundaram-HO

I was unable to reproduce your issue with the provided fixture.

# main.tf
variable "myabsolutepath"{
  type = string
}

output "varOut"{
  value = var.myabsolutepath
}

#terragrunt.hcl
inputs = {
  myabsolutepath = "/workspace/modules"
}

output from terragrunt plan

STDOUT terraform:   + varOut = "/workspace/modules"

Can you check if there are any extra files that could hold variables or ENV vars in your shell?

wakeful avatar Jun 20 '25 14:06 wakeful

i have the same problem. it looks like it is a terragrunt output problem (but i am not 100% sure). also the behavior is not consistent with different paths. my findings:

  • paths in nested objects or simple string variables can get replaced by relative path ../../../../../../../../../user/app/example.com/public
  • the path /usr/local/bin stays absolut
  • /etc/apt stays absolut
  • changing in the cache dir and running tofu directly leaves the path alone (data provided with test.auto.vars
  • the data in the state file and the data stored with the provider is correct (absulute path). also with terragrunt so i assume it is an output bug for paths the terragrunt files is located. being in a path /home/user/my-terragunt-project and running terragunt there while providing an absolut path starting with /home makes the path relative in the output. providing a different stating point like /var as variable content, leads to the correct output. but always the correct data is stored.

c33s avatar Jun 29 '25 22:06 c33s

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for raising this issue.

github-actions[bot] avatar Sep 28 '25 02:09 github-actions[bot]