Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: count can't be a SimpleVariable #8243

Merged
merged 1 commit into from
Aug 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,10 +468,15 @@ func (c *Config) Validate() error {
"%s: resource count can't reference resource variable: %s",
n,
v.FullKey()))
case *SimpleVariable:
errs = append(errs, fmt.Errorf(
"%s: resource count can't reference variable: %s",
n,
v.FullKey()))
case *UserVariable:
// Good
default:
panic("Unknown type in count var: " + n)
panic(fmt.Sprintf("Unknown type in count var in %s: %T", n, v))
}
}

Expand Down
7 changes: 7 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
c := testConfig(t, "validate-depends-on-var")
if err := c.Validate(); err == nil {
Expand Down
3 changes: 3 additions & 0 deletions config/test-fixtures/validate-count-var-unknown/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "aws_instance" "foo" {
count = "${list}"
}
19 changes: 19 additions & 0 deletions terraform/context_validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ import (
"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) {
p := testProvider("aws")
m := testModule(t, "validate-bad-var")
Expand Down
3 changes: 3 additions & 0 deletions terraform/test-fixtures/validate-bad-count/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "aws_instance" "foo" {
count = "${list}"
}