improve failing test
Correct the initial test state, and expand the test to cause a cycle without the previous fix.
This commit is contained in:
parent
2ea921f915
commit
67fd32db7e
|
@ -11390,18 +11390,29 @@ variable "ct" {
|
|||
|
||||
resource "test_instance" "a" {
|
||||
count = var.ct
|
||||
}
|
||||
|
||||
resource "test_instance" "b" {
|
||||
require_new = local.removable
|
||||
lifecycle {
|
||||
create_before_destroy = true
|
||||
}
|
||||
}
|
||||
|
||||
resource "test_instance" "b" {
|
||||
foo = join(".", test_instance.a[*].id)
|
||||
resource "test_instance" "c" {
|
||||
require_new = test_instance.b.id
|
||||
lifecycle {
|
||||
create_before_destroy = true
|
||||
}
|
||||
}
|
||||
|
||||
output "out" {
|
||||
value = join(".", test_instance.a[*].id)
|
||||
}
|
||||
|
||||
locals {
|
||||
removable = join(".", test_instance.a[*].id)
|
||||
}
|
||||
`})
|
||||
|
||||
state := states.NewState()
|
||||
|
@ -11411,7 +11422,8 @@ output "out" {
|
|||
&states.ResourceInstanceObjectSrc{
|
||||
Status: states.ObjectReady,
|
||||
AttrsJSON: []byte(`{"id":"a0"}`),
|
||||
Dependencies: []addrs.ConfigResource{mustResourceAddr("module.child.aws_instance.child")},
|
||||
Dependencies: []addrs.ConfigResource{},
|
||||
CreateBeforeDestroy: true,
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
|
@ -11420,7 +11432,8 @@ output "out" {
|
|||
&states.ResourceInstanceObjectSrc{
|
||||
Status: states.ObjectReady,
|
||||
AttrsJSON: []byte(`{"id":"a1"}`),
|
||||
Dependencies: []addrs.ConfigResource{mustResourceAddr("module.child.aws_instance.child")},
|
||||
Dependencies: []addrs.ConfigResource{},
|
||||
CreateBeforeDestroy: true,
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
|
@ -11428,8 +11441,22 @@ output "out" {
|
|||
mustResourceInstanceAddr("test_instance.b").Resource,
|
||||
&states.ResourceInstanceObjectSrc{
|
||||
Status: states.ObjectReady,
|
||||
AttrsJSON: []byte(`{"id":"b", "foo":"old.old"}`),
|
||||
AttrsJSON: []byte(`{"id":"b", "require_new":"old.old"}`),
|
||||
Dependencies: []addrs.ConfigResource{mustResourceAddr("test_instance.a")},
|
||||
CreateBeforeDestroy: true,
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
root.SetResourceInstanceCurrent(
|
||||
mustResourceInstanceAddr("test_instance.c").Resource,
|
||||
&states.ResourceInstanceObjectSrc{
|
||||
Status: states.ObjectReady,
|
||||
AttrsJSON: []byte(`{"id":"c", "require_new":"b"}`),
|
||||
Dependencies: []addrs.ConfigResource{
|
||||
mustResourceAddr("test_instance.a"),
|
||||
mustResourceAddr("test_instance.b"),
|
||||
},
|
||||
CreateBeforeDestroy: true,
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
|
@ -11443,7 +11470,7 @@ output "out" {
|
|||
ctx := testContext2(t, &ContextOpts{
|
||||
Variables: InputValues{
|
||||
"ct": &InputValue{
|
||||
Value: cty.NumberIntVal(1),
|
||||
Value: cty.NumberIntVal(0),
|
||||
SourceType: ValueFromCaller,
|
||||
},
|
||||
},
|
||||
|
@ -11462,6 +11489,11 @@ output "out" {
|
|||
// if resource b isn't going to apply correctly, we will get an error about
|
||||
// an invalid plan value
|
||||
state, diags = ctx.Apply()
|
||||
errMsg := diags.ErrWithWarnings().Error()
|
||||
if strings.Contains(errMsg, "Cycle") {
|
||||
t.Fatal("test should not produce a cycle:\n", errMsg)
|
||||
}
|
||||
|
||||
if !diags.HasErrors() {
|
||||
// FIXME: this test is correct, but needs to wait until we no longer
|
||||
// evaluate resourced that are pending destruction.
|
||||
|
|
Loading…
Reference in New Issue