Merge pull request #25258 from hashicorp/jbardin/module-refs
Whole module references
This commit is contained in:
commit
27012f7ee1
|
@ -5947,3 +5947,48 @@ resource "aws_instance" "foo" {
|
||||||
t.Errorf("missing %s change for %s", action, res)
|
t.Errorf("missing %s change for %s", action, res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContext2Plan_moduleRefIndex(t *testing.T) {
|
||||||
|
m := testModuleInline(t, map[string]string{
|
||||||
|
"main.tf": `
|
||||||
|
module "mod" {
|
||||||
|
for_each = {
|
||||||
|
a = "thing"
|
||||||
|
}
|
||||||
|
in = null
|
||||||
|
source = "./mod"
|
||||||
|
}
|
||||||
|
|
||||||
|
module "single" {
|
||||||
|
source = "./mod"
|
||||||
|
in = module.mod["a"]
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
"mod/main.tf": `
|
||||||
|
variable "in" {
|
||||||
|
}
|
||||||
|
|
||||||
|
output "out" {
|
||||||
|
value = "foo"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_instance" "foo" {
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
})
|
||||||
|
|
||||||
|
p := testProvider("aws")
|
||||||
|
p.DiffFn = testDiffFn
|
||||||
|
|
||||||
|
ctx := testContext2(t, &ContextOpts{
|
||||||
|
Config: m,
|
||||||
|
Providers: map[addrs.Provider]providers.Factory{
|
||||||
|
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
_, diags := ctx.Plan()
|
||||||
|
if diags.HasErrors() {
|
||||||
|
t.Fatal(diags.ErrWithWarnings())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -95,11 +95,7 @@ func (n *nodeExpandModuleVariable) ReferenceOutside() (selfPath, referencePath a
|
||||||
|
|
||||||
// GraphNodeReferenceable
|
// GraphNodeReferenceable
|
||||||
func (n *nodeExpandModuleVariable) ReferenceableAddrs() []addrs.Referenceable {
|
func (n *nodeExpandModuleVariable) ReferenceableAddrs() []addrs.Referenceable {
|
||||||
// FIXME: References for module variables probably need to be thought out a bit more
|
return []addrs.Referenceable{n.Addr}
|
||||||
// Otherwise, we can reference the output via the address itself, or the
|
|
||||||
// module call
|
|
||||||
_, call := n.Module.Call()
|
|
||||||
return []addrs.Referenceable{n.Addr, call}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemovableIfNotTargeted
|
// RemovableIfNotTargeted
|
||||||
|
|
|
@ -303,6 +303,8 @@ func (m ReferenceMap) References(v dag.Vertex) []dag.Vertex {
|
||||||
subject = ri.ContainingResource()
|
subject = ri.ContainingResource()
|
||||||
case addrs.AbsModuleCallOutput:
|
case addrs.AbsModuleCallOutput:
|
||||||
subject = ri.ModuleCallOutput()
|
subject = ri.ModuleCallOutput()
|
||||||
|
case addrs.ModuleCallInstance:
|
||||||
|
subject = ri.Call
|
||||||
default:
|
default:
|
||||||
log.Printf("[WARN] ReferenceTransformer: reference not found: %q", subject)
|
log.Printf("[WARN] ReferenceTransformer: reference not found: %q", subject)
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in New Issue