-
Notifications
You must be signed in to change notification settings - Fork 21
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
create default tf vars file #65
Conversation
Signed-off-by: Brian DeGeeter <b.degeeter@f5.com>
Hi @bdegeeter, thanks for the PR. Before diving into a code review, I was hoping to check on a few things. In familiarizing myself with the tfvars file, I created a minimal sample bundle employing the approach of using a pre-made tfvars file (existing in the same I wonder if this might be the simplest approach, assuming it suits the needs mentioned here? It basically circumvents the need for parameters to be managed by Porter. Alternatively, if the bundle author wants installers of the bundle to supply their own tfvars file at runtime, the parameter could just be a 'classic' parameter with no output source, like so:
Then, a parameter set for this bundle could be generated with the location to the user's tfvars file supplied:
...and used for any bundle action, e.g.
This latter use case would tie in nicely with @carolynvs 's proposal in getporter/porter#1672, specifically the Otherwise, if the bundle author does wish to have a bundle parameter for individual terraform vars, it seems like the What do you think of those thoughts/approaches? Let me know if I may be missing (or misunderstanding) use case(s) here. Thanks! |
Here's how I've applied it to a working example. https://github.com/bdegeeter/porter-terraform-example/pull/3/files It's still desirable for my case to use bundle parameters for every TF var. It provides a more uniform interface to bundles in general. I could see the same pattern apply to generation of ansible inventory vars. The bundle user doesn't need to care about the specific format for terraform, ansible or some other tool. The primary goal I was going for is to have mixin vars block written as a tfvar file similar to tfstate so I did not have to maintain a duplicate Maybe there's a different strategy to have a "global" vars block? Having users or a service craft a file specific to a technology like terraform is not desirable over more "specific" types like strings, ints, numbers, and booleans. |
On a code review note (if the PR is desired). I made the change with go1.16 and did not see the build error. When I switch to go1.13 I can repro the issue. I can fix for 1.13 or update to use 1.16 depending on preference. |
Indeed, excellent point around expressing terraform vars as bundle parameters to the user -- terraform can just be an implementation detail, among others, that the bundle author has decided to use, and which perhaps needn't be obvious/explicit to the bundle user. The one thing this brings up for me, which isn't an issue for this PR, is how the tfvars and tfstate params are still shown to the user when/if they generate a parameter set from bundles that use these. However, the pattern is that users of the bundle should not provide values for either. This is a good issue for us to file in Porter (maybe allowing bundle authors to 'hide' such parameters with output sources -- or at least parameters that aren't expected to be set by users installing the bundle)... anyway, for another time :)
That's an interesting idea. My first idea was perhaps adding a
However, not sure this would be any better... it would also be a bit of a paradigm shift for a mixin config section -- classically it is used for build-time options as opposed to run-time. Ok, thanks so much for supplying a link to your example bundle using this feature. I'm definitely getting a better picture of the functionality here. I'll start checking out the code! |
pkg/terraform/install.go
Outdated
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("TF var file created:\n%s\n", string(vbs)) |
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.
I wonder if we should remove this log line? Perhaps to avoid printing sensitive parameter values? Or perhaps a compromise would be to conditionally print if debug is set to true
?
pkg/terraform/install.go
Outdated
for _, k := range sortKeys(step.Vars) { | ||
step.Flags = append(step.Flags, builder.NewFlag("var", fmt.Sprintf("'%s=%s'", k, step.Vars[k]))) | ||
if step.CreateVarFile { | ||
vf, err := m.FileSystem.Fs.Create(path.Join(m.WorkingDir, m.TerraformVarsFilename)) |
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.
nit: this could be written as m.FileSystem.Create(path.Join(m.WorkingDir, m.TerraformVarsFilename))
Oh, I forgot to mention. I believe the build failure was occurring on the |
fix(build): pin packr
Signed-off-by: Brian DeGeeter <b.degeeter@f5.com>
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.
This is looking great, thanks for collaborating! A few last items to look at...
Signed-off-by: Brian DeGeeter <b.degeeter@f5.com>
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.
Thank you @bdegeeter ! LGTM.
new feature for optional creation of a
terraform.tfvars.json
file from thevars
block. This enables persistent of non-default or required vars with no default via a file parameter and output.Add
createVarFile: true
to the terraform install block to enable.