Merge pull request #5516 from hashicorp/phinze/tainted-target-bug
core: Encode Targets in saved Planfile
This commit is contained in:
commit
ad0836be6f
|
@ -319,6 +319,7 @@ func (c *Context) Plan() (*Plan, error) {
|
||||||
Module: c.module,
|
Module: c.module,
|
||||||
Vars: c.variables,
|
Vars: c.variables,
|
||||||
State: c.state,
|
State: c.state,
|
||||||
|
Targets: c.targets,
|
||||||
}
|
}
|
||||||
|
|
||||||
var operation walkOperation
|
var operation walkOperation
|
||||||
|
|
|
@ -4015,3 +4015,72 @@ template_file.parent:
|
||||||
t.Fatalf("expected state: \n%s\ngot: \n%s", expected, actual)
|
t.Fatalf("expected state: \n%s\ngot: \n%s", expected, actual)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContext2Apply_targetedWithTaintedInState(t *testing.T) {
|
||||||
|
p := testProvider("aws")
|
||||||
|
p.DiffFn = testDiffFn
|
||||||
|
p.ApplyFn = testApplyFn
|
||||||
|
ctx := testContext2(t, &ContextOpts{
|
||||||
|
Module: testModule(t, "apply-tainted-targets"),
|
||||||
|
Providers: map[string]ResourceProviderFactory{
|
||||||
|
"aws": testProviderFuncFixed(p),
|
||||||
|
},
|
||||||
|
Targets: []string{"aws_instance.iambeingadded"},
|
||||||
|
State: &State{
|
||||||
|
Modules: []*ModuleState{
|
||||||
|
&ModuleState{
|
||||||
|
Path: rootModulePath,
|
||||||
|
Resources: map[string]*ResourceState{
|
||||||
|
"aws_instance.ifailedprovisioners": &ResourceState{
|
||||||
|
Tainted: []*InstanceState{
|
||||||
|
&InstanceState{
|
||||||
|
ID: "ifailedprovisioners",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
plan, err := ctx.Plan()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write / Read plan to simulate running it through a Plan file
|
||||||
|
var buf bytes.Buffer
|
||||||
|
if err := WritePlan(plan, &buf); err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
planFromFile, err := ReadPlan(&buf)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx = planFromFile.Context(&ContextOpts{
|
||||||
|
Module: testModule(t, "apply-tainted-targets"),
|
||||||
|
Providers: map[string]ResourceProviderFactory{
|
||||||
|
"aws": testProviderFuncFixed(p),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
state, err := ctx.Apply()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
actual := strings.TrimSpace(state.String())
|
||||||
|
expected := strings.TrimSpace(`
|
||||||
|
aws_instance.iambeingadded:
|
||||||
|
ID = foo
|
||||||
|
aws_instance.ifailedprovisioners: (1 tainted)
|
||||||
|
ID = <not created>
|
||||||
|
Tainted ID 1 = ifailedprovisioners
|
||||||
|
`)
|
||||||
|
if actual != expected {
|
||||||
|
t.Fatalf("expected state: \n%s\ngot: \n%s", expected, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ type Plan struct {
|
||||||
Module *module.Tree
|
Module *module.Tree
|
||||||
State *State
|
State *State
|
||||||
Vars map[string]string
|
Vars map[string]string
|
||||||
|
Targets []string
|
||||||
|
|
||||||
once sync.Once
|
once sync.Once
|
||||||
}
|
}
|
||||||
|
@ -38,6 +39,7 @@ func (p *Plan) Context(opts *ContextOpts) *Context {
|
||||||
opts.Module = p.Module
|
opts.Module = p.Module
|
||||||
opts.State = p.State
|
opts.State = p.State
|
||||||
opts.Variables = p.Vars
|
opts.Variables = p.Vars
|
||||||
|
opts.Targets = p.Targets
|
||||||
return NewContext(opts)
|
return NewContext(opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
resource "aws_instance" "ifailedprovisioners" { }
|
||||||
|
|
||||||
|
resource "aws_instance" "iambeingadded" { }
|
|
@ -0,0 +1,5 @@
|
||||||
|
resource "aws_instance" "ifailedprovisioners" {
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_instance" "iambeingadded" {
|
||||||
|
}
|
Loading…
Reference in New Issue