core: Move invalid output context tests to "validate"
This problem should now be caught at validate time rather than plan time, because we can use the schema to detect the problem before the resource has been resolved.
This commit is contained in:
parent
824986b698
commit
5a77045a61
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue