Merge pull request #17642 from hashicorp/jbardin/GH-17462

remove more unneeded partial outputs
This commit is contained in:
James Bardin 2018-03-20 11:11:54 -04:00 committed by GitHub
commit 38e6309f03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 0 deletions

View File

@ -2969,6 +2969,28 @@ STATE:
} }
} }
// ensure that outputs missing references due to targetting are removed from
// the graph.
func TestContext2Plan_outputContainsTargetedResource(t *testing.T) {
m := testModule(t, "plan-untargeted-resource-output")
p := testProvider("aws")
p.DiffFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Module: m,
ProviderResolver: ResourceProviderResolverFixed(
map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
),
Targets: []string{"module.mod.aws_instance.a"},
})
_, err := ctx.Plan()
if err != nil {
t.Fatalf("err: %s", err)
}
}
// https://github.com/hashicorp/terraform/issues/4515 // https://github.com/hashicorp/terraform/issues/4515
func TestContext2Plan_targetedOverTen(t *testing.T) { func TestContext2Plan_targetedOverTen(t *testing.T) {
m := testModule(t, "plan-targeted-over-ten") m := testModule(t, "plan-targeted-over-ten")

View File

@ -0,0 +1,8 @@
module "mod" {
source = "./mod"
}
resource "aws_instance" "c" {
name = "${module.mod.output}"
}

View File

@ -0,0 +1,15 @@
locals {
"one" = 1
}
resource "aws_instance" "a" {
count = "${local.one}"
}
resource "aws_instance" "b" {
count = "${local.one}"
}
output "output" {
value = "${join("", coalescelist(aws_instance.a.*.id, aws_instance.b.*.id))}"
}

View File

@ -217,6 +217,12 @@ func filterPartialOutputs(v interface{}, targetedNodes *dag.Set, g *Graph) bool
if _, ok := d.(*NodeCountBoundary); ok { if _, ok := d.(*NodeCountBoundary); ok {
continue continue
} }
if !targetedNodes.Include(d) {
// this one is going to be removed, so it doesn't count
continue
}
// as soon as we see a real dependency, we mark this as // as soon as we see a real dependency, we mark this as
// non-removable // non-removable
return true return true