terraform: don't include providers if not targeted
Fixes #12009 This is a simple change similar to #10911 where we need to exclude providers that aren't targeted.
This commit is contained in:
parent
d1ecaff6f6
commit
9062a1893e
|
@ -2519,6 +2519,39 @@ STATE:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContext2Plan_targetedModuleWithProvider(t *testing.T) {
|
||||||
|
m := testModule(t, "plan-targeted-module-with-provider")
|
||||||
|
p := testProvider("null")
|
||||||
|
p.DiffFn = testDiffFn
|
||||||
|
ctx := testContext2(t, &ContextOpts{
|
||||||
|
Module: m,
|
||||||
|
Providers: map[string]ResourceProviderFactory{
|
||||||
|
"null": testProviderFuncFixed(p),
|
||||||
|
},
|
||||||
|
Targets: []string{"module.child2"},
|
||||||
|
})
|
||||||
|
|
||||||
|
plan, err := ctx.Plan()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
actual := strings.TrimSpace(plan.String())
|
||||||
|
expected := strings.TrimSpace(`
|
||||||
|
DIFF:
|
||||||
|
|
||||||
|
module.child2:
|
||||||
|
CREATE: null_resource.foo
|
||||||
|
|
||||||
|
STATE:
|
||||||
|
|
||||||
|
<no state>
|
||||||
|
`)
|
||||||
|
if actual != expected {
|
||||||
|
t.Fatalf("expected:\n%s\n\ngot:\n%s", expected, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestContext2Plan_targetedOrphan(t *testing.T) {
|
func TestContext2Plan_targetedOrphan(t *testing.T) {
|
||||||
m := testModule(t, "plan-targeted-orphan")
|
m := testModule(t, "plan-targeted-orphan")
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
|
|
|
@ -33,6 +33,24 @@ func TestPlanGraphBuilder(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPlanGraphBuilder_targetModule(t *testing.T) {
|
||||||
|
b := &PlanGraphBuilder{
|
||||||
|
Module: testModule(t, "graph-builder-plan-target-module-provider"),
|
||||||
|
Providers: []string{"null"},
|
||||||
|
Targets: []string{"module.child2"},
|
||||||
|
}
|
||||||
|
|
||||||
|
g, err := b.Build(RootModulePath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Logf("Graph: %s", g.String())
|
||||||
|
|
||||||
|
testGraphNotContains(t, g, "module.child1.provider.null")
|
||||||
|
testGraphNotContains(t, g, "module.child1.null_resource.foo")
|
||||||
|
}
|
||||||
|
|
||||||
const testPlanGraphBuilderStr = `
|
const testPlanGraphBuilderStr = `
|
||||||
aws_instance.web
|
aws_instance.web
|
||||||
aws_security_group.firewall
|
aws_security_group.firewall
|
||||||
|
|
|
@ -38,6 +38,13 @@ func (n *NodeAbstractProvider) Path() []string {
|
||||||
return n.PathValue
|
return n.PathValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RemovableIfNotTargeted
|
||||||
|
func (n *NodeAbstractProvider) RemoveIfNotTargeted() bool {
|
||||||
|
// We need to add this so that this node will be removed if
|
||||||
|
// it isn't targeted or a dependency of a target.
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// GraphNodeReferencer
|
// GraphNodeReferencer
|
||||||
func (n *NodeAbstractProvider) References() []string {
|
func (n *NodeAbstractProvider) References() []string {
|
||||||
if n.Config == nil {
|
if n.Config == nil {
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
variable "key" {}
|
||||||
|
provider "null" { key = "${var.key}" }
|
||||||
|
|
||||||
|
resource "null_resource" "foo" {}
|
|
@ -0,0 +1,4 @@
|
||||||
|
variable "key" {}
|
||||||
|
provider "null" { key = "${var.key}" }
|
||||||
|
|
||||||
|
resource "null_resource" "foo" {}
|
|
@ -0,0 +1,2 @@
|
||||||
|
module "child1" { source = "./child1" }
|
||||||
|
module "child2" { source = "./child2" }
|
|
@ -0,0 +1,4 @@
|
||||||
|
variable "key" {}
|
||||||
|
provider "null" { key = "${var.key}" }
|
||||||
|
|
||||||
|
resource "null_resource" "foo" {}
|
|
@ -0,0 +1,4 @@
|
||||||
|
variable "key" {}
|
||||||
|
provider "null" { key = "${var.key}" }
|
||||||
|
|
||||||
|
resource "null_resource" "foo" {}
|
|
@ -0,0 +1,9 @@
|
||||||
|
module "child1" {
|
||||||
|
source = "./child1"
|
||||||
|
key = "value"
|
||||||
|
}
|
||||||
|
|
||||||
|
module "child2" {
|
||||||
|
source = "./child2"
|
||||||
|
key = "value"
|
||||||
|
}
|
Loading…
Reference in New Issue