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

Scaffold appears broken using exact call from docs, leveraging external template. #3511

Closed gmaghera closed 3 weeks ago

gmaghera commented 3 weeks ago

Describe the bug

The exact use case stated in Terragrunt docs for scaffold using external template fails to run successfully.

Steps To Reproduce

  1. Navigate to the current https://terragrunt.gruntwork.io/docs/features/scaffold/#examples (https://github.com/gruntwork-io/terragrunt/blob/d91f921282ff3427313f49e75aa4e1d061cfe518/docs/_docs/02_features/scaffold.md?plain=1#L129 for posterity), and locate this example:

terragrunt scaffold github.com/gruntwork-io/terragrunt.git//test/fixtures/inputs git@github.com/gruntwork-io/terragrunt.git//test/fixtures/scaffold/external-template

  1. Run the example
❯ terragrunt scaffold github.com/gruntwork-io/terragrunt.git//test/fixtures/inputs git@github.com/gruntwork-io/terragrunt.git//test/fixtures/scaffold/external-template
09:03:31.590 WARN   The working directory . is not empty.
09:03:32.137 INFO   Scaffolding a new Terragrunt module git::https://github.com/gruntwork-io/terragrunt.git//test/fixtures/inputs?ref=v0.68.5-beta2024102101 to .
fatal: '/var/folders/r6/rp90tb0x2sxcq2vhdkdr9c1h0000gp/T/scaffold907025682/git@github.com/gruntwork-io/terragrunt.git' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
09:03:48.737 WARN   Failed to execute git ls-remote --tags file:///var/folders/r6/rp90tb0x2sxcq2vhdkdr9c1h0000gp/T/scaffold907025682/git@github.com/gruntwork-io/terragrunt.git in .

fatal: '/var/folders/r6/rp90tb0x2sxcq2vhdkdr9c1h0000gp/T/scaffold907025682/git@github.com/gruntwork-io/terragrunt.git' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

exit status 128
09:03:48.737 WARN   Failed to find last release tag for URL file:///var/folders/r6/rp90tb0x2sxcq2vhdkdr9c1h0000gp/T/scaffold907025682/git@github.com/gruntwork-io/terragrunt.git, so will not add a ref param to the URL
09:03:48.737 INFO   Using template from file:///var/folders/r6/rp90tb0x2sxcq2vhdkdr9c1h0000gp/T/scaffold907025682/git@github.com/gruntwork-io/terragrunt.git//test/fixtures/scaffold/external-template
09:03:48.808 ERROR  stat /var/folders/r6/rp90tb0x2sxcq2vhdkdr9c1h0000gp/T/scaffold907025682/git@github.com/gruntwork-io/terragrunt.git: no such file or directory
09:03:48.808 ERROR  Unable to determine underlying exit code, so Terragrunt will exit with error code 1

Expected behavior

As stated by the docs, "Scaffold new project using external template:" ... "# will be created: external-template.txt terragrunt.hcl , files from external template".

Nice to haves

image

Versions

denis256 commented 3 weeks ago

Hello, should be:

terragrunt scaffold github.com/gruntwork-io/terragrunt.git//test/fixtures/inputs git@github.com:gruntwork-io/terragrunt.git//test/fixtures/scaffold/external-template

I will update documentation

gmaghera commented 3 weeks ago

Thanks, @denis256!

That diff is so subtle, it took me a minute to see it.

gmaghera commented 3 weeks ago

@denis256 should this also work with local file paths? I've cloned the terragrunt repo and tried to give it the local directory instead:

❯ terragrunt scaffold github.com/gruntwork-io/terragrunt.git//test/fixtures/inputs /Users/gmaghera/Workspaces/terragrunt/test/fixtures/scaffold/external-template
08:34:01.547 WARN   The working directory . is not empty.
08:34:02.075 INFO   Scaffolding a new Terragrunt module git::https://github.com/gruntwork-io/terragrunt.git//test/fixtures/inputs?ref=v0.68.5-beta2024102101 to .
fatal: '/Users/gmaghera/Workspaces/terragrunt/test/fixtures/scaffold/external-template' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
08:35:14.842 WARN   Failed to execute git ls-remote --tags file://../../../../../../terragrunt/test/fixtures/scaffold/external-template in .

fatal: '../../../../../../terragrunt/test/fixtures/scaffold/external-template' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

exit status 128
08:35:14.842 WARN   Failed to find last release tag for URL file://../../../../../../terragrunt/test/fixtures/scaffold/external-template, so will not add a ref param to the URL
08:35:14.843 INFO   Using template from file://../../../../../../terragrunt/test/fixtures/scaffold/external-template
08:35:14.937 ERROR  error downloading 'file://../../../../../../terragrunt/test/fixtures/scaffold/external-template': destination exists and is not a symlink
08:35:14.937 ERROR  Unable to determine underlying exit code, so Terragrunt will exit with error code 1

This is what I tried initially, and it did not work, so I tried to use one of the examples from the docs. None of the examples in there show how to do this via file paths -- which I think would be really helpful for developing the custom boilerplate.

Do you have a trick for getting that to work?

denis256 commented 3 weeks ago

Hi, try to use // in local path

terragrunt scaffold github.com/gruntwork-io/terragrunt.git//test/fixtures/inputs /projects/gruntwork/terragrunt-tests/scaffold/local//external-template
$ terragrunt scaffold github.com/gruntwork-io/terragrunt.git//test/fixtures/inputs /projects/gruntwork/terragrunt-tests/scaffold/local//external-template
[INFO] Getting version from tgenv-version-name
[INFO] TGENV_VERSION is 0.68.4
19:07:18.082 INFO   Scaffolding a new Terragrunt module git::https://github.com/gruntwork-io/terragrunt.git//test/fixtures/inputs?ref=v0.68.5-beta2024102101 to .
fatal: '/projects/gruntwork/terragrunt-tests/scaffold/local' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
19:07:24.005 WARN   Failed to find last release tag for URL file:///projects/gruntwork/terragrunt-tests/scaffold/local, so will not add a ref param to the URL
19:07:24.006 INFO   Using template from file:///projects/gruntwork/terragrunt-tests/scaffold/local//external-template
19:07:24.007 INFO   Running boilerplate generation to .
[boilerplate] 2024/10/23 19:07:24 Loading boilerplate config from /tmp/template2649612922/boilerplate.yml
[boilerplate] 2024/10/23 19:07:24 Loading boilerplate config from /tmp/template2649612922/boilerplate.yml
[boilerplate] 2024/10/23 19:07:24 Processing templates in /tmp/template2649612922 and outputting generated files to /projects/gruntwork/terragrunt-tests/scaffold/local/temp
[boilerplate] 2024/10/23 19:07:24 Skipping /tmp/template2649612922
[boilerplate] 2024/10/23 19:07:24 Skipping /tmp/template2649612922/boilerplate.yml
19:07:24.012 INFO   Running fmt on generated code .
19:07:24.012 INFO   Scaffolding completed
gmaghera commented 3 weeks ago

That works!

Thank you so much, @denis256.