diff --git a/terraform/context_validate_test.go b/terraform/context_validate_test.go index 087de1a2e..469966805 100644 --- a/terraform/context_validate_test.go +++ b/terraform/context_validate_test.go @@ -1131,6 +1131,71 @@ func TestContext2Validate_interpolateMap(t *testing.T) { } } +func TestContext2Validate_varSensitive(t *testing.T) { + // Smoke test through validate where a variable has sensitive applied + m := testModuleInline(t, map[string]string{ + "main.tf": ` +variable "foo" { + default = "xyz" + sensitive = true +} + +variable "bar" { + sensitive = true +} + +data "aws_data_source" "bar" { + foo = var.bar +} + +resource "aws_instance" "foo" { + foo = var.foo +} +`, + }) + + p := testProvider("aws") + p.ValidateResourceTypeConfigFn = func(req providers.ValidateResourceTypeConfigRequest) providers.ValidateResourceTypeConfigResponse { + // Providers receive unmarked values + if got, want := req.Config.GetAttr("foo"), cty.UnknownVal(cty.String); !got.RawEquals(want) { + t.Fatalf("wrong value for foo\ngot: %#v\nwant: %#v", got, want) + } + return providers.ValidateResourceTypeConfigResponse{} + } + p.ValidateDataSourceConfigFn = func(req providers.ValidateDataSourceConfigRequest) (resp providers.ValidateDataSourceConfigResponse) { + if got, want := req.Config.GetAttr("foo"), cty.UnknownVal(cty.String); !got.RawEquals(want) { + t.Fatalf("wrong value for foo\ngot: %#v\nwant: %#v", got, want) + } + return providers.ValidateDataSourceConfigResponse{} + } + + ctx := testContext2(t, &ContextOpts{ + Config: m, + Providers: map[addrs.Provider]providers.Factory{ + addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p), + }, + Variables: InputValues{ + "bar": &InputValue{ + Value: cty.StringVal("boop"), + SourceType: ValueFromCaller, + }, + }, + }) + + diags := ctx.Validate() + if diags.HasErrors() { + t.Fatal(diags.Err()) + } + + if !p.ValidateResourceTypeConfigCalled { + t.Fatal("expected ValidateResourceTypeConfigFn to be called") + } + + if !p.ValidateDataSourceConfigCalled { + t.Fatal("expected ValidateDataSourceConfigFn to be called") + } +} + // Manually validate using the new PlanGraphBuilder func TestContext2Validate_PlanGraphBuilder(t *testing.T) { fixture := contextFixtureApplyVars(t)