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

feat: add load of export_as_locals #123

Merged
merged 12 commits into from
Dec 31, 2021
Merged

feat: add load of export_as_locals #123

merged 12 commits into from
Dec 31, 2021

Conversation

katcipis
Copy link
Contributor

@katcipis katcipis commented Dec 30, 2021

Includes the core logic but no code generation, which will be done in a different PR. It is very similar to globals, but evaluation is simpler, so there is no attempt to extract duplication here yet, maybe in a future PR.

The spec: https://github.com/mineiros-io/terramate/blob/main/docs/locals-generation.md

@katcipis katcipis self-assigned this Dec 30, 2021
@codecov-commenter
Copy link

Codecov Report

Merging #123 (73e51a9) into main (e2135e0) will increase coverage by 0.11%.
The diff coverage is 81.41%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #123      +/-   ##
==========================================
+ Coverage   73.29%   73.41%   +0.11%     
==========================================
  Files          27       29       +2     
  Lines        2760     2998     +238     
==========================================
+ Hits         2023     2201     +178     
- Misses        556      597      +41     
- Partials      181      200      +19     
Flag Coverage Δ
tests 73.41% <81.41%> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
export_as_locals.go 77.89% <77.89%> (ø)
globals.go 91.96% <100.00%> (+0.14%) ⬆️
hcl/hcl.go 78.04% <100.00%> (-0.34%) ⬇️
test/sandbox/sandbox.go 82.60% <100.00%> (+0.88%) ⬆️
order.go 71.87% <0.00%> (-18.42%) ⬇️
cmd/terramate/cli/cli.go 63.18% <0.00%> (-1.30%) ⬇️
run.go 64.70% <0.00%> (ø)
hcl/printer.go 100.00% <0.00%> (ø)
dag/dag.go 91.26% <0.00%> (ø)
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e2135e0...73e51a9. Read the comment docs.

@katcipis katcipis requested a review from i4ki December 30, 2021 21:54
@katcipis katcipis marked this pull request as ready for review December 30, 2021 21:54
Copy link
Contributor

@soerenmartius soerenmartius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a decent amount of work! Thanks man, very good progress! I thank you for the input but will leave the review to someone who's a bit more familiar with Go :)

@katcipis
Copy link
Contributor Author

That's a decent amount of work! Thanks man, very good progress! I thank you for the input but will leave the review to someone who's a bit more familiar with Go :)

thanks for the feedback/review 💯

Copy link
Contributor

@i4ki i4ki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but left comments regarding the naming of choice.

The block is called export_as_locals to be clear the symbols will be generated as terraform locals, but it doesn't mean types and functions must have exportAsLocals as this is just the user-facing block name.

We're adding the ability to generate TF locals from terramate variables (globals and metadata at this moment), so from very high level, the generate has the task of "load locals variable mapping" and generate TF locals. Having this in mind, I would call the file locals_decl.go or locals_mapping.go and the functions to load the locals definitions could be LoadLocalsMap() or LoadLocalsDecl() or something like that.

Just sharing that the whole naming feels strange, it's like we are mixing syntax with the semantics.

// export_as_locals blocks.
//
// The rootdir MUST be an absolute path.
func LoadStackExportAsLocals(rootdir string, sm StackMetadata, g *Globals) (ExportAsLocals, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are they called LoadStack* if they load from any kind of configuration?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By having ExportAsLocals in the function names and types seems like the logic is doing this, when in fact this is just the name of the block...

I would call this just LoadStackLocals(), as it loads the locals values that are going to be generated later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are they called LoadStack* if they load from any kind of configuration?

Loading exported locals definitions depends on metadata + globals, and both are defined only on the context of a stack, there is no way to load locals that don't belong to a stack, unless we were loading un-evaluated information. It is pretty much the same as globals/metadata, they can be used/defined anywhere on a project but evaluation is always on the context of a stack.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By having ExportAsLocals in the function names and types seems like the logic is doing this, when in fact this is just the name of the block...

I would call this just LoadStackLocals(), as it loads the locals values that are going to be generated later.

Maybe LoadStackExportedLocals() ?

return ExportAsLocals{}, fmt.Errorf("%q must be an absolute path", rootdir)
}

unEvalExport, err := loadStackExportAsLocals(rootdir, sm.Path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unEvalExport is funny 😄

First, you have symbols or variables and after evaluation you get values. So maybe:

localVars, err := loadStackLocals(rootdir, sm.Path)
localValues, err := localVars.eval(sm, g)

as globals and metadata are kinds of variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

man I hated this uneval naming thing..but at the time I was completely stuck on not being able to think on better names, thanks 💯

return unEvalExportAsLocals{}, err
}

exportLocals := newUnEvalExportAsLocals()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newUnEvalExportAsLocals() again newUnEval is strange and AsLocal looks like converting something. Of course the context of the file is export_as_locals but it doesn't mean we need to embed this everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Man adding the "As" everywhere was the dumbest idea I ever had in my life..honestly..WTF. +1 on improving.

@katcipis
Copy link
Contributor Author

LGTM but left comments regarding the naming of choice.

The block is called export_as_locals to be clear the symbols will be generated as terraform locals, but it doesn't mean types and functions must have exportAsLocals as this is just the user-facing block name.

I hated the naming, was just not able to think on something better yet =P. +1 on improving.

We're adding the ability to generate TF locals from terramate variables (globals and metadata at this moment), so from very high level, the generate has the task of "load locals variable mapping" and generate TF locals. Having this in mind, I would call the file locals_decl.go or locals_mapping.go and the functions to load the locals definitions could be LoadLocalsMap() or LoadLocalsDecl() or something like that.

hmm maybe LoadStackLocals, Im torn because I also wanted to make it clear the whole concept that locals use exported data from Terramate (that is the whole point), just talking about "loading locals" doesn't make that very clear IMHO, and the concept exists independent of syntax, exported as locals are a thing, they are exported from Terramate and imported on Terraform code on the stack.

Just sharing that the whole naming feels strange, it's like we are mixing syntax with the semantics.

Hmm yeah maybe, I think I was too literal, but the semantic concept of exporting Terramate data as locals exist, it is not just because of the syntax, we are literally exporting data from Terramate configs into stack Terraform code. At this stage we are not generating the final code yet, but indeed just loading, but we are loading "exported locals".

Maybe the naming should be around "exported locals"... hmm thinking. I will merge this and address this on a PR ASAP, just to make sure I can keep building generate. Thanks for the review/feedback ❤️

@katcipis katcipis merged commit afdd844 into main Dec 31, 2021
@katcipis katcipis deleted the katcipis-export-as-locals branch December 31, 2021 15:48
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

Successfully merging this pull request may close these issues.

4 participants