Repository navigation
Conversation
Add a store that reads and writes HCL, so Terraform .tfvars and
Terragrunt .hcl files can be encrypted directly. The format is selected
by the .hcl and .tfvars extensions or with --input-type/--output-type hcl.
Attributes and (labeled) blocks are mapped to the sops tree. A block is
stored under its header, for example `resource "aws_instance" "web" {`,
which keeps it distinct from an attribute holding an object. Literal
strings, numbers and bools are encrypted, as are lists and objects made
of literals. Any other expression (references, function calls,
interpolated templates, ...) is kept as its source text, wrapped as
`${...}`, and encrypted like a string, so it is written back verbatim
on decryption. Comments are kept; the sops metadata is stored as a
top-level `sops` attribute.
Fixes getsops#292
Signed-off-by: Ethan Aldrich <ethan@ethanaldrich.net>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #292
Adds an
hclstore so Terraform.tfvarsand Terragrunt-style.hclfiles can be encrypted directly. It is picked by the.hcl/.tfvarsextensions or--input-type/--output-type hcl;.tfvars.jsonstays JSON. It is built onhashicorp/hcl/v2and wired in the same places asini.Design
resource "aws_instance" "web" {. The{keepstags { }distinct fromtags = { }.${...}(HCL's own JSON convention), and written back verbatim on decrypt. I encrypt these rather than leave them readable because an expression can hold a secret, and a plaintext leaf would need core changes.--unencrypted-regexstill works as usual.sops = { ... }attribute.Limitations
terraform fmtstyle: blank lines are dropped, heredocs become quoted strings,1.0becomes1.k /* c */ = "v") are dropped.\uescapes) are kept as source text so they round-trip byte-exact; such block labels are rejected.${...}is rejected, since it can't be told apart from an expression.set/unset/--extractuse the full block header in single quotes:['resource "aws_instance" "web" {']["ami"].Dependency
hcl/v2andgo-ctydirect, plus 5 indirect modules. The linux/amd64 binary grows by 2.4 MB (3.2%).Testing
stores/hclcover round trips, blocks, expressions, comments, Unicode, error cases, and a full AES encrypt/decrypt that checks no secret or expression text is visible. The formats tests and thedecrypt_formatfunctional test now cover HCL too.go test ./...: onlyhcvaultandkmsfail (no Docker socket), the same as on main.go vetandmake vendor && git diff --exit-codeare clean..hclfile with nested and repeated labeled blocks decrypts byte-identical. A tamperedENC[...]value fails the MAC check.terraform plan -var-fileon an encrypted.tfvarsonly warns about the undeclaredsopsvariable.