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 973 forks source link

backend.tf and provider.tf are not generated #3014

Closed tnimni closed 2 months ago

tnimni commented 7 months ago

Describe the bug When running terragrunt apply the backend.tf and provider.tf are not generated in the folder this is my directory structure └── terraform ├── aws │   ├── rnd-account │   │   ├── data │   │   ├── eks │   │   └── vpc

i started with creating the VPC folder, when i first run from there, terragrunt create backend.tf and provider.tf in the folder i then created the eks folder and run from there, and the files wasn't created. the code it self run fine and i did see that these files are generated inside .terragrunt-cache folder.

as far as i understood from the quick guide https://terragrunt.gruntwork.io/docs/getting-started/quick-start/#keep-your-backend-configuration-dry the file should be created in the folder

also if i now delete the files backend.tf and provider.tf from vpc folder and run terragrunt apply again, they are not created

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

#Root hcl
remote_state {
  backend = "s3"
  generate = {
    path      = "backend.tf"
    if_exists = "overwrite_terragrunt"
  }
  config = {
    bucket = "REDUCTED"

    key = "${path_relative_to_include()}/terraform.tfstate"
    region         = "us-east-2"
    encrypt        = true
    dynamodb_table = "REDUCTED"
  }
}

generate "provider" {
  path = "provider.tf"
  if_exists = "overwrite_terragrunt"
  contents = <<EOF
provider "aws" {
  shared_config_files      = ["~/.aws/config"]
  shared_credentials_files = ["~/.aws/credentials"]
  version                  = "5.41.0"
}
EOF
}

#VPC hcl
include "root" {
  path = find_in_parent_folders()
}

dependency "data" {
  config_path = "../data"
}

dependencies {
    paths = ["../data"]
}

terraform {
    source = "tfr:///terraform-aws-modules/vpc/aws?version=5.6.0"
}
//removed the rest of the file

#EKS hcl
include "root" {
  path = find_in_parent_folders()
}

dependency "data" {
  config_path = "../data"
}

dependencies {
    paths = ["../data"]
}

terraform {
    source = "tfr:///terraform-aws-modules/eks/aws?version=20.8.3"
}
//removed the rest of the file

Expected behavior I expect the file to be created

Nice to have

Versions

Additional context Add any other context about the problem here.

denis256 commented 7 months ago

Hello, files are generated in .terragrunt-cache subdirectories, in the same location where terraform.source is cloned, it is generated in this directory to allow terraform to load generated files.

Simplified example in: https://github.com/denis256/terragrunt-tests/tree/master/issue-3014

$ find . -name "provider.tf"
./.terragrunt-cache/IapPHzXpaoeEizb1HIcjz5_Vofs/SnMEXfZEvz37We0nU3Gh7JoDfRI/modules/test-file/provider.tf

$ cat ./.terragrunt-cache/IapPHzXpaoeEizb1HIcjz5_Vofs/SnMEXfZEvz37We0nU3Gh7JoDfRI/modules/test-file/provider.tf
# Generated by Terragrunt. Sig: nIlQXj57tbuaRZEa
provider "aws" {
  shared_config_files      = ["~/.aws/config"]
  shared_credentials_files = ["~/.aws/credentials"]
  version                  = "5.41.0"
}
github-actions[bot] commented 2 months ago

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.