mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 17:01:04 -06:00
terraform: add test to verify orphan outputs in modules are removed
For #7598 This doesn't work with the old graph, we guard it as such.
This commit is contained in:
parent
61a1501731
commit
9e5d1f10b0
@ -12,6 +12,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/terraform/config/module"
|
||||
"github.com/hashicorp/terraform/helper/experiment"
|
||||
)
|
||||
|
||||
func TestContext2Apply_basic(t *testing.T) {
|
||||
@ -2113,6 +2114,58 @@ func TestContext2Apply_outputOrphan(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Apply_outputOrphanModule(t *testing.T) {
|
||||
if !experiment.Enabled(experiment.X_newApply) {
|
||||
t.SkipNow()
|
||||
}
|
||||
|
||||
m := testModule(t, "apply-output-orphan-module")
|
||||
p := testProvider("aws")
|
||||
p.ApplyFn = testApplyFn
|
||||
p.DiffFn = testDiffFn
|
||||
|
||||
state := &State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: []string{"root", "child"},
|
||||
Outputs: map[string]*OutputState{
|
||||
"foo": &OutputState{
|
||||
Type: "string",
|
||||
Value: "bar",
|
||||
},
|
||||
"bar": &OutputState{
|
||||
Type: "string",
|
||||
Value: "baz",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
actual := strings.TrimSpace(state.String())
|
||||
expected := strings.TrimSpace(testTerraformApplyOutputOrphanModuleStr)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad: \n%s", actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Apply_providerComputedVar(t *testing.T) {
|
||||
m := testModule(t, "apply-provider-computed")
|
||||
p := testProvider("aws")
|
||||
|
@ -501,6 +501,14 @@ Outputs:
|
||||
foo = bar
|
||||
`
|
||||
|
||||
const testTerraformApplyOutputOrphanModuleStr = `
|
||||
module.child:
|
||||
<no state>
|
||||
Outputs:
|
||||
|
||||
foo = bar
|
||||
`
|
||||
|
||||
const testTerraformApplyProvisionerStr = `
|
||||
aws_instance.bar:
|
||||
ID = foo
|
||||
|
@ -0,0 +1 @@
|
||||
output "foo" { value = "bar" }
|
@ -0,0 +1,3 @@
|
||||
module "child" {
|
||||
source = "./child"
|
||||
}
|
Loading…
Reference in New Issue
Block a user