failing test for cbd cycle
This commit is contained in:
parent
9451f8ae74
commit
71f4526ae5
|
@ -11099,3 +11099,121 @@ func TestContext2Apply_taintedDestroyFailure(t *testing.T) {
|
||||||
t.Fatalf("unexpected attrs for c: %q\n", c.Current.AttrsJSON)
|
t.Fatalf("unexpected attrs for c: %q\n", c.Current.AttrsJSON)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContext2Apply_cbdCycle(t *testing.T) {
|
||||||
|
m, snap := testModuleWithSnapshot(t, "apply-cbd-cycle")
|
||||||
|
p := testProvider("test")
|
||||||
|
p.ApplyFn = testApplyFn
|
||||||
|
p.DiffFn = testDiffFn
|
||||||
|
|
||||||
|
state := states.NewState()
|
||||||
|
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||||
|
root.SetResourceInstanceCurrent(
|
||||||
|
addrs.Resource{
|
||||||
|
Mode: addrs.ManagedResourceMode,
|
||||||
|
Type: "test_instance",
|
||||||
|
Name: "a",
|
||||||
|
}.Instance(addrs.NoKey),
|
||||||
|
&states.ResourceInstanceObjectSrc{
|
||||||
|
Status: states.ObjectReady,
|
||||||
|
AttrsJSON: []byte(`{"id":"a","require_new":"old","foo":"b"}`),
|
||||||
|
Dependencies: []addrs.AbsResource{
|
||||||
|
addrs.AbsResource{
|
||||||
|
Resource: addrs.Resource{
|
||||||
|
Mode: addrs.ManagedResourceMode,
|
||||||
|
Type: "test_instance",
|
||||||
|
Name: "b",
|
||||||
|
},
|
||||||
|
Module: addrs.RootModuleInstance,
|
||||||
|
},
|
||||||
|
addrs.AbsResource{
|
||||||
|
Resource: addrs.Resource{
|
||||||
|
Mode: addrs.ManagedResourceMode,
|
||||||
|
Type: "test_instance",
|
||||||
|
Name: "c",
|
||||||
|
},
|
||||||
|
Module: addrs.RootModuleInstance,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
addrs.ProviderConfig{
|
||||||
|
Type: "test",
|
||||||
|
}.Absolute(addrs.RootModuleInstance),
|
||||||
|
)
|
||||||
|
root.SetResourceInstanceCurrent(
|
||||||
|
addrs.Resource{
|
||||||
|
Mode: addrs.ManagedResourceMode,
|
||||||
|
Type: "test_instance",
|
||||||
|
Name: "b",
|
||||||
|
}.Instance(addrs.NoKey),
|
||||||
|
&states.ResourceInstanceObjectSrc{
|
||||||
|
Status: states.ObjectReady,
|
||||||
|
AttrsJSON: []byte(`{"id":"b","require_new":"old","foo":"c"}`),
|
||||||
|
Dependencies: []addrs.AbsResource{
|
||||||
|
addrs.AbsResource{
|
||||||
|
Resource: addrs.Resource{
|
||||||
|
Mode: addrs.ManagedResourceMode,
|
||||||
|
Type: "test_instance",
|
||||||
|
Name: "c",
|
||||||
|
},
|
||||||
|
Module: addrs.RootModuleInstance,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
addrs.ProviderConfig{
|
||||||
|
Type: "test",
|
||||||
|
}.Absolute(addrs.RootModuleInstance),
|
||||||
|
)
|
||||||
|
root.SetResourceInstanceCurrent(
|
||||||
|
addrs.Resource{
|
||||||
|
Mode: addrs.ManagedResourceMode,
|
||||||
|
Type: "test_instance",
|
||||||
|
Name: "c",
|
||||||
|
}.Instance(addrs.NoKey),
|
||||||
|
&states.ResourceInstanceObjectSrc{
|
||||||
|
Status: states.ObjectReady,
|
||||||
|
AttrsJSON: []byte(`{"id":"c","require_new":"old"}`),
|
||||||
|
},
|
||||||
|
addrs.ProviderConfig{
|
||||||
|
Type: "test",
|
||||||
|
}.Absolute(addrs.RootModuleInstance),
|
||||||
|
)
|
||||||
|
|
||||||
|
providerResolver := providers.ResolverFixed(
|
||||||
|
map[string]providers.Factory{
|
||||||
|
"test": testProviderFuncFixed(p),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
hook := &testHook{}
|
||||||
|
ctx := testContext2(t, &ContextOpts{
|
||||||
|
Config: m,
|
||||||
|
ProviderResolver: providerResolver,
|
||||||
|
State: state,
|
||||||
|
Hooks: []Hook{hook},
|
||||||
|
})
|
||||||
|
|
||||||
|
plan, diags := ctx.Plan()
|
||||||
|
diags.HasErrors()
|
||||||
|
if diags.HasErrors() {
|
||||||
|
t.Fatalf("diags: %s", diags.Err())
|
||||||
|
}
|
||||||
|
|
||||||
|
// We'll marshal and unmarshal the plan here, to ensure that we have
|
||||||
|
// a clean new context as would be created if we separately ran
|
||||||
|
// terraform plan -out=tfplan && terraform apply tfplan
|
||||||
|
ctxOpts, err := contextOptsForPlanViaFile(snap, state, plan)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
ctxOpts.ProviderResolver = providerResolver
|
||||||
|
ctx, diags = NewContext(ctxOpts)
|
||||||
|
if diags.HasErrors() {
|
||||||
|
t.Fatalf("failed to create context for plan: %s", diags.Err())
|
||||||
|
}
|
||||||
|
|
||||||
|
_, diags = ctx.Apply()
|
||||||
|
if diags.HasErrors() {
|
||||||
|
t.Fatalf("diags: %s", diags.Err())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
resource "test_instance" "a" {
|
||||||
|
foo = test_instance.b.id
|
||||||
|
require_new = "changed"
|
||||||
|
|
||||||
|
lifecycle {
|
||||||
|
create_before_destroy = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "test_instance" "b" {
|
||||||
|
foo = test_instance.c.id
|
||||||
|
require_new = "changed"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
resource "test_instance" "c" {
|
||||||
|
require_new = "changed"
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue