mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-13 09:32:24 -06:00
terraform: test that dependencies in the state are enough to maintain
order
This commit is contained in:
parent
cfd3be4856
commit
bcfec4e24e
@ -164,6 +164,95 @@ func TestContext2Apply_resourceDependsOnModule(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test that without a config, the Dependencies in the state are enough
|
||||
// to maintain proper ordering.
|
||||
func TestContext2Apply_resourceDependsOnModuleStateOnly(t *testing.T) {
|
||||
m := testModule(t, "apply-resource-depends-on-module-empty")
|
||||
p := testProvider("aws")
|
||||
p.DiffFn = testDiffFn
|
||||
|
||||
state := &State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.a": &ResourceState{
|
||||
Type: "aws_instance",
|
||||
Primary: &InstanceState{
|
||||
ID: "bar",
|
||||
},
|
||||
Dependencies: []string{"module.child"},
|
||||
},
|
||||
},
|
||||
},
|
||||
&ModuleState{
|
||||
Path: []string{"root", "child"},
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.child": &ResourceState{
|
||||
Type: "aws_instance",
|
||||
Primary: &InstanceState{
|
||||
ID: "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
{
|
||||
// Wait for the dependency, sleep, and verify the graph never
|
||||
// called a child.
|
||||
var called int32
|
||||
var checked bool
|
||||
p.ApplyFn = func(
|
||||
info *InstanceInfo,
|
||||
is *InstanceState,
|
||||
id *InstanceDiff) (*InstanceState, error) {
|
||||
if info.HumanId() == "aws_instance.a" {
|
||||
checked = true
|
||||
|
||||
// Sleep to allow parallel execution
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
// Verify that called is 0 (dep not called)
|
||||
if atomic.LoadInt32(&called) != 0 {
|
||||
return nil, fmt.Errorf("module child should not be called")
|
||||
}
|
||||
}
|
||||
|
||||
atomic.AddInt32(&called, 1)
|
||||
return testApplyFn(info, is, id)
|
||||
}
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
State: state,
|
||||
})
|
||||
|
||||
if _, err := ctx.Plan(); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
state, err := ctx.Apply()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
if !checked {
|
||||
t.Fatal("should check")
|
||||
}
|
||||
|
||||
checkStateString(t, state, `
|
||||
<no state>
|
||||
module.child:
|
||||
<no state>
|
||||
`)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Apply_resourceDependsOnModuleDestroy(t *testing.T) {
|
||||
m := testModule(t, "apply-resource-depends-on-module")
|
||||
p := testProvider("aws")
|
||||
|
@ -0,0 +1 @@
|
||||
# Empty!
|
Loading…
Reference in New Issue
Block a user