Skip to content

Commit

Permalink
Include var declaration where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
alisdair committed May 13, 2022
1 parent 378ee6a commit 6494aa0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
7 changes: 5 additions & 2 deletions internal/terraform/eval_variable.go
Expand Up @@ -110,8 +110,11 @@ func prepareFinalInputVariableValue(addr addrs.AbsInputVariableInstance, raw *In
// and not by the operator directly. In such a case, the failing secret value should not be
// displayed to the operator
if cfg.Sensitive {
subject = nil
detail += fmt.Sprintf("\n\n%s is marked as sensitive. Invalid value defined at %s.", addr, sourceRange.ToHCL())
detail = fmt.Sprintf(
"The given value is not suitable for %s, which is sensitive: %s. Invalid value defined at %s.",
addr, err, sourceRange.ToHCL(),
)
subject = cfg.DeclRange.Ptr()
}
}

Expand Down
12 changes: 6 additions & 6 deletions internal/terraform/eval_variable_test.go
Expand Up @@ -590,13 +590,11 @@ func TestPrepareFinalInputVariableValue(t *testing.T) {
{
ValueFromConfig,
tfdiags.SourceRange{
Filename: "example.tf",
Filename: "example.tfvars",
Start: tfdiags.SourcePos(hcl.InitialPos),
End: tfdiags.SourcePos(hcl.InitialPos),
},
`Invalid value for input variable: The given value is not suitable for var.constrained_string_sensitive_required declared at main.tf:46,3-51: string required.
var.constrained_string_sensitive_required is marked as sensitive. Invalid value defined at example.tf:1,1-1.`,
`Invalid value for input variable: The given value is not suitable for var.constrained_string_sensitive_required, which is sensitive: string required. Invalid value defined at example.tfvars:1,1-1.`,
true,
},
}
Expand All @@ -623,8 +621,10 @@ var.constrained_string_sensitive_required is marked as sensitive. Invalid value
t.Errorf("wrong error\ngot: %s\nwant: %s", got, want)
}

if test.HideSubject != (diags[0].Source().Subject == nil) {
t.Errorf("Subject (code context) should have been masked\ngot: %v", diags[0].Source().Subject)
if test.HideSubject {
if got, want := diags[0].Source().Subject.StartString(), test.SourceRange.StartString(); got == want {
t.Errorf("Subject start should have been hidden, but was %s", got)
}
}
})
})
Expand Down

0 comments on commit 6494aa0

Please sign in to comment.