diff --git a/config/config.go b/config/config.go index 9549d0a507..949ad06d00 100644 --- a/config/config.go +++ b/config/config.go @@ -557,6 +557,7 @@ func (c *Config) Validate() error { case *ResourceVariable: case *TerraformVariable: case *UserVariable: + case *LocalVariable: default: errs = append(errs, fmt.Errorf( diff --git a/config/config_test.go b/config/config_test.go index 49c4d9ac3e..50301f21f9 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -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 { diff --git a/config/test-fixtures/validate-local-value-count/main.tf b/config/test-fixtures/validate-local-value-count/main.tf new file mode 100644 index 0000000000..b50c4b3609 --- /dev/null +++ b/config/test-fixtures/validate-local-value-count/main.tf @@ -0,0 +1,8 @@ + +locals { + count = 3 +} + +resource "null_resource" "foo" { + count = "${local.count}" +} diff --git a/terraform/context_plan_test.go b/terraform/context_plan_test.go index 39baa426d6..0f6fdf2842 100644 --- a/terraform/context_plan_test.go +++ b/terraform/context_plan_test.go @@ -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") diff --git a/terraform/test-fixtures/plan-local-value-count/main.tf b/terraform/test-fixtures/plan-local-value-count/main.tf new file mode 100644 index 0000000000..34aad96ad6 --- /dev/null +++ b/terraform/test-fixtures/plan-local-value-count/main.tf @@ -0,0 +1,8 @@ + +locals { + count = 3 +} + +resource "test_resource" "foo" { + count = "${local.count}" +}