Skip to main content
Knowledge Base

How to configure terragrunt when terraform modules are in individual repos?

Answer

Dear all, I had a single terraform repo with all of the modules in there. but now I have started seperatring 'em inn their individual repos and terragrunt fails to run. Say, I have two modules, named: `tf-service-moda` and `tf-service-modb` as two seperate git repos and all of the terragrunt stuff in a diffrent repo, called: `tg-modules`. `modb` is dependent on `modb`. This is sample file-system: ``` . ├── services │   ├── tf-service-moda │   │   ├── file1.tf │   │   └── file2.tf │   └── tf-service-modb │   ├── file1.tf │   └── file2.tf └── tg-modules ├── global.yaml ├── moda │   ├── terragrunt.hcl │   └── variables.yaml └── modb ├── terragrunt.hcl └── variables.yaml ``` Below are the sample config files.... #### global.yaml: ``` --- module_branch: master tf_repo_pfx: "https://git-codecommit.us-west-2.amazonaws.com/v1/repos/tf-service" ``` #### moda/terragrunt.hcl: ``` include { path = find_in_parent_folders() } locals { module_name = "moda" values = merge( yamldecode(file(find_in_parent_folders("global.yaml"))), yamldecode(file("variables.yaml")), ) } inputs = merge( local.values, ) terraform { source = "${local.values.tf_repo_pfx}-${local.module_name}?ref=${local.values.module_branch}" } ``` #### modb/terragrunt.hcl: ``` include { path = find_in_parent_folders() } locals { module_name = "modb" values = merge( yamldecode(file(find_in_parent_folders("global.yaml"))), yamldecode(file("variables.yaml")), ) } dependency "moda" { config_path = "../moda" } dependencies { paths = ["../moda"] } terraform { source = "${local.values.tf_repo_pfx}-${local.module_name}?ref=${local.values.module_branch}" } ``` with this, if I run terragrunt with ~~--terragrunt-source /repos/services//modb~~ `-terragrunt-source /repos/services//tf-service-modb` all work okay but fit I do just `terragrunt plan` to let it downloaded directly from git, it fails with this: ``` Santanu Dasd83436b64af6142517947f0b26bb5772d0ab810bWARN[0000] No double-slash (//) found in source URL /v1/repos/tf-service-moda. Relative paths in downloaded Terraform code may not work. prefix=[/home/santanu/repos/tg-modules/moda] ERRO[0001] 1 error occurred: * bad response code: 401 ERRO[0001] Unable to determine underlying exit code, so Terragrunt will exit with error code 1 ``` How do I fix this? What am I missing here? really appreciate any help. -S --- <ins datetime="2023-03-27T19:03:50Z"> <p><a href="https://support.gruntwork.io/hc/requests/110029">Tracked in ticket #110029</a></p> </ins>

okay, finally figured out what was overlooked: The value for `tf_repo_pfx` MUST be prefixed with `git::`, for Terraform to process arbitrary Git repositories ``` tf_repo_pfx: "git::https://github.com/dsantanu/tf-sample" ``` The above repo works just fine, if `tf_repo_pfx`(in global.yaml) is updated with `git::` prefix.