Merge pull request #611 from Banno/fix-multivar-in-modules
looking up count of multivars in correct module config
This commit is contained in:
commit
4b8151ec6d
|
@ -1679,10 +1679,19 @@ func (c *walkContext) computeResourceMultiVariable(
|
||||||
c.Context.sl.RLock()
|
c.Context.sl.RLock()
|
||||||
defer c.Context.sl.RUnlock()
|
defer c.Context.sl.RUnlock()
|
||||||
|
|
||||||
|
childPath := c.Path[1:len(c.Path)]
|
||||||
|
|
||||||
|
var modTree *module.Tree
|
||||||
|
if len(childPath) == 0 {
|
||||||
|
modTree = c.Context.module
|
||||||
|
} else {
|
||||||
|
modTree = c.Context.module.Child(childPath)
|
||||||
|
}
|
||||||
|
|
||||||
// Get the resource from the configuration so we can know how
|
// Get the resource from the configuration so we can know how
|
||||||
// many of the resource there is.
|
// many of the resource there is.
|
||||||
var cr *config.Resource
|
var cr *config.Resource
|
||||||
for _, r := range c.Context.module.Config().Resources {
|
for _, r := range modTree.Config().Resources {
|
||||||
if r.Id() == v.ResourceId() {
|
if r.Id() == v.ResourceId() {
|
||||||
cr = r
|
cr = r
|
||||||
break
|
break
|
||||||
|
@ -1697,7 +1706,7 @@ func (c *walkContext) computeResourceMultiVariable(
|
||||||
|
|
||||||
// Get the relevant module
|
// Get the relevant module
|
||||||
// TODO: Not use only root module
|
// TODO: Not use only root module
|
||||||
module := c.Context.state.RootModule()
|
module := c.Context.state.ModuleByPath(c.Path)
|
||||||
|
|
||||||
count, err := cr.Count()
|
count, err := cr.Count()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -2978,6 +2978,28 @@ func TestContextPlan_moduleInputFromVar(t *testing.T) {
|
||||||
t.Fatalf("bad:\n%s", actual)
|
t.Fatalf("bad:\n%s", actual)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
func TestContextPlan_moduleMultiVar(t *testing.T) {
|
||||||
|
m := testModule(t, "plan-module-multi-var")
|
||||||
|
p := testProvider("aws")
|
||||||
|
p.DiffFn = testDiffFn
|
||||||
|
ctx := testContext(t, &ContextOpts{
|
||||||
|
Module: m,
|
||||||
|
Providers: map[string]ResourceProviderFactory{
|
||||||
|
"aws": testProviderFuncFixed(p),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
plan, err := ctx.Plan(nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
actual := strings.TrimSpace(plan.String())
|
||||||
|
expected := strings.TrimSpace(testTerraformPlanModuleMultiVarStr)
|
||||||
|
if actual != expected {
|
||||||
|
t.Fatalf("bad:\n%s", actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
func TestContextPlan_moduleOrphans(t *testing.T) {
|
func TestContextPlan_moduleOrphans(t *testing.T) {
|
||||||
m := testModule(t, "plan-modules-remove")
|
m := testModule(t, "plan-modules-remove")
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
|
|
|
@ -841,6 +841,25 @@ STATE:
|
||||||
<no state>
|
<no state>
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const testTerraformPlanModuleMultiVarStr = `
|
||||||
|
DIFF:
|
||||||
|
|
||||||
|
module.child:
|
||||||
|
CREATE: aws_instance.bar.0
|
||||||
|
baz: "" => "baz"
|
||||||
|
type: "" => "aws_instance"
|
||||||
|
CREATE: aws_instance.bar.1
|
||||||
|
baz: "" => "baz"
|
||||||
|
type: "" => "aws_instance"
|
||||||
|
CREATE: aws_instance.foo
|
||||||
|
foo: "" => "baz,baz"
|
||||||
|
type: "" => "aws_instance"
|
||||||
|
|
||||||
|
STATE:
|
||||||
|
|
||||||
|
<no state>
|
||||||
|
`
|
||||||
|
|
||||||
const testTerraformPlanModuleOrphansStr = `
|
const testTerraformPlanModuleOrphansStr = `
|
||||||
DIFF:
|
DIFF:
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
resource "aws_instance" "bar" {
|
||||||
|
baz = "baz"
|
||||||
|
count = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_instance" "foo" {
|
||||||
|
foo = "${join(",",aws_instance.bar.*.baz)}"
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
module "child" {
|
||||||
|
source = "./child"
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue