terraform: improve error messages to assist REPL
This commit is contained in:
parent
d9c522173d
commit
a633cdf95d
|
@ -25,6 +25,21 @@ func TestSession_basicState(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
|
||||
&terraform.ModuleState{
|
||||
Path: []string{"root", "module"},
|
||||
Resources: map[string]*terraform.ResourceState{
|
||||
"test_instance.foo": &terraform.ResourceState{
|
||||
Type: "test_instance",
|
||||
Primary: &terraform.InstanceState{
|
||||
ID: "bar",
|
||||
Attributes: map[string]string{
|
||||
"id": "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -64,6 +79,32 @@ func TestSession_basicState(t *testing.T) {
|
|||
},
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("missing module", func(t *testing.T) {
|
||||
testSession(t, testSessionTest{
|
||||
State: state,
|
||||
Inputs: []testSessionInput{
|
||||
{
|
||||
Input: "module.child.foo",
|
||||
Error: true,
|
||||
ErrorContains: "Couldn't find module \"child\"",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("missing module output", func(t *testing.T) {
|
||||
testSession(t, testSessionTest{
|
||||
State: state,
|
||||
Inputs: []testSessionInput{
|
||||
{
|
||||
Input: "module.module.foo",
|
||||
Error: true,
|
||||
ErrorContains: "Couldn't find output \"foo\"",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestSession_stateless(t *testing.T) {
|
||||
|
|
|
@ -160,6 +160,13 @@ func (i *Interpolater) valueModuleVar(
|
|||
// ensure that the module is in the state, so if we reach this
|
||||
// point otherwise it really is a panic.
|
||||
result[n] = unknownVariable()
|
||||
|
||||
// During apply this is always an error
|
||||
if i.Operation == walkApply {
|
||||
return fmt.Errorf(
|
||||
"Couldn't find module %q for var: %s",
|
||||
v.Name, v.FullKey())
|
||||
}
|
||||
} else {
|
||||
// Get the value from the outputs
|
||||
if outputState, ok := mod.Outputs[v.Field]; ok {
|
||||
|
@ -171,6 +178,13 @@ func (i *Interpolater) valueModuleVar(
|
|||
} else {
|
||||
// Same reasons as the comment above.
|
||||
result[n] = unknownVariable()
|
||||
|
||||
// During apply this is always an error
|
||||
if i.Operation == walkApply {
|
||||
return fmt.Errorf(
|
||||
"Couldn't find output %q for module var: %s",
|
||||
v.Field, v.FullKey())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue