Merge pull request #12772 from hashicorp/jbardin/GH-12742

Don't interpolate multivariables during walkInput
This commit is contained in:
James Bardin 2017-03-16 13:59:10 -04:00 committed by GitHub
commit a90d370d68
5 changed files with 56 additions and 0 deletions

View File

@ -658,3 +658,30 @@ func TestContext2Input_hcl(t *testing.T) {
t.Fatalf("bad: \n%s", actualStr) t.Fatalf("bad: \n%s", actualStr)
} }
} }
// adding a list interpolation in fails to interpolate the count variable
func TestContext2Input_submoduleTriggersInvalidCount(t *testing.T) {
input := new(MockUIInput)
m := testModule(t, "input-submodule-count")
p := testProvider("aws")
p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
UIInput: input,
})
p.InputFn = func(i UIInput, c *ResourceConfig) (*ResourceConfig, error) {
return c, nil
}
p.ConfigureFn = func(c *ResourceConfig) error {
return nil
}
if err := ctx.Input(InputModeStd); err != nil {
t.Fatalf("err: %s", err)
}
}

View File

@ -540,6 +540,13 @@ func (i *Interpolater) computeResourceMultiVariable(
unknownVariable := unknownVariable() unknownVariable := unknownVariable()
// If we're only looking for input, we don't need to expand a
// multi-variable. This prevents us from encountering things that should be
// known but aren't because the state has yet to be refreshed.
if i.Operation == walkInput {
return &unknownVariable, nil
}
// Get the information about this resource variable, and verify // Get the information about this resource variable, and verify
// that it exists and such. // that it exists and such.
module, cr, err := i.resourceVariableInfo(scope, v) module, cr, err := i.resourceVariableInfo(scope, v)

View File

@ -0,0 +1,4 @@
module "mod" {
source = "./mod"
count = 2
}

View File

@ -0,0 +1,11 @@
variable "count" {
}
resource "aws_instance" "foo" {
count = "${var.count}"
}
module "submod" {
source = "./submod"
list = ["${aws_instance.foo.*.id}"]
}

View File

@ -0,0 +1,7 @@
variable "list" {
type = "list"
}
resource "aws_instance" "bar" {
count = "${var.list[0]}"
}