Skip to content

Commit

Permalink
terraform: don't fail refresh if output doesn't exist [GH-483]
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Oct 21, 2014
1 parent 590a635 commit 0908e8f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
8 changes: 8 additions & 0 deletions terraform/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
44 changes: 44 additions & 0 deletions terraform/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -4441,6 +4481,10 @@ module.child:
ID = new
`

const testContextRefreshOutputPartialStr = `
<no state>
`

const testContextRefreshTaintedStr = `
aws_instance.web: (1 tainted)
ID = <not created>
Expand Down
7 changes: 7 additions & 0 deletions terraform/test-fixtures/refresh-output-partial/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "aws_instance" "foo" {}

resource "aws_instance" "web" {}

output "foo" {
value = "${aws_instance.web.foo}"
}

0 comments on commit 0908e8f

Please sign in to comment.