-
Notifications
You must be signed in to change notification settings - Fork 20
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
feat: extra_templates allows users to control templates #1046
Conversation
…o heathj/providers
config/v2/resolvers.go
Outdated
templates := []ExtraTemplate{} | ||
for _, v := range *comm.ExtraTemplates { | ||
templates = append(templates, ExtraTemplate{ | ||
Overwrite: v.Overwrite, | ||
Files: v.Files, | ||
}) | ||
} | ||
return &templates |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential opportunity to make a helper to consolidate same mapping functionality (1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right, but unfortunately, the way this codebase's packages are laid out makes this difficult without doing a bit of refactoring. The config stage structs are all pointers because the configuration can or cannot have values and then they duplicate these same structs in the plan phase once they are "resolved" (going down the tree of overwrites from global -> default -> account -> env -> component) through the tree overwrites. Resolved structs don't have pointers. I would love to simplify this code since its so copy/pasted, but maybe I will try that in a different PR
plan/plan.go
Outdated
extraTemplates := []ExtraTemplate{} | ||
for _, v := range v2.ResolveExtraTemplates(commons...) { | ||
extraTemplates = append(extraTemplates, ExtraTemplate{ | ||
Files: v.Files, | ||
Overwrite: v.Overwrite, | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential opportunity to make a helper to consolidate same mapping functionality (2)
Co-authored-by: Hayden Spitzley <[email protected]>
Summary
This PR adds a feature to fogg.yml that allows users to add custom golang templates to components. Users will have full access to the plan's struct in the template, allowing them to write configuration files of their own without changing the fogg code base. This is handy when we have repeatable stacks for a specific application or environment, but don't necessarily need it to be hardcoded into the fogg codebase. We can think of these a mini fogg extensions.
You can provide a set of files to any component (env, account, global, default,...) and you can also specify if fogg should overwrite a file that already exists with the
overwrite
option (defaults to false). Settingoverwrite
to true would allow someone to scaffold and template an infra stack, but still be allowed to manage the component's infrastructure normally without worrying about fogg overwritting the changes.Here's an example of how to call it:
In addition to the normal stuff fogg creates, it would also produce these files:
terraform/envs/dev/eks/variables.tf
terraform/envs/dev/eks/test.txt
Notice how instead of relying on
env = var.tags.env
, we could code-generate the local variableenv
withenv = {{.Env | quote}}
, since the template has access to the full component plan.