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

Feature request: optionally allow empty files to be generated #136

Open
izeau opened this issue May 12, 2024 · 3 comments
Open

Feature request: optionally allow empty files to be generated #136

izeau opened this issue May 12, 2024 · 3 comments

Comments

@izeau
Copy link

izeau commented May 12, 2024

Hi there :)

I am planning on using Scaffold to generate Terraform modules boilerplate. Hashicorps recommends using a standard layout with well-known file paths that should be used even if they're empty (main.tf, variables.tf, outputs.tf). This is not a hard requirement though, as Terraform itself does not care -- it's just a convention.

Currently (v0.0.91), an empty render will result in ErrTemplateIsEmpty, which is ignored but prevents the file from being written to (as specified in the docs). While I fully understand this behavior, I would like to be able to optionally bypass this check at the scaffold level. Now the issue as far as I can tell would be introducing options in the scaffold.yaml file, which you might want to avoid to prevent feature creep.

Thank you for your work, and for your time :)

@hay-kot
Copy link
Owner

hay-kot commented May 12, 2024

Will definitely need to think about this some more. I know I've been wanting to make some changes that could possibly break some scaffolds, so having some way to opt-into behavior may be necessary.

In the mean time, adding comments to the files so they always have content or if they aren't templates, adding them to the skip list would always copy them (I think)

@izeau
Copy link
Author

izeau commented May 12, 2024

Adding Terraform comments is what I have been doing in the meantime.

By the way, there is a strange output if the template only contains only gotemplate comment and whitespace (e.g if it's only {{/* ... */}}): the resulting file contains its own path.

.scaffold/terraform-module/scaffold.yaml
questions:
  - name: module_name
    required: true
    prompt:
      message: name

computed:
  module_dir: "infrastructure/modules/terraform-aws-{{ .Scaffold.module_name }}"

rewrites:
  - from: templates/main.tf
    to: "{{ .Computed.module_dir }}/main.tf"
.scaffold/terraform-module/templates/main.tf
{{/* test */}}
infrastructure/modules/terraform-aws-example/main.tf
infrastructure/modules/terraform-aws-example/main.tf

@hay-kot
Copy link
Owner

hay-kot commented May 12, 2024

Super weird, found the issue there - fixed in #138. Thank you!

@izeau izeau mentioned this issue May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants