Skip to content

Commit

Permalink
Merge pull request #2878 from hashicorp/b-provider-warnings-crash
Browse files Browse the repository at this point in the history
core: fix crash on provider warning
  • Loading branch information
phinze committed Jul 29, 2015
2 parents 1f31444 + 5ebbda3 commit 686598e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
40 changes: 40 additions & 0 deletions terraform/context_apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,46 @@ func TestContext2Apply_providerAlias(t *testing.T) {
}
}

// GH-2870
func TestContext2Apply_providerWarning(t *testing.T) {
m := testModule(t, "apply-provider-warning")
p := testProvider("aws")
p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn
p.ValidateFn = func(c *ResourceConfig) (ws []string, es []error) {
ws = append(ws, "Just a warning")
return
}
ctx := testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
})

if _, err := ctx.Plan(); err != nil {
t.Fatalf("err: %s", err)
}

state, err := ctx.Apply()
if err != nil {
t.Fatalf("err: %s", err)
}

actual := strings.TrimSpace(state.String())
expected := strings.TrimSpace(`
aws_instance.foo:
ID = foo
`)
if actual != expected {
t.Fatalf("got: \n%s\n\nexpected:\n%s", actual, expected)
}

if !p.ConfigureCalled {
t.Fatalf("provider Configure() was never called!")
}
}

func TestContext2Apply_emptyModule(t *testing.T) {
m := testModule(t, "apply-empty-module")
p := testProvider("aws")
Expand Down
29 changes: 27 additions & 2 deletions terraform/evaltree_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ func ProviderEvalTree(n string, config *config.RawConfig) EvalNode {
},
})

// Apply stuff
seq = append(seq, &EvalOpFilter{
Ops: []walkOperation{walkValidate, walkRefresh, walkPlan, walkApply},
Ops: []walkOperation{walkValidate},
Node: &EvalSequence{
Nodes: []EvalNode{
&EvalGetProvider{
Expand Down Expand Up @@ -70,6 +69,32 @@ func ProviderEvalTree(n string, config *config.RawConfig) EvalNode {
},
})

// Apply stuff
seq = append(seq, &EvalOpFilter{
Ops: []walkOperation{walkRefresh, walkPlan, walkApply},
Node: &EvalSequence{
Nodes: []EvalNode{
&EvalGetProvider{
Name: n,
Output: &provider,
},
&EvalInterpolate{
Config: config,
Output: &resourceConfig,
},
&EvalBuildProviderConfig{
Provider: n,
Config: &resourceConfig,
Output: &resourceConfig,
},
&EvalSetProviderConfig{
Provider: n,
Config: &resourceConfig,
},
},
},
})

// We configure on everything but validate, since validate may
// not have access to all the variables.
seq = append(seq, &EvalOpFilter{
Expand Down
1 change: 1 addition & 0 deletions terraform/test-fixtures/apply-provider-warning/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
resource "aws_instance" "foo" {}

0 comments on commit 686598e

Please sign in to comment.