Merge remote-tracking branch 'origin/master' into fix-aws-instance-block-devices-index-range

This commit is contained in:
Luke Amdor 2014-12-01 12:40:40 -06:00
commit 0ac28a651f
5 changed files with 64 additions and 2 deletions

View File

@ -1679,10 +1679,19 @@ func (c *walkContext) computeResourceMultiVariable(
c.Context.sl.RLock()
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
// many of the resource there is.
var cr *config.Resource
for _, r := range c.Context.module.Config().Resources {
for _, r := range modTree.Config().Resources {
if r.Id() == v.ResourceId() {
cr = r
break
@ -1697,7 +1706,7 @@ func (c *walkContext) computeResourceMultiVariable(
// Get the relevant module
// TODO: Not use only root module
module := c.Context.state.RootModule()
module := c.Context.state.ModuleByPath(c.Path)
count, err := cr.Count()
if err != nil {

View File

@ -2978,6 +2978,28 @@ func TestContextPlan_moduleInputFromVar(t *testing.T) {
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) {
m := testModule(t, "plan-modules-remove")
p := testProvider("aws")

View File

@ -841,6 +841,25 @@ 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 = `
DIFF:

View File

@ -0,0 +1,8 @@
resource "aws_instance" "bar" {
baz = "baz"
count = 2
}
resource "aws_instance" "foo" {
foo = "${join(",",aws_instance.bar.*.baz)}"
}

View File

@ -0,0 +1,4 @@
module "child" {
source = "./child"
}