terraform: don't fail refresh if output doesn't exist [GH-483]

This commit is contained in:
Mitchell Hashimoto 2014-10-20 18:45:52 -07:00
parent 590a635b70
commit 0908e8f42c
3 changed files with 59 additions and 0 deletions

View File

@ -531,6 +531,14 @@ func (c *walkContext) Walk() error {
outputs := make(map[string]string)
for _, o := range conf.Outputs {
if err := c.computeVars(o.RawConfig, nil); err != nil {
// If we're refreshing, then we ignore output errors. This is
// properly not fully the correct behavior, but fixes a range
// of issues right now. As we expand test cases to find the
// correct behavior, this will likely be removed.
if c.Operation == walkRefresh {
continue
}
return err
}
vraw := o.RawConfig.Config()["value"]

View File

@ -4131,6 +4131,46 @@ func TestContextRefresh_noState(t *testing.T) {
}
}
func TestContextRefresh_outputPartial(t *testing.T) {
p := testProvider("aws")
m := testModule(t, "refresh-output-partial")
ctx := testContext(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
State: &State{
Modules: []*ModuleState{
&ModuleState{
Path: rootModulePath,
Resources: map[string]*ResourceState{
"aws_instance.foo": &ResourceState{
Type: "aws_instance",
Primary: &InstanceState{
ID: "foo",
},
},
},
},
},
},
})
p.RefreshFn = nil
p.RefreshReturn = nil
s, err := ctx.Refresh()
if err != nil {
t.Fatalf("err: %s", err)
}
actual := strings.TrimSpace(s.String())
expected := strings.TrimSpace(testContextRefreshOutputPartialStr)
if actual != expected {
t.Fatalf("bad:\n\n%s\n\n%s", actual, expected)
}
}
func TestContextRefresh_state(t *testing.T) {
p := testProvider("aws")
m := testModule(t, "refresh-basic")
@ -4441,6 +4481,10 @@ module.child:
ID = new
`
const testContextRefreshOutputPartialStr = `
<no state>
`
const testContextRefreshTaintedStr = `
aws_instance.web: (1 tainted)
ID = <not created>

View File

@ -0,0 +1,7 @@
resource "aws_instance" "foo" {}
resource "aws_instance" "web" {}
output "foo" {
value = "${aws_instance.web.foo}"
}