terragrunt icon indicating copy to clipboard operation
terragrunt copied to clipboard

backend.tf and provider.tf are not generated

Open tnimni opened this issue 11 months ago • 1 comments

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

  • [ ] Terminal output
  • [ ] Screenshots

Versions

  • Terragrunt version: terragrunt version 0.55.16
  • Terraform version: Terraform v1.7.4 on darwin_arm64
  • Environment details (Ubuntu 20.04, Windows 10, etc.): mac Apple M1 Pro

Additional context Add any other context about the problem here.

tnimni avatar Mar 20 '24 15:03 tnimni

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"
}

denis256 avatar Mar 21 '24 14:03 denis256

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 Aug 13 '24 01:08 github-actions[bot]