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

Update TFWriter to write files w/hclwrite package #23

Merged

Conversation

heyealex
Copy link
Contributor

@heyealex heyealex commented Nov 3, 2021

In order to handle certian complex data structures and long or
multi-line strings, our current approach of converting to YAML flow
style strings before writing to HCL files would not longer suffice. This
commit implements writing with the
hcl/hclwrite
library which gives us more control over how HCL is written and enforces
style guidelines actively.

As part of this conversion, some of the data in the config needs to be
converted to cty.Value objects rather than interface{} for handling
dynamic typing. This all happens in the writer currently, however at
some point it may be better to rebuild the pipeline to work with
cty.Value from the start.

@heyealex heyealex requested a review from cboneti November 3, 2021 19:45
Copy link
Member

@cboneti cboneti left a comment

Choose a reason for hiding this comment

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

Please see my comments

pkg/reswriter/reswriter.go Outdated Show resolved Hide resolved
pkg/reswriter/tfwriter.go Outdated Show resolved Hide resolved
pkg/reswriter/tfwriter.go Outdated Show resolved Hide resolved
pkg/reswriter/tfwriter.go Outdated Show resolved Hide resolved
pkg/reswriter/tfwriter.go Outdated Show resolved Hide resolved
In order to handle certian complex data structures and long or
multi-line strings, our current approach of converting to YAML flow
style strings before writing to HCL files would not longer suffice. This
commit implements writing with the
[hcl/hclwrite](https://pkg.go.dev/github.com/hashicorp/hcl/v2/hclwrite)
library which gives us more control over how HCL is written and enforces
style guidelines actively.

As part of this conversion, some of the data in the config needs to be
converted to cty.Value objects rather than interface{} for handling
dynamic typing. This all happens in the writer currently, however at
some point it may be better to rebuild the pipeline to work with
cty.Value from the start.
Addresses some reviewer feedback:

Pulls most functionality into a single function that will be used by all
inheriting struct objects (TFWriter, PackerWriter) rather than having
empty functions in both to support the interface.

Also removes a step from writeTerraformTfvars that updates passthrough
variables, as they should not exist there.

Added a test to increase coverage once again past 80%.
Merge remote-tracking branch 'upstream/develop' into hclwrite-resource-writer

* Updates tests to bring them back up to 80% in the reswriter
* Update writeMain to write terraform block with backend
* Handle merge conflicts
@heyealex heyealex merged commit 57c2265 into GoogleCloudPlatform:develop Nov 4, 2021
@heyealex heyealex deleted the hclwrite-resource-writer branch November 4, 2021 23:37
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.

2 participants