Skip to content

Commit 5534e3d

Browse files
committed
backport of commit 27ea08b
1 parent afab18e commit 5534e3d

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

internal/terraform/context_plan_test.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6974,7 +6974,7 @@ func TestContext2Plan_variableCustomValidationsCrossRef(t *testing.T) {
69746974
}
69756975
}
69766976

6977-
func TestContext2Plan_variableCustomValidationsSensitive(t *testing.T) {
6977+
func TestContext2Plan_variableCustomValidationsChildSensitive(t *testing.T) {
69786978
m := testModule(t, "validate-variable-custom-validations-child-sensitive")
69796979

69806980
p := testProvider("test")
@@ -6993,6 +6993,39 @@ func TestContext2Plan_variableCustomValidationsSensitive(t *testing.T) {
69936993
}
69946994
}
69956995

6996+
func TestContext2Plan_variableCustomValidationsSensitive(t *testing.T) {
6997+
m := testModule(t, "validate-variable-custom-validations-sensitive")
6998+
6999+
p := testProvider("test")
7000+
ctx := testContext2(t, &ContextOpts{
7001+
Providers: map[addrs.Provider]providers.Factory{
7002+
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
7003+
},
7004+
})
7005+
7006+
_, diags := ctx.Plan(m, states.NewState(), SimplePlanOpts(plans.NormalMode, InputValues{
7007+
"input": {
7008+
Value: cty.StringVal("short"),
7009+
},
7010+
}))
7011+
if len(diags) != 1 {
7012+
t.Fatal("wanted exactly one error")
7013+
}
7014+
if diff := cmp.Diff(diags[0].Description(), tfdiags.Description{
7015+
Summary: "Invalid value for variable",
7016+
Detail: "too short\n\nThis was checked by the validation rule at testdata/validate-variable-custom-validations-sensitive/validate-variable-custom-validations-sensitive.tf:4,3-13.",
7017+
}); len(diff) > 0 {
7018+
t.Error(diff)
7019+
}
7020+
7021+
vars := diags[0].FromExpr().EvalContext.Variables["var"].AsValueMap()
7022+
7023+
_, ms := vars["input"].Unmark()
7024+
if _, ok := ms[marks.Sensitive]; !ok {
7025+
t.Error("should have been marked as sensitive")
7026+
}
7027+
}
7028+
69967029
func TestContext2Plan_nullOutputNoOp(t *testing.T) {
69977030
// this should always plan a NoOp change for the output
69987031
m := testModuleInline(t, map[string]string{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
variable "input" {
3+
type = string
4+
validation {
5+
condition = length(var.input) > 5
6+
error_message = "too short"
7+
}
8+
sensitive = true
9+
}
10+
11+
output "value" {
12+
value = var.input
13+
}

0 commit comments

Comments
 (0)