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

output-folder flag for scaffold #3652

Open
platymatt opened this issue Dec 12, 2024 · 5 comments
Open

output-folder flag for scaffold #3652

platymatt opened this issue Dec 12, 2024 · 5 comments
Labels
contributions-requested Requesting contributions from the community enhancement New feature or request preserved Preserved issues never go stale

Comments

@platymatt
Copy link

platymatt commented Dec 12, 2024

Describe the enhancement

When using terragrunt scaffold it creates the terragrunt.hcl in your working directory. I would like to be able to specify an output directory with a flag or variable. My goal is to place the terragrunt.hcl within my nested folder structure with the scaffold command.

I have tried messing with the following boilerplate.yml below as well as adding a before: section that would change my current directory to one provided by the variables or use an after: section to move the produced file to the desired location and neither work.

variables:
  - name: Environment
    description: The environment for where to deploy this infrastucture.
    type: string
    default: dev
  - name: Region
    description: The region for where to deploy this infrastucture.
    type: string
    default: us-gov-west-1
  - name: Tenant
    description: The region for where to deploy this infrastucture.
    type: string
    default: common
  - name: Resource
    description: The region for where to deploy this infrastucture.
    type: string
    default: common
  - name: outPutFolder
    type: string
    default: "deployments/{{ .Environment }}}/{{ .Region }}/{{ .Tenant }}/{{ .Resource }}/"

Additional context

Add any other context about the enhancement here.

Things you might want to address include:

Alternatives I may have to consider is running a after: block with a script to create the directories and place the file where I want it to go. I haven't tried that yet. I've been looking for examples for this use case and haven't found any.

PoC (Proof of Concept)

No PoC available at this time.

RFC Not Needed

  • I'm unsure if this needs an RFC. The boilerplate tool allows for an --output-folder flag and requires it, but terragrunt scaffold doesn't allow the output-folder flag to be set.
@platymatt platymatt added the enhancement New feature or request label Dec 12, 2024
@yhakbar
Copy link
Collaborator

yhakbar commented Dec 12, 2024

Thanks for creating this @platymatt ,

This is a solid enhancement, and not one that would be terribly difficult, I don't think.

I'll mark it as contributions-requested, as it's not something we're looking to prioritize anytime soon, but I'll also mark it as preserved, as we will get to it eventually if the community doesn't first.

My preferred solution would be that scaffold uses an --output-folder flag so that users familiar with Boilerplate can guess the right flag without reading the docs.

This also adds an additional wrinkle that the catalog TUI doesn't offer a way to select where scaffolding will take place once a user decides to scaffold. It might be good to add an extra keybinding that lets a user do that. It might require integrating or building something like yazi to let someone interact with their filesystem to create the destination for the unit.

@yhakbar yhakbar added contributions-requested Requesting contributions from the community preserved Preserved issues never go stale labels Dec 12, 2024
@platymatt
Copy link
Author

@yhakbar would a workaround for this to make custom script that is called in a after: hook?

@yhakbar
Copy link
Collaborator

yhakbar commented Dec 13, 2024

@yhakbar would a workaround for this to make custom script that is called in a after: hook?

I'm not sure if that's the best workaround. I think some testing would be required. Personally, I would recommend that you look at actually implementing an --output-folder flag in scaffold. I gave you some guidance on the other issue, and I'm happy to help you make it happen.

@tgeijg
Copy link

tgeijg commented Dec 13, 2024

@platymatt You can achieve this currently by using boilerplate dependencies. There is then an issue with the fact that scaffold runs an hclfmt on the entire repo. I've created an issue for that here: #3657

(that also has an example boilerplate that should give you some idea on how that works)

@platymatt
Copy link
Author

platymatt commented Jan 6, 2025

@tgeijg I tried something using your example and didn't get desired results yet. Maybe it's because I'm using a mono-repo with both terragrunt-live and modules within the same repository.

Here is the boilerplate.yml

variables:
  - name: Environment
    order: 0
    description: The environment for where to deploy this infrastucture.
    type: string
    default: zone-c

  - name: MissionApp
    order: 1
    description: The mission app that is using this infrastructure, could be saocde or c1sercde.
    type: string
    validations:
      - required

  - name: Region
    order: 2
    description: The region for where to deploy this infrastucture.
    type: string
    default: us-gov-west-1

  - name: Tenant
    order: 3
    description: The region for where to deploy this infrastucture.
    type: string
    default: common

  - name: Resource
    order: 4
    description: The region for where to deploy this infrastucture.
    type: string
    validations:
      - required


  - name: baseFilePath
    order: 5
    description: |-
      DO NOT add a leading slash, DO add a trailing slash 
    type: string
    default: "deployments/{{ .Environment }}/{{ .MissionApp }}/{{ .Region }}/{{ .Tenant }}/{{ .Resource }}/"
    validations:
      - required
      - length-5-500

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

Here is my output if I don't input "y":

DO NOT add a leading slash, DO add a trailing slash 
? Please enter baseFilePath 
[boilerplate] 2025/01/06 20:25:12 Using default value for variable 'baseFilePath': deployments/{{ .Environment }}/{{ .MissionApp }}/{{ .Region }}/{{ .Tenant }}/{{ .Resource }}/
This boilerplate template has a dependency! Run boilerplate on dependency base with template folder ../.boilerplate and output folder {{ .baseFilePath }}? (y/n) : 
[boilerplate] 2025/01/06 20:25:13 Skipping dependency base
[boilerplate] 2025/01/06 20:25:13 Processing templates in /tmp/scaffold1746004980/.boilerplate and outputting generated files to /workspaces/c1p_pc
[boilerplate] 2025/01/06 20:25:13 Skipping /tmp/scaffold1746004980/.boilerplate
[boilerplate] 2025/01/06 20:25:13 Skipping /tmp/scaffold1746004980/.boilerplate/boilerplate.yml
INFO[0016] Running fmt on generated code /workspaces/c1p_pc
INFO[0016] /workspaces/c1p_pc/terragrunt.hcl was updated 
INFO[0016] Scaffolding completed   

Here is my output if I select "y" and it seems to loop which is odd:

aseFilePath
Path for the base file, e.g. "deployments/prod/saocde/us-gov-west-1/saoc/des"
DO NOT add a leading slash, DO add a trailing slash 
? Please enter baseFilePath 
[boilerplate] 2025/01/07 10:49:51 Using default value for variable 'baseFilePath': deployments/{{ .Environment }}/{{ .MissionApp }}/{{ .Region }}/{{ .Tenant }}/{{ .Resource }}/
This boilerplate template has a dependency! Run boilerplate on dependency base with template folder ../.boilerplate and output folder {{ .baseFilePath }}? (y/n) : y
[boilerplate] 2025/01/07 10:49:53 Processing dependency base, with template folder /tmp/scaffold2272186761/.boilerplate and output folder /workspaces/c1p_pc/deployments/zone-c/saocde/us-gov-west-1/common/test
[boilerplate] 2025/01/07 10:49:53 Loading boilerplate config from /tmp/scaffold2272186761/.boilerplate/boilerplate.yml
[boilerplate] 2025/01/07 10:49:53 Loading boilerplate config from /tmp/scaffold2272186761/.boilerplate/boilerplate.yml
This boilerplate template has a dependency! Run boilerplate on dependency base with template folder ../.boilerplate and output folder {{ .baseFilePath }}? (y/n) : y
[boilerplate] 2025/01/07 10:50:07 Processing dependency base, with template folder /tmp/scaffold2272186761/.boilerplate and output folder /workspaces/c1p_pc/deployments/zone-c/saocde/us-gov-west-1/common/test/deployments/zone-c/saocde/us-gov-west-1/common/test
[boilerplate] 2025/01/07 10:50:07 Loading boilerplate config from /tmp/scaffold2272186761/.boilerplate/boilerplate.yml
[boilerplate] 2025/01/07 10:50:07 Loading boilerplate config from /tmp/scaffold2272186761/.boilerplate/boilerplate.yml
This boilerplate template has a dependency! Run boilerplate on dependency base with template folder ../.boilerplate and output folder {{ .baseFilePath }}? (y/n) : y
[boilerplate] 2025/01/07 10:50:15 Processing dependency base, with template folder /tmp/scaffold2272186761/.boilerplate and output folder /workspaces/c1p_pc/deployments/zone-c/saocde/us-gov-west-1/common/test/deployments/zone-c/saocde/us-gov-west-1/common/test/deployments/zone-c/saocde/us-gov-west-1/common/test
[boilerplate] 2025/01/07 10:50:15 Loading boilerplate config from /tmp/scaffold2272186761/.boilerplate/boilerplate.yml
[boilerplate] 2025/01/07 10:50:15 Loading boilerplate config from /tmp/scaffold2272186761/.boilerplate/boilerplate.yml
This boilerplate template has a dependency! Run boilerplate on dependency base with template folder ../.boilerplate and output folder {{ .baseFilePath }}? (y/n) : y
[boilerplate] 2025/01/07 10:50:16 Processing dependency base, with template folder /tmp/scaffold2272186761/.boilerplate and output folder /workspaces/c1p_pc/deployments/zone-c/saocde/us-gov-west-1/common/test/deployments/zone-c/saocde/us-gov-west-1/common/test/deployments/zone-c/saocde/us-gov-west-1/common/test/deployments/zone-c/saocde/us-gov-west-1/common/test
[boilerplate] 2025/01/07 10:50:16 Loading boilerplate config from /tmp/scaffold2272186761/.boilerplate/boilerplate.yml
[boilerplate] 2025/01/07 10:50:16 Loading boilerplate config from /tmp/scaffold2272186761/.boilerplate/boilerplate.yml
This boilerplate template has a dependency! Run boilerplate on dependency base with template folder ../.boilerplate and output folder {{ .baseFilePath }}? (y/n) : n
[boilerplate] 2025/01/07 10:51:50 Skipping dependency base
[boilerplate] 2025/01/07 10:51:50 Processing templates in /tmp/scaffold2272186761/.boilerplate and outputting generated files to /workspaces/c1p_pc/deployments/zone-c/saocde/us-gov-west-1/common/test/deployments/zone-c/saocde/us-gov-west-1/common/test/deployments/zone-c/saocde/us-gov-west-1/common/test/deployments/zone-c/saocde/us-gov-west-1/common/test
[boilerplate] 2025/01/07 10:51:50 Skipping /tmp/scaffold2272186761/.boilerplate
[boilerplate] 2025/01/07 10:51:50 Skipping /tmp/scaffold2272186761/.boilerplate/boilerplate.yml
[boilerplate] 2025/01/07 10:51:50 Processing templates in /tmp/scaffold2272186761/.boilerplate and outputting generated files to /workspaces/c1p_pc/deployments/zone-c/saocde/us-gov-west-1/common/test/deployments/zone-c/saocde/us-gov-west-1/common/test/deployments/zone-c/saocde/us-gov-west-1/common/test
[boilerplate] 2025/01/07 10:51:50 Skipping /tmp/scaffold2272186761/.boilerplate
[boilerplate] 2025/01/07 10:51:50 Skipping /tmp/scaffold2272186761/.boilerplate/boilerplate.yml
[boilerplate] 2025/01/07 10:51:50 Processing templates in /tmp/scaffold2272186761/.boilerplate and outputting generated files to /workspaces/c1p_pc/deployments/zone-c/saocde/us-gov-west-1/common/test/deployments/zone-c/saocde/us-gov-west-1/common/test
[boilerplate] 2025/01/07 10:51:50 Skipping /tmp/scaffold2272186761/.boilerplate
[boilerplate] 2025/01/07 10:51:50 Skipping /tmp/scaffold2272186761/.boilerplate/boilerplate.yml
[boilerplate] 2025/01/07 10:51:50 Processing templates in /tmp/scaffold2272186761/.boilerplate and outputting generated files to /workspaces/c1p_pc/deployments/zone-c/saocde/us-gov-west-1/common/test
[boilerplate] 2025/01/07 10:51:50 Skipping /tmp/scaffold2272186761/.boilerplate
[boilerplate] 2025/01/07 10:51:50 Skipping /tmp/scaffold2272186761/.boilerplate/boilerplate.yml
[boilerplate] 2025/01/07 10:51:50 Processing templates in /tmp/scaffold2272186761/.boilerplate and outputting generated files to /workspaces/c1p_pc
[boilerplate] 2025/01/07 10:51:50 Skipping /tmp/scaffold2272186761/.boilerplate
[boilerplate] 2025/01/07 10:51:50 Skipping /tmp/scaffold2272186761/.boilerplate/boilerplate.yml
INFO[0172] Running fmt on generated code /workspaces/c1p_pc 
INFO[0172] /workspaces/c1p_pc/terragrunt.hcl was updated 
INFO[0172] /workspaces/c1p_pc/deployments/zone-c/saocde/us-gov-west-1/common/test/terragrunt.hcl was updated 
INFO[0172] /workspaces/c1p_pc/deployments/zone-c/saocde/us-gov-west-1/common/test/deployments/zone-c/saocde/us-gov-west-1/common/test/terragrunt.hcl was updated 
INFO[0172] /workspaces/c1p_pc/deployments/zone-c/saocde/us-gov-west-1/common/test/deployments/zone-c/saocde/us-gov-west-1/common/test/deployments/zone-c/saocde/us-gov-west-1/common/test/terragrunt.hcl was updated 
INFO[0172] /workspaces/c1p_pc/deployments/zone-c/saocde/us-gov-west-1/common/test/deployments/zone-c/saocde/us-gov-west-1/common/test/deployments/zone-c/saocde/us-gov-west-1/common/test/deployments/zone-c/saocde/us-gov-west-1/common/test/terragrunt.hcl was updated 
INFO[0172] Scaffolding completed                        

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributions-requested Requesting contributions from the community enhancement New feature or request preserved Preserved issues never go stale
Projects
None yet
Development

No branches or pull requests

3 participants