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
|
||||
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")
|
||||
|
|
|
@ -17,6 +17,7 @@ type EvalApply struct {
|
|||
Diff **InstanceDiff
|
||||
Provider *ResourceProvider
|
||||
Output **InstanceState
|
||||
CreateNew *bool
|
||||
Error *error
|
||||
Tainted *bool
|
||||
}
|
||||
|
@ -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) {
|
||||
|
|
|
@ -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{
|
||||
|
@ -265,6 +265,7 @@ func (n *graphNodeExpandedResource) EvalTree() EvalNode {
|
|||
Provider: &provider,
|
||||
Output: &state,
|
||||
Error: &err,
|
||||
CreateNew: &createNew,
|
||||
Tainted: &tainted,
|
||||
},
|
||||
&EvalWriteState{
|
||||
|
@ -278,6 +279,7 @@ func (n *graphNodeExpandedResource) EvalTree() EvalNode {
|
|||
State: &state,
|
||||
Resource: n.Resource,
|
||||
InterpResource: resource,
|
||||
CreateNew: &createNew,
|
||||
Tainted: &tainted,
|
||||
Error: &err,
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue