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

fix: Avoid panic in sops decrypt #3494

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
}