Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terragrunt scaffold should only run hclfmt on updated folders instead of the working directory #3657

Open
tgeijg opened this issue Dec 13, 2024 · 1 comment
Labels
bug Something isn't working preserved Preserved issues never go stale

Comments

@tgeijg
Copy link

tgeijg commented Dec 13, 2024

Describe the enhancement

Currently when using terragrunt catalog and/or scaffold, the scaffold command runs a hclfmt on the working directory. This can subsequently end up touching far more files than just the ones that the scaffold command created. Ideally, the hclfmt is either made optional, or only runs against the terragrunt files that scaffold itself generated.

Additional context

It seems to me that the current assumption is that people would run scaffold from the directory they want to generate terragrunt files in. Given that assumption the idea of running the hclfmt on the working directory isn't a terrible one. However, terragrunt's own architecture proposal is to use a base/child structure. The easiest way I've found to have scaffold generate both a base and a child terragrunt file, is by running scaffold from the root of the repo (and have the user input the file paths for both directories). This is reasonably easy to achieve using boilerplate dependencies.

The biggest problem I'm facing is that running the terragrunt scaffold from the root of the directory will run the hclfmt against the entire repo, instead of just the two (or more) subfolders that the command itself created.

Example

The below boilerplate template essentially just created two dependencies in two folders, the path of which is required as user input.

variables:
  - name: sourceUrl
    description: Url for source module
    type: string
    default: ""

  - name: requiredVariables
    description: Required input variables for module
    type: list
    default: []

  - name: optionalVariables
    description: Optional input variables for module
    type: list
    default: []

  - name: baseFileName
    description: Name for the base terragrunt file WITHOUT file extension, e.g. "dynamodb". (NOT "terragrunt")
    type: string
    validations:
      - required
      - length-3-50

  - name: baseFilePath
    description: |-
      Path for the base file, e.g. "base/team/service/"
      DO NOT add a leading slash, DO add a trailing slash 
    type: string
    validations:
      - required
      - length-5-500

  - name: leafFilePath
    description: |-
      Path for the leaf file, e.g. "development/us-east-1/team/service/"
      DO NOT add a leading slash, DO add a trailing slash 
    type: string
    validations:
      - required
      - length-5-500

partials:
  - ../.boilerplate-files/boilerplate-partials/*.hcl

dependencies:
  - name: base
    template-url: ../.boilerplate-files/base-file
    output-folder: "{{ .baseFilePath }}"
  
  - name: leaf
    template-url: ../.boilerplate-files/leaf-file
    output-folder: "{{ .leafFilePath }}"

(dependency templates not included for brevity)

Technically you can run this from anywhere in the repo, but the most logical place to run the scaffold command for the above boilerplate template is the root of the repo. All files generated will be in subfolders, so running hclfmt against the entire working directory is not ideal, as it may touch a whole list of files which are not in any way related to the scaffold call.

@tgeijg tgeijg added the enhancement New feature or request label Dec 13, 2024
@yhakbar yhakbar added bug Something isn't working preserved Preserved issues never go stale and removed enhancement New feature or request labels Dec 20, 2024
@yhakbar
Copy link
Collaborator

yhakbar commented Dec 20, 2024

I would classify this as a bug. Scaffold shouldn't mysteriously format content it didn't generate. We'll look to address this in the new year.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working preserved Preserved issues never go stale
Projects
None yet
Development

No branches or pull requests

2 participants