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.08k stars 981 forks source link

Using scaffold with a boilerplate which includes a dependency results in an error #3509

Closed gmaghera closed 2 weeks ago

gmaghera commented 3 weeks ago

Describe the bug

Inability to use a boilerplate dependency with terragrunt scaffold

Steps To Reproduce

Create a boilerplate template which includes a dependency.

For example:

variables:
  - name: EnableRootInclude
    description: Should include root module
    type: bool
    default: true

dependencies:
  - name: module
    template-url: ./base
    output-folder: "/tmp/base"

And then create a base directory at the same level, and populate it with a valid boilerplate.yml file and a _base.hcl file with some random text.

From another directory, test it out with boilerplate:

❯ boilerplate \
  --template-url ~/Desktop/template \
  --output-folder /tmp/tofu-module-full \
  --non-interactive
[boilerplate] 2024/10/21 17:53:27 Loading boilerplate config from /Users/gmaghera/Desktop/template/boilerplate.yml
[boilerplate] 2024/10/21 17:53:27 Loading boilerplate config from /Users/gmaghera/Desktop/template/boilerplate.yml
[boilerplate] 2024/10/21 17:53:27 Using default value for variable 'EnableRootInclude': true
[boilerplate] 2024/10/21 17:53:27 Processing dependency module, with template folder /Users/gmaghera/Desktop/template/base and output folder /tmp/base
[boilerplate] 2024/10/21 17:53:27 Loading boilerplate config from /Users/gmaghera/Desktop/template/boilerplate.yml
[boilerplate] 2024/10/21 17:53:27 Loading boilerplate config from /Users/gmaghera/Desktop/template/base/boilerplate.yml
[boilerplate] 2024/10/21 17:53:27 Processing templates in /Users/gmaghera/Desktop/template/base and outputting generated files to /tmp/base
[boilerplate] 2024/10/21 17:53:27 Skipping /Users/gmaghera/Desktop/template/base
[boilerplate] 2024/10/21 17:53:27 Skipping /Users/gmaghera/Desktop/template/base/boilerplate.yml
[boilerplate] 2024/10/21 17:53:27 Processing templates in /Users/gmaghera/Desktop/template and outputting generated files to /tmp/tofu-module-full
[boilerplate] 2024/10/21 17:53:27 Skipping /Users/gmaghera/Desktop/template
[boilerplate] 2024/10/21 17:53:27 Creating folder /tmp/tofu-module-full/base
[boilerplate] 2024/10/21 17:53:27 Copying /Users/gmaghera/Desktop/template/base/boilerplate.yml to /tmp/tofu-module-full/base/boilerplate.yml
[boilerplate] 2024/10/21 17:53:27 Skipping /Users/gmaghera/Desktop/template/boilerplate.yml

And now try to use that same boilerplate (including a dependency) from terragrunt scaffold:

> terragrunt scaffold git@gitlab.com:rivian/dc/platform/terraform-modules/s3//. ~/Desktop/template/boilerplate.yml

EnableRootInclude
Should include root module
[boilerplate] 2024/10/21 17:54:21 Using default value for variable 'EnableRootInclude': true
This boilerplate template has a dependency! Run boilerplate on dependency module with template folder ./base and output folder /tmp/base? (y/n) : y
[boilerplate] 2024/10/21 17:54:24 Processing dependency module, with template folder /var/folders/r6/rp90tb0x2sxcq2vhdkdr9c1h0000gp/T/template3836136150/base and output folder /tmp/base
[boilerplate] 2024/10/21 17:54:24 Loading boilerplate config from /var/folders/r6/rp90tb0x2sxcq2vhdkdr9c1h0000gp/T/template3836136150/boilerplate.yml
17:54:24.449 ERROR  Could not find boilerplate.yml in /var/folders/r6/rp90tb0x2sxcq2vhdkdr9c1h0000gp/T/template3836136150/base/boilerplate.yml and the missing-config-action flag is set to exit
17:54:24.449 ERROR  Unable to determine underlying exit code, so Terragrunt will exit with error code 1
// non-relevant

Expected behavior

Ability to use boilerplate dependencies, ideally. If not possible, it would be nice to state this in the docs.

Nice to haves

image

Versions

Additional context

Add any other context about the problem here.

gmaghera commented 2 weeks ago

After learning about using // in local paths supplied for template directory, from @denis256 via https://github.com/gruntwork-io/terragrunt/issues/3511#issuecomment-2433224791 -- I tried the same with a template that includes a dependency. And it worked!

Here is the command that worked, for others who may run into this:

boilerplate \
--template-url ~/Workspaces/boilerplate-template// \
--output-folder /tmp/tofu-module-full \
--non-interactive

Note the // in ~/Workspaces/boilerplate-template//.