diff --git a/terraform/context_plan_test.go b/terraform/context_plan_test.go index 55fc0313ae..eac78e26a5 100644 --- a/terraform/context_plan_test.go +++ b/terraform/context_plan_test.go @@ -3701,85 +3701,3 @@ aws_instance.foo.1: t.Fatalf("bad:\n%s\n\nexpected\n\n%s", actual, expected) } } - -func TestContext2Plan_invalidOutput(t *testing.T) { - m := testModuleInline(t, map[string]string{ - "main.tf": ` -data "aws_instance" "name" {} - -output "out" { - value = "${data.aws_instance.name.missing}" -}`, - }) - - p := testProvider("aws") - ctx := testContext2(t, &ContextOpts{ - Config: m, - ProviderResolver: ResourceProviderResolverFixed( - map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, - ), - }) - - // if this ever fails to pass validate, add a resource to reference in the config - diags := ctx.Validate() - if diags.HasErrors() { - t.Fatalf("validate errors: %s", diags.Err()) - } - - _, diags = ctx.Refresh() - if diags.HasErrors() { - t.Fatalf("refresh errors: %s", diags.Err()) - } - - _, diags = ctx.Plan() - if !diags.HasErrors() { - t.Fatal("succeeded; want errors") - } -} - -func TestContext2Plan_invalidModuleOutput(t *testing.T) { - m := testModuleInline(t, map[string]string{ - "child/main.tf": ` -data "aws_instance" "name" {} - -output "out" { - value = "${data.aws_instance.name.missing}" -}`, - "main.tf": ` -module "child" { - source = "./child" -} - -resource "aws_instance" "foo" { - foo = "${module.child.out}" -}`, - }) - - p := testProvider("aws") - ctx := testContext2(t, &ContextOpts{ - Config: m, - ProviderResolver: ResourceProviderResolverFixed( - map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, - ), - }) - - // if this ever fails to pass validate, add a resource to reference in the config - diags := ctx.Validate() - if diags.HasErrors() { - t.Fatalf("validate errors: %s", diags.Err()) - } - - _, diags = ctx.Refresh() - if diags.HasErrors() { - t.Fatalf("refresh errors: %s", diags.Err()) - } - - _, diags = ctx.Plan() - if !diags.HasErrors() { - t.Fatal("succeeded; want errors") - } -} diff --git a/terraform/context_validate_test.go b/terraform/context_validate_test.go index af512c59e0..ba10766443 100644 --- a/terraform/context_validate_test.go +++ b/terraform/context_validate_test.go @@ -1234,3 +1234,67 @@ func TestContext2Validate_PlanGraphBuilder(t *testing.T) { t.Fatal(walker.NonFatalDiagnostics.Err()) } } + +func TestContext2Validate_invalidOutput(t *testing.T) { + m := testModuleInline(t, map[string]string{ + "main.tf": ` +data "aws_data_source" "name" {} + +output "out" { + value = "${data.aws_data_source.name.missing}" +}`, + }) + + p := testProvider("aws") + ctx := testContext2(t, &ContextOpts{ + Config: m, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), + }) + + diags := ctx.Validate() + if !diags.HasErrors() { + // Should get this error: + // Unsupported attribute: This object does not have an attribute named "missing" + t.Fatal("succeeded; want errors") + } +} + +func TestContext2Validate_invalidModuleOutput(t *testing.T) { + m := testModuleInline(t, map[string]string{ + "child/main.tf": ` +data "aws_data_source" "name" {} + +output "out" { + value = "${data.aws_data_source.name.missing}" +}`, + "main.tf": ` +module "child" { + source = "./child" +} + +resource "aws_instance" "foo" { + foo = "${module.child.out}" +}`, + }) + + p := testProvider("aws") + ctx := testContext2(t, &ContextOpts{ + Config: m, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), + }) + + diags := ctx.Validate() + if !diags.HasErrors() { + // Should get this error: + // Unsupported attribute: This object does not have an attribute named "missing" + t.Fatal("succeeded; want errors") + } +}