Dont use terraform's file() for singleline strings in GCE metadata #9084
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently the instance_template's metadata field contains the startup script, ssh keys, cluster name, and IG name. rather than storing redundant separate files containing just the cluster and IG names, this will store them as string literals within the .tf file.
The motivation for this is that a new version of hcl2 adds support for writing multiline maps. Using the library's function for writing maps will allow us to get rid of our own hcl2.go's
writeMap
function. The only blocker is that the library doesn't support values being literals likefoo = file()
. GCE's instance_template is the only such use of maps in kops and this fixes 2 of the 4 fields.The instance_template terraform resource actually has a separate metadata_startup_script field that we can use instead of having the script in the metadata field (I'll update that in a followup PR). That leaves the ssh key as the last file() in the metadata field. We could inline it as another hardcoded string, but it seems better to use ssh keys at the project level rather than instance level. I dont have a gce account to test that though so I'd need assistance in that migration.
/assign @geojaz
This also removes a redundant terraform literal function
LiteralExpression
that was only used in one place, with the identicalLiteralFromStringValue
being more commonly used.