gruntwork-io / terragrunt

Terragrunt is a flexible orchestration tool that allows Infrastructure as Code written in OpenTofu/Terraform to scale.
https://terragrunt.gruntwork.io/
MIT License
8.04k stars 975 forks source link

Terragrunt run does not create local file in mac OS #3324

Closed skumble closed 2 months ago

skumble commented 2 months ago

Describe the bug

When i run the terragrunt apply for the below terraform code it does not create the file "foo.bar" in the path "../modules/cassandra/instance_creation/files/" instead i could find it in inside the ".terragrunt-cache"

Steps To Reproduce

Steps to reproduce the behavior, code snippets and examples which can be used to reproduce the issue.

resource "local_file" "foo" {
  content  = "foo! test test test"
  filename = "${path.module}/../modules/cassandra/instance_creation/files/foo.bar"
}

Expected behavior

The "foo.bar" file should be created when the terragrunt apply command is run

Nice to haves

$ cat .//spaces-live-infra-terragrunt/live/sandbox/us-gov-west-1/core-app-infra/managed-services/cassandra/.terragrunt-cache/LitHMSlLlB0uHHqYge-DouolS10/Fsd8cV2oG0EvjtpJIXo91yn-Pa0/modules/eks-services/modules/cassandra/instance_creation/files/foo.bar foo! test test test

Versions

Additional context

Add any other context about the problem here.

denis256 commented 2 months ago

Hello, this is by design (if terraform.source is defined), in .terragrunt-cache is downloaded terraform sources, generated files if required, and invoked Terraform

skumble commented 2 months ago

Hello, thanks for the response.

Any alternative method to achieve this "resource "local_file"" in terragrunt ?

yhakbar commented 2 months ago

Hey @skumble , it depends on what you're trying to do.

One simple way to do this is to use the get_terragrunt_dir function to construct a file path, then pass that into your modules as a variable.

e.g.

# terragrunt.hcl
inputs = {
  filename = "${get_terragrunt_dir()}/foo.bar"
}

# main.tf
variable "filename" {}

resource "local_file" "this" {
  filename = var.filename
  content  = "foo! test test test"
}
denis256 commented 2 months ago

Hi, can be used a couple of ideas:

skumble commented 2 months ago

https://github.com/gruntwork-io/terragrunt/issues/3324#issuecomment-2273294503 This helped. Thanks a lot @yhakbar yhakbar