config: allow local value interpolations in count

There is some additional, early validation on the "count" meta-argument
that verifies that only suitable variable types are used, and adding local
values to this whitelist was missed in the initial implementation.
This commit is contained in:
Martin Atkins 2017-09-01 09:35:49 -07:00
parent 8cd0ee80e5
commit 0a342e8dc2
5 changed files with 57 additions and 0 deletions

View File

@ -557,6 +557,7 @@ func (c *Config) Validate() error {
case *ResourceVariable:
case *TerraformVariable:
case *UserVariable:
case *LocalVariable:
default:
errs = append(errs, fmt.Errorf(

View File

@ -312,6 +312,13 @@ func TestConfigValidate_countUserVar(t *testing.T) {
}
}
func TestConfigValidate_countLocalValue(t *testing.T) {
c := testConfig(t, "validate-local-value-count")
if err := c.Validate(); err != nil {
t.Fatalf("err: %s", err)
}
}
func TestConfigValidate_countVar(t *testing.T) {
c := testConfig(t, "validate-count-var")
if err := c.Validate(); err != nil {

View File

@ -0,0 +1,8 @@
locals {
count = 3
}
resource "null_resource" "foo" {
count = "${local.count}"
}

View File

@ -1294,6 +1294,39 @@ func TestContext2Plan_computedDataCountResource(t *testing.T) {
}
}
func TestContext2Plan_localValueCount(t *testing.T) {
m := testModule(t, "plan-local-value-count")
p := testProvider("test")
p.DiffFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Module: m,
ProviderResolver: ResourceProviderResolverFixed(
map[string]ResourceProviderFactory{
"test": testProviderFuncFixed(p),
},
),
})
plan, err := ctx.Plan()
if err != nil {
t.Fatalf("err: %s", err)
}
if got := len(plan.Diff.Modules); got != 1 {
t.Fatalf("got %d modules; want 1", got)
}
moduleDiff := plan.Diff.Modules[0]
// make sure we created 3 "bar"s
for i := 0; i < 3; i++ {
resource := fmt.Sprintf("test_resource.foo.%d", i)
if _, ok := moduleDiff.Resources[resource]; !ok {
t.Fatalf("missing diff for %s", resource)
}
}
}
// Higher level test at TestResource_dataSourceListPlanPanic
func TestContext2Plan_dataSourceTypeMismatch(t *testing.T) {
m := testModule(t, "plan-data-source-type-mismatch")

View File

@ -0,0 +1,8 @@
locals {
count = 3
}
resource "test_resource" "foo" {
count = "${local.count}"
}