terraform: fix crash if outputs with no state [GH-358]

This commit is contained in:
Mitchell Hashimoto 2014-10-03 15:57:43 -07:00
parent 5c2182e316
commit 94f43ff145
3 changed files with 23 additions and 1 deletions

View File

@ -498,7 +498,7 @@ func (c *walkContext) Walk() error {
// On Apply, we prune so that we don't do outputs if we destroyed // On Apply, we prune so that we don't do outputs if we destroyed
mod.prune() mod.prune()
} }
if len(mod.Resources) == 0 { if mod == nil || len(mod.Resources) == 0 {
return nil return nil
} }

View File

@ -3336,6 +3336,27 @@ func TestContextRefresh_modules(t *testing.T) {
} }
} }
// GH-70
func TestContextRefresh_noState(t *testing.T) {
p := testProvider("aws")
m := testModule(t, "refresh-no-state")
ctx := testContext(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
})
p.RefreshFn = nil
p.RefreshReturn = &InstanceState{
ID: "foo",
}
if _, err := ctx.Refresh(); err != nil {
t.Fatalf("err: %s", err)
}
}
func TestContextRefresh_state(t *testing.T) { func TestContextRefresh_state(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
m := testModule(t, "refresh-basic") m := testModule(t, "refresh-basic")

View File

@ -0,0 +1 @@
output "foo" {}