Merge pull request #8243 from hashicorp/b-simple-var-validate

config: count can't be a SimpleVariable
This commit is contained in:
Mitchell Hashimoto 2016-08-16 13:55:35 -07:00 committed by GitHub
commit 9acde0c2c8
5 changed files with 38 additions and 1 deletions

View File

@ -468,10 +468,15 @@ func (c *Config) Validate() error {
"%s: resource count can't reference resource variable: %s", "%s: resource count can't reference resource variable: %s",
n, n,
v.FullKey())) v.FullKey()))
case *SimpleVariable:
errs = append(errs, fmt.Errorf(
"%s: resource count can't reference variable: %s",
n,
v.FullKey()))
case *UserVariable: case *UserVariable:
// Good // Good
default: default:
panic("Unknown type in count var: " + n) panic(fmt.Sprintf("Unknown type in count var in %s: %T", n, v))
} }
} }

View File

@ -216,6 +216,13 @@ func TestConfigValidate_countVarInvalid(t *testing.T) {
} }
} }
func TestConfigValidate_countVarUnknown(t *testing.T) {
c := testConfig(t, "validate-count-var-unknown")
if err := c.Validate(); err == nil {
t.Fatal("should not be valid")
}
}
func TestConfigValidate_dependsOnVar(t *testing.T) { func TestConfigValidate_dependsOnVar(t *testing.T) {
c := testConfig(t, "validate-depends-on-var") c := testConfig(t, "validate-depends-on-var")
if err := c.Validate(); err == nil { if err := c.Validate(); err == nil {

View File

@ -0,0 +1,3 @@
resource "aws_instance" "foo" {
count = "${list}"
}

View File

@ -6,6 +6,25 @@ import (
"testing" "testing"
) )
func TestContext2Validate_badCount(t *testing.T) {
p := testProvider("aws")
m := testModule(t, "validate-bad-count")
c := testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
})
w, e := c.Validate()
if len(w) > 0 {
t.Fatalf("bad: %#v", w)
}
if len(e) == 0 {
t.Fatalf("bad: %#v", e)
}
}
func TestContext2Validate_badVar(t *testing.T) { func TestContext2Validate_badVar(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
m := testModule(t, "validate-bad-var") m := testModule(t, "validate-bad-var")

View File

@ -0,0 +1,3 @@
resource "aws_instance" "foo" {
count = "${list}"
}