diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index bd7e8049d..8ece50adb 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -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") diff --git a/terraform/terraform_test.go b/terraform/terraform_test.go index 52f17bdb4..56386641f 100644 --- a/terraform/terraform_test.go +++ b/terraform/terraform_test.go @@ -501,6 +501,14 @@ Outputs: foo = bar ` +const testTerraformApplyOutputOrphanModuleStr = ` +module.child: + + Outputs: + + foo = bar +` + const testTerraformApplyProvisionerStr = ` aws_instance.bar: ID = foo diff --git a/terraform/test-fixtures/apply-output-orphan-module/child/main.tf b/terraform/test-fixtures/apply-output-orphan-module/child/main.tf new file mode 100644 index 000000000..70619c4e3 --- /dev/null +++ b/terraform/test-fixtures/apply-output-orphan-module/child/main.tf @@ -0,0 +1 @@ +output "foo" { value = "bar" } diff --git a/terraform/test-fixtures/apply-output-orphan-module/main.tf b/terraform/test-fixtures/apply-output-orphan-module/main.tf new file mode 100644 index 000000000..0f6991c53 --- /dev/null +++ b/terraform/test-fixtures/apply-output-orphan-module/main.tf @@ -0,0 +1,3 @@ +module "child" { + source = "./child" +}