From bc26777963b51f351e2651e41a44d3b66ce0198f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 2 Oct 2014 18:22:32 -0700 Subject: [PATCH] config: count can't interpolate count variables --- config/config.go | 5 +++++ config/config_test.go | 7 +++++++ config/test-fixtures/validate-count-count-var/main.tf | 3 +++ 3 files changed, 15 insertions(+) create mode 100644 config/test-fixtures/validate-count-count-var/main.tf diff --git a/config/config.go b/config/config.go index 4d6ea1a85..b49dd685b 100644 --- a/config/config.go +++ b/config/config.go @@ -258,6 +258,11 @@ func (c *Config) Validate() error { // Verify count variables for _, v := range r.RawCount.Variables { switch v.(type) { + case *CountVariable: + errs = append(errs, fmt.Errorf( + "%s: resource count can't reference count variable: %s", + n, + v.FullKey())) case *ModuleVariable: errs = append(errs, fmt.Errorf( "%s: resource count can't reference module variable: %s", diff --git a/config/config_test.go b/config/config_test.go index 76c12d4a0..317d69edf 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -60,6 +60,13 @@ func TestConfigValidate_countInt(t *testing.T) { } } +func TestConfigValidate_countCountVar(t *testing.T) { + c := testConfig(t, "validate-count-count-var") + if err := c.Validate(); err == nil { + t.Fatal("should not be valid") + } +} + func TestConfigValidate_countModuleVar(t *testing.T) { c := testConfig(t, "validate-count-module-var") if err := c.Validate(); err == nil { diff --git a/config/test-fixtures/validate-count-count-var/main.tf b/config/test-fixtures/validate-count-count-var/main.tf new file mode 100644 index 000000000..f33618784 --- /dev/null +++ b/config/test-fixtures/validate-count-count-var/main.tf @@ -0,0 +1,3 @@ +resource "aws_instance" "web" { + count = "${count.index}" +}