Skip to content

Commit

Permalink
fix: Avoid panic in sops decrypt (#3494)
Browse files Browse the repository at this point in the history
  • Loading branch information
yhakbar authored Oct 17, 2024
1 parent a33a1d1 commit 956aeeb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config/config_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ func extractSopsErrors(err error) *errors.MultiError {
}

// append the original error if no group results were found
if errs.Len() == 0 {
if errs == nil {
errs = errs.Append(err)
}

Expand Down
Empty file.
3 changes: 3 additions & 0 deletions test/fixtures/sops-missing/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locals {
secret_vars = yamldecode(sops_decrypt_file("${get_terragrunt_dir()}/missing.yaml"))
}
19 changes: 17 additions & 2 deletions test/integration_sops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (
)

const (
testFixtureSops = "fixtures/sops"
testFixtureSopsErrors = "fixtures/sops-errors"
testFixtureSops = "fixtures/sops"
testFixtureSopsErrors = "fixtures/sops-errors"
testFixtureSopsMissing = "fixtures/sops-missing"
)

func TestSopsDecryptedCorrectly(t *testing.T) {
Expand Down Expand Up @@ -97,3 +98,17 @@ func TestTerragruntLogSopsErrors(t *testing.T) {
assert.Contains(t, errorOut, "error decrypting key: [error decrypting key")
assert.Contains(t, errorOut, "error base64-decoding encrypted data key: illegal base64 data at input byte")
}

func TestSopsDecryptOnMissing(t *testing.T) {
t.Parallel()

cleanupTerraformFolder(t, testFixtureSopsMissing)
tmpEnvPath := copyEnvironment(t, testFixtureSopsMissing)
rootPath := util.JoinPath(tmpEnvPath, testFixtureSopsMissing)

// apply and check for errors
_, errorOut, err := runTerragruntCommandWithOutput(t, "terragrunt apply --terragrunt-non-interactive --terragrunt-log-level debug --terragrunt-working-dir "+rootPath)
require.Error(t, err)

assert.Contains(t, errorOut, "Encountered error while evaluating locals in file ./terragrunt.hcl")
}

0 comments on commit 956aeeb

Please sign in to comment.