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

Allow templating COMPONENT_NAME during package create #1888

Closed
Racer159 opened this issue Jul 7, 2023 · 1 comment
Closed

Allow templating COMPONENT_NAME during package create #1888

Racer159 opened this issue Jul 7, 2023 · 1 comment
Assignees
Labels
enhancement ✨ New feature or request
Milestone

Comments

@Racer159
Copy link
Contributor

Racer159 commented Jul 7, 2023

Is your feature request related to a problem? Please describe.

When creating reusable importable components it would be useful to have a ###ZARF_COMPONENT_NAME### template / variable that can be used to scope that component properly.

Describe the solution you'd like

  • Given I have a zarf.yaml with ###ZARF_COMPONENT_NAME### in a string value
  • When I run zarf package create on that package
  • Then Zarf will template that value with that component's name

Describe alternatives you've considered

We could do this on deploy time or in another way, but most scoping would be around variables or actions and this would be easier / more declarative to do create-time.

Additional context

This would make things like a reusable S3 bucket component easier to make.

@Racer159 Racer159 added the enhancement ✨ New feature or request label Jul 7, 2023
@Racer159 Racer159 added this to the The Bucket milestone Jul 20, 2023
@cmwylie19 cmwylie19 self-assigned this Jul 20, 2023
Noxsios added a commit that referenced this issue Aug 2, 2023
## Description

This PR allows for templating component name during package create and
give the ability to template with more fields in the component struct.

While the PR is roughly similar to
[FindYamlTemplates](https://github.com/defenseunicorns/zarf/blob/02150cfda1a32d5c6ebb4c446d731dc217e3961e/src/pkg/utils/yaml.go#L164)
there is extra complexity in components that required a new function
[FindComponentTemplatesAndReload](https://github.com/defenseunicorns/zarf/blob/9b3e396abc39a395ceb7999565bfb09088cd39c5/src/pkg/utils/yaml.go#L166).
Each component may have a different name that the string map would
overwrite. Due to this nature, the straightforward path was a new
function to mutate in place, FindComponentTemplatesAndReload. It
operates on the ZarfPackage object passed in by interface by iterating
over the Components and mutating by updating the templated files. This
opens up the possibility to template more fields in components rather
than just [component
names](https://github.com/defenseunicorns/zarf/blob/9b3e396abc39a395ceb7999565bfb09088cd39c5/src/pkg/utils/yaml.go#L186).

Currently there is a place-holder example of
[Component-Name-Template](https://github.com/defenseunicorns/zarf/blob/1888/examples/component-name-template/zarf.yaml)
which will need to be changed before removing draft status from PR.

This PR is in a holding pattern while waiting from feedback from
@Racer159


## Related Issue

Fixes 
<!-- or -->
Relates to #1888

## Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Other (security config, docs update, etc)

## Checklist before merging

- [x] Test, docs, adr added or updated as needed
- [x] [Contributor Guide
Steps](https://github.com/defenseunicorns/zarf/blob/main/CONTRIBUTING.md#developer-workflow)
followed

---------

Signed-off-by: Case Wylie <cmwylie19@defenseunicorns.com>
Co-authored-by: razzle <harry@razzle.cloud>
@Racer159
Copy link
Contributor Author

Racer159 commented Aug 2, 2023

Closing as completed by #1923

@Racer159 Racer159 closed this as completed Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants