mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
allow evaluation of 0 instances during apply
While this was easier to spot during plan, it is also possible to evaluate resources with 0 instances during apply as well. This doesn't effect the failure when scaling CBD instances, it only changes the fact that the inconsistent value is no longer unknown.
This commit is contained in:
parent
7b2f66c403
commit
7156649336
@ -11912,3 +11912,66 @@ resource "test_instance" "b" {
|
||||
t.Fatalf("apply errors: %s", diags.Err())
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Apply_removeReferencedResource(t *testing.T) {
|
||||
m := testModuleInline(t, map[string]string{
|
||||
"main.tf": `
|
||||
variable "ct" {
|
||||
}
|
||||
|
||||
resource "test_resource" "to_remove" {
|
||||
count = var.ct
|
||||
}
|
||||
|
||||
resource "test_resource" "c" {
|
||||
value = join("", test_resource.to_remove[*].id)
|
||||
}
|
||||
`})
|
||||
|
||||
p := testProvider("test")
|
||||
p.ApplyFn = testApplyFn
|
||||
p.DiffFn = testDiffFn
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
|
||||
},
|
||||
Variables: InputValues{
|
||||
"ct": &InputValue{
|
||||
Value: cty.NumberIntVal(1),
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if _, diags := ctx.Plan(); diags.HasErrors() {
|
||||
t.Fatalf("plan errors: %s", diags.Err())
|
||||
}
|
||||
|
||||
state, diags := ctx.Apply()
|
||||
if diags.HasErrors() {
|
||||
t.Fatalf("apply errors: %s", diags.Err())
|
||||
}
|
||||
|
||||
ctx = testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
|
||||
},
|
||||
Variables: InputValues{
|
||||
"ct": &InputValue{
|
||||
Value: cty.NumberIntVal(0),
|
||||
},
|
||||
},
|
||||
State: state,
|
||||
})
|
||||
|
||||
if _, diags := ctx.Plan(); diags.HasErrors() {
|
||||
t.Fatalf("plan errors: %s", diags.Err())
|
||||
}
|
||||
|
||||
_, diags = ctx.Apply()
|
||||
if diags.HasErrors() {
|
||||
t.Fatalf("apply errors: %s", diags.Err())
|
||||
}
|
||||
}
|
||||
|
@ -648,12 +648,10 @@ func (d *evaluationStateData) GetResource(addr addrs.Resource, rng tfdiags.Sourc
|
||||
|
||||
if rs == nil {
|
||||
switch d.Operation {
|
||||
case walkPlan:
|
||||
// During plan as we evaluate each removed instance they are removed
|
||||
// from the temporary working state. Since we know there there are
|
||||
// no instances, and resources might be referenced in a context
|
||||
// that needs to be known during plan, return an empty container of
|
||||
// the expected type.
|
||||
case walkPlan, walkApply:
|
||||
// During plan and apply as we evaluate each removed instance they
|
||||
// are removed from the working state. Since we know there are no
|
||||
// instances, return an empty container of the expected type.
|
||||
switch {
|
||||
case config.Count != nil:
|
||||
return cty.EmptyTupleVal, diags
|
||||
|
Loading…
Reference in New Issue
Block a user