mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-25 08:21:07 -06:00
terraform: passing test for destroy edge for module only
Just adding passing tests as a sanity check for a bug.
This commit is contained in:
parent
ac3d67e40f
commit
af61d566c2
@ -0,0 +1,8 @@
|
||||
resource "aws_instance" "a" {}
|
||||
resource "aws_instance" "b" {
|
||||
value = "${aws_instance.a.id}"
|
||||
}
|
||||
|
||||
resource "aws_instance" "c" {
|
||||
value = "${aws_instance.b.id}"
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
module "child" {
|
||||
source = "./child"
|
||||
}
|
@ -45,12 +45,11 @@ func (t *AttachStateTransformer) Transform(g *Graph) error {
|
||||
}
|
||||
|
||||
// Attach the first resource state we get
|
||||
log.Printf("SEARCH: %s", addr)
|
||||
found := false
|
||||
for _, result := range results {
|
||||
if rs, ok := result.Value.(*ResourceState); ok {
|
||||
log.Printf(
|
||||
"[DEBUG] Attaching resource state to %q: %s",
|
||||
"[DEBUG] Attaching resource state to %q: %#v",
|
||||
dag.VertexName(v), rs)
|
||||
an.AttachResourceState(rs)
|
||||
found = true
|
||||
|
@ -96,6 +96,32 @@ func TestDestroyEdgeTransformer_module(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDestroyEdgeTransformer_moduleOnly(t *testing.T) {
|
||||
g := Graph{Path: RootModulePath}
|
||||
g.Add(&graphNodeDestroyerTest{AddrString: "module.child.aws_instance.a"})
|
||||
g.Add(&graphNodeDestroyerTest{AddrString: "module.child.aws_instance.b"})
|
||||
g.Add(&graphNodeDestroyerTest{AddrString: "module.child.aws_instance.c"})
|
||||
tf := &DestroyEdgeTransformer{
|
||||
Module: testModule(t, "transform-destroy-edge-module-only"),
|
||||
}
|
||||
if err := tf.Transform(&g); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
actual := strings.TrimSpace(g.String())
|
||||
expected := strings.TrimSpace(`
|
||||
module.child.aws_instance.a (destroy)
|
||||
module.child.aws_instance.b (destroy)
|
||||
module.child.aws_instance.c (destroy)
|
||||
module.child.aws_instance.b (destroy)
|
||||
module.child.aws_instance.c (destroy)
|
||||
module.child.aws_instance.c (destroy)
|
||||
`)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad:\n\n%s", actual)
|
||||
}
|
||||
}
|
||||
|
||||
type graphNodeCreatorTest struct {
|
||||
AddrString string
|
||||
Refs []string
|
||||
|
Loading…
Reference in New Issue
Block a user