terraform: don't fail refresh if output doesn't exist [GH-483]
This commit is contained in:
parent
590a635b70
commit
0908e8f42c
|
@ -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"]
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
resource "aws_instance" "foo" {}
|
||||
|
||||
resource "aws_instance" "web" {}
|
||||
|
||||
output "foo" {
|
||||
value = "${aws_instance.web.foo}"
|
||||
}
|
Loading…
Reference in New Issue