terraform: provisioners should only be run on first create
This commit is contained in:
parent
c70cc682ea
commit
e2abf17c9c
|
@ -3581,9 +3581,8 @@ func TestContext2Apply_provisionerResourceRef(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
// Provisioner should NOT run on a diff, only create
|
// 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")
|
m := testModule(t, "apply-provisioner-diff")
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
pr := testProvisioner()
|
pr := testProvisioner()
|
||||||
|
@ -3592,7 +3591,7 @@ func TestContextApply_Provisioner_Diff(t *testing.T) {
|
||||||
pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error {
|
pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
ctx := testContext(t, &ContextOpts{
|
ctx := testContext2(t, &ContextOpts{
|
||||||
Module: m,
|
Module: m,
|
||||||
Providers: map[string]ResourceProviderFactory{
|
Providers: map[string]ResourceProviderFactory{
|
||||||
"aws": testProviderFuncFixed(p),
|
"aws": testProviderFuncFixed(p),
|
||||||
|
@ -3628,7 +3627,7 @@ func TestContextApply_Provisioner_Diff(t *testing.T) {
|
||||||
mod.Resources["aws_instance.bar"].Primary.Attributes["foo"] = "baz"
|
mod.Resources["aws_instance.bar"].Primary.Attributes["foo"] = "baz"
|
||||||
|
|
||||||
// Re-create context with state
|
// Re-create context with state
|
||||||
ctx = testContext(t, &ContextOpts{
|
ctx = testContext2(t, &ContextOpts{
|
||||||
Module: m,
|
Module: m,
|
||||||
Providers: map[string]ResourceProviderFactory{
|
Providers: map[string]ResourceProviderFactory{
|
||||||
"aws": testProviderFuncFixed(p),
|
"aws": testProviderFuncFixed(p),
|
||||||
|
@ -3659,6 +3658,7 @@ func TestContextApply_Provisioner_Diff(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
func TestContextApply_outputDiffVars(t *testing.T) {
|
func TestContextApply_outputDiffVars(t *testing.T) {
|
||||||
m := testModule(t, "apply-good")
|
m := testModule(t, "apply-good")
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
|
|
|
@ -12,13 +12,14 @@ import (
|
||||||
// EvalApply is an EvalNode implementation that writes the diff to
|
// EvalApply is an EvalNode implementation that writes the diff to
|
||||||
// the full diff.
|
// the full diff.
|
||||||
type EvalApply struct {
|
type EvalApply struct {
|
||||||
Info *InstanceInfo
|
Info *InstanceInfo
|
||||||
State **InstanceState
|
State **InstanceState
|
||||||
Diff **InstanceDiff
|
Diff **InstanceDiff
|
||||||
Provider *ResourceProvider
|
Provider *ResourceProvider
|
||||||
Output **InstanceState
|
Output **InstanceState
|
||||||
Error *error
|
CreateNew *bool
|
||||||
Tainted *bool
|
Error *error
|
||||||
|
Tainted *bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *EvalApply) Args() ([]EvalNode, []EvalType) {
|
func (n *EvalApply) Args() ([]EvalNode, []EvalType) {
|
||||||
|
@ -52,6 +53,11 @@ func (n *EvalApply) Eval(
|
||||||
}
|
}
|
||||||
state.init()
|
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
|
// Call pre-apply hook
|
||||||
err := ctx.Hook(func(h Hook) (HookAction, error) {
|
err := ctx.Hook(func(h Hook) (HookAction, error) {
|
||||||
|
@ -155,6 +161,7 @@ type EvalApplyProvisioners struct {
|
||||||
State **InstanceState
|
State **InstanceState
|
||||||
Resource *config.Resource
|
Resource *config.Resource
|
||||||
InterpResource *Resource
|
InterpResource *Resource
|
||||||
|
CreateNew *bool
|
||||||
Tainted *bool
|
Tainted *bool
|
||||||
Error *error
|
Error *error
|
||||||
}
|
}
|
||||||
|
@ -173,6 +180,11 @@ func (n *EvalApplyProvisioners) Eval(
|
||||||
return nil, nil
|
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
|
// Call pre hook
|
||||||
err := ctx.Hook(func(h Hook) (HookAction, error) {
|
err := ctx.Hook(func(h Hook) (HookAction, error) {
|
||||||
|
|
|
@ -223,7 +223,7 @@ func (n *graphNodeExpandedResource) EvalTree() EvalNode {
|
||||||
var provider ResourceProvider
|
var provider ResourceProvider
|
||||||
var diffApply *InstanceDiff
|
var diffApply *InstanceDiff
|
||||||
var err error
|
var err error
|
||||||
var tainted bool
|
var createNew, tainted bool
|
||||||
seq.Nodes = append(seq.Nodes, &EvalOpFilter{
|
seq.Nodes = append(seq.Nodes, &EvalOpFilter{
|
||||||
Ops: []walkOperation{walkApply},
|
Ops: []walkOperation{walkApply},
|
||||||
Node: &EvalSequence{
|
Node: &EvalSequence{
|
||||||
|
@ -259,13 +259,14 @@ func (n *graphNodeExpandedResource) EvalTree() EvalNode {
|
||||||
Output: &state,
|
Output: &state,
|
||||||
},
|
},
|
||||||
&EvalApply{
|
&EvalApply{
|
||||||
Info: info,
|
Info: info,
|
||||||
State: &state,
|
State: &state,
|
||||||
Diff: &diffApply,
|
Diff: &diffApply,
|
||||||
Provider: &provider,
|
Provider: &provider,
|
||||||
Output: &state,
|
Output: &state,
|
||||||
Error: &err,
|
Error: &err,
|
||||||
Tainted: &tainted,
|
CreateNew: &createNew,
|
||||||
|
Tainted: &tainted,
|
||||||
},
|
},
|
||||||
&EvalWriteState{
|
&EvalWriteState{
|
||||||
Name: n.stateId(),
|
Name: n.stateId(),
|
||||||
|
@ -278,6 +279,7 @@ func (n *graphNodeExpandedResource) EvalTree() EvalNode {
|
||||||
State: &state,
|
State: &state,
|
||||||
Resource: n.Resource,
|
Resource: n.Resource,
|
||||||
InterpResource: resource,
|
InterpResource: resource,
|
||||||
|
CreateNew: &createNew,
|
||||||
Tainted: &tainted,
|
Tainted: &tainted,
|
||||||
Error: &err,
|
Error: &err,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue