mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-25 08:21:07 -06:00
test for incorrectly evaluated outputs
This commit is contained in:
parent
333bdecf39
commit
a0723442b9
@ -1485,3 +1485,105 @@ resource "test_object" "y" {
|
||||
_, diags = ctx.Apply(plan, m)
|
||||
assertNoErrors(t, diags)
|
||||
}
|
||||
|
||||
// Outputs should not cause evaluation errors during destroy
|
||||
// Check eval from both root level outputs and module outputs, which are
|
||||
// handled differently during apply.
|
||||
func TestContext2Apply_outputsNotToEvaluate(t *testing.T) {
|
||||
m := testModuleInline(t, map[string]string{
|
||||
"main.tf": `
|
||||
module "mod" {
|
||||
source = "./mod"
|
||||
cond = false
|
||||
}
|
||||
|
||||
output "from_resource" {
|
||||
value = module.mod.from_resource
|
||||
}
|
||||
|
||||
output "from_data" {
|
||||
value = module.mod.from_data
|
||||
}
|
||||
`,
|
||||
|
||||
"./mod/main.tf": `
|
||||
variable "cond" {
|
||||
type = bool
|
||||
}
|
||||
|
||||
module "mod" {
|
||||
source = "../mod2/"
|
||||
cond = var.cond
|
||||
}
|
||||
|
||||
output "from_resource" {
|
||||
value = module.mod.resource
|
||||
}
|
||||
|
||||
output "from_data" {
|
||||
value = module.mod.data
|
||||
}
|
||||
`,
|
||||
|
||||
"./mod2/main.tf": `
|
||||
variable "cond" {
|
||||
type = bool
|
||||
}
|
||||
|
||||
resource "test_object" "x" {
|
||||
count = var.cond ? 0:1
|
||||
}
|
||||
|
||||
data "test_object" "d" {
|
||||
count = var.cond ? 0:1
|
||||
}
|
||||
|
||||
output "resource" {
|
||||
value = var.cond ? null : test_object.x.*.test_string[0]
|
||||
}
|
||||
|
||||
output "data" {
|
||||
value = one(data.test_object.d[*].test_string)
|
||||
}
|
||||
`})
|
||||
|
||||
p := simpleMockProvider()
|
||||
p.ReadDataSourceFn = func(req providers.ReadDataSourceRequest) (resp providers.ReadDataSourceResponse) {
|
||||
resp.State = req.Config
|
||||
return resp
|
||||
}
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
// apply the state
|
||||
opts := SimplePlanOpts(plans.NormalMode, nil)
|
||||
plan, diags := ctx.Plan(m, states.NewState(), opts)
|
||||
assertNoErrors(t, diags)
|
||||
|
||||
state, diags := ctx.Apply(plan, m)
|
||||
assertNoErrors(t, diags)
|
||||
|
||||
// and destroy
|
||||
opts = SimplePlanOpts(plans.DestroyMode, nil)
|
||||
plan, diags = ctx.Plan(m, state, opts)
|
||||
assertNoErrors(t, diags)
|
||||
|
||||
state, diags = ctx.Apply(plan, m)
|
||||
assertNoErrors(t, diags)
|
||||
|
||||
// and destroy again with no state
|
||||
if !state.Empty() {
|
||||
t.Fatal("expected empty state, got", state)
|
||||
}
|
||||
|
||||
opts = SimplePlanOpts(plans.DestroyMode, nil)
|
||||
plan, diags = ctx.Plan(m, state, opts)
|
||||
assertNoErrors(t, diags)
|
||||
|
||||
_, diags = ctx.Apply(plan, m)
|
||||
assertNoErrors(t, diags)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user