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:
Mitchell Hashimoto 2016-11-01 22:42:41 -07:00
parent 61a1501731
commit 9e5d1f10b0
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
4 changed files with 65 additions and 0 deletions

View File

@ -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")

View File

@ -501,6 +501,14 @@ Outputs:
foo = bar
`
const testTerraformApplyOutputOrphanModuleStr = `
module.child:
<no state>
Outputs:
foo = bar
`
const testTerraformApplyProvisionerStr = `
aws_instance.bar:
ID = foo

View File

@ -0,0 +1 @@
output "foo" { value = "bar" }

View File

@ -0,0 +1,3 @@
module "child" {
source = "./child"
}