terraform: provisioners should only be run on first create

This commit is contained in:
Mitchell Hashimoto 2015-02-13 10:09:35 -08:00
parent c70cc682ea
commit e2abf17c9c
3 changed files with 33 additions and 19 deletions

View File

@ -3581,9 +3581,8 @@ func TestContext2Apply_provisionerResourceRef(t *testing.T) {
}
}
/*
// Provisioner should NOT run on a diff, only create
func TestContextApply_Provisioner_Diff(t *testing.T) {
func TestContext2Apply_Provisioner_Diff(t *testing.T) {
m := testModule(t, "apply-provisioner-diff")
p := testProvider("aws")
pr := testProvisioner()
@ -3592,7 +3591,7 @@ func TestContextApply_Provisioner_Diff(t *testing.T) {
pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error {
return nil
}
ctx := testContext(t, &ContextOpts{
ctx := testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
@ -3628,7 +3627,7 @@ func TestContextApply_Provisioner_Diff(t *testing.T) {
mod.Resources["aws_instance.bar"].Primary.Attributes["foo"] = "baz"
// Re-create context with state
ctx = testContext(t, &ContextOpts{
ctx = testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
@ -3659,6 +3658,7 @@ func TestContextApply_Provisioner_Diff(t *testing.T) {
}
}
/*
func TestContextApply_outputDiffVars(t *testing.T) {
m := testModule(t, "apply-good")
p := testProvider("aws")

View File

@ -12,13 +12,14 @@ import (
// EvalApply is an EvalNode implementation that writes the diff to
// the full diff.
type EvalApply struct {
Info *InstanceInfo
State **InstanceState
Diff **InstanceDiff
Provider *ResourceProvider
Output **InstanceState
Error *error
Tainted *bool
Info *InstanceInfo
State **InstanceState
Diff **InstanceDiff
Provider *ResourceProvider
Output **InstanceState
CreateNew *bool
Error *error
Tainted *bool
}
func (n *EvalApply) Args() ([]EvalNode, []EvalType) {
@ -52,6 +53,11 @@ func (n *EvalApply) Eval(
}
state.init()
// Flag if we're creating a new instance
if n.CreateNew != nil {
*n.CreateNew = (state.ID == "" && !diff.Destroy) || diff.RequiresNew()
}
{
// Call pre-apply hook
err := ctx.Hook(func(h Hook) (HookAction, error) {
@ -155,6 +161,7 @@ type EvalApplyProvisioners struct {
State **InstanceState
Resource *config.Resource
InterpResource *Resource
CreateNew *bool
Tainted *bool
Error *error
}
@ -173,6 +180,11 @@ func (n *EvalApplyProvisioners) Eval(
return nil, nil
}
if !*n.CreateNew {
// If we're not creating a new resource, then don't run provisioners
return nil, nil
}
{
// Call pre hook
err := ctx.Hook(func(h Hook) (HookAction, error) {

View File

@ -223,7 +223,7 @@ func (n *graphNodeExpandedResource) EvalTree() EvalNode {
var provider ResourceProvider
var diffApply *InstanceDiff
var err error
var tainted bool
var createNew, tainted bool
seq.Nodes = append(seq.Nodes, &EvalOpFilter{
Ops: []walkOperation{walkApply},
Node: &EvalSequence{
@ -259,13 +259,14 @@ func (n *graphNodeExpandedResource) EvalTree() EvalNode {
Output: &state,
},
&EvalApply{
Info: info,
State: &state,
Diff: &diffApply,
Provider: &provider,
Output: &state,
Error: &err,
Tainted: &tainted,
Info: info,
State: &state,
Diff: &diffApply,
Provider: &provider,
Output: &state,
Error: &err,
CreateNew: &createNew,
Tainted: &tainted,
},
&EvalWriteState{
Name: n.stateId(),
@ -278,6 +279,7 @@ func (n *graphNodeExpandedResource) EvalTree() EvalNode {
State: &state,
Resource: n.Resource,
InterpResource: resource,
CreateNew: &createNew,
Tainted: &tainted,
Error: &err,
},