Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: move targets transform after flatten #2555

Merged
merged 1 commit into from
Jun 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions terraform/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6593,6 +6593,48 @@ module.child:
`)
}

// GH-1858
func TestContext2Apply_targetedModuleDep(t *testing.T) {
m := testModule(t, "apply-targeted-module-dep")
p := testProvider("aws")
p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
Targets: []string{"aws_instance.foo"},
})

if _, err := ctx.Plan(); err != nil {
t.Fatalf("err: %s", err)
}

state, err := ctx.Apply()
if err != nil {
t.Fatalf("err: %s", err)
}

checkStateString(t, state, `
aws_instance.foo:
ID = foo
foo = foo
type = aws_instance

Dependencies:
module.child

module.child:
aws_instance.mod:
ID = foo

Outputs:

output = foo
`)
}

func TestContext2Apply_targetedModuleResource(t *testing.T) {
m := testModule(t, "apply-targeted-module-resource")
p := testProvider("aws")
Expand Down
8 changes: 4 additions & 4 deletions terraform/graph_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,6 @@ func (b *BuiltinGraphBuilder) Steps(path []string) []GraphTransformer {
// Make sure all the connections that are proxies are connected through
&ProxyTransformer{},

// Optionally reduces the graph to a user-specified list of targets and
// their dependencies.
&TargetsTransformer{Targets: b.Targets, Destroy: b.Destroy},

// Make sure we have a single root
&RootTransformer{},
}
Expand All @@ -152,6 +148,10 @@ func (b *BuiltinGraphBuilder) Steps(path []string) []GraphTransformer {
// We don't do the following for modules.
if len(path) <= 1 {
steps = append(steps,
// Optionally reduces the graph to a user-specified list of targets and
// their dependencies.
&TargetsTransformer{Targets: b.Targets, Destroy: b.Destroy},

// Prune the providers and provisioners. This must happen
// only once because flattened modules might depend on empty
// providers.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "aws_instance" "mod" { }

output "output" {
value = "${aws_instance.mod.id}"
}
7 changes: 7 additions & 0 deletions terraform/test-fixtures/apply-targeted-module-dep/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module "child" {
source = "./child"
}

resource "aws_instance" "foo" {
foo = "${module.child.output}"
}