core: protect against count.index in modules
Modules should get a validation error just like outputs do. refs #1528
This commit is contained in:
parent
347690a73e
commit
975a96f271
|
@ -290,6 +290,14 @@ func (c *Config) Validate() error {
|
||||||
raw[k] = strVal
|
raw[k] = strVal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for invalid count variables
|
||||||
|
for _, v := range m.RawConfig.Variables {
|
||||||
|
if _, ok := v.(*CountVariable); ok {
|
||||||
|
errs = append(errs, fmt.Errorf(
|
||||||
|
"%s: count variables are only valid within resources", m.Name))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update the raw configuration to only contain the string values
|
// Update the raw configuration to only contain the string values
|
||||||
m.RawConfig, err = NewRawConfig(raw)
|
m.RawConfig, err = NewRawConfig(raw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -63,10 +63,17 @@ func TestConfigValidate_countInt(t *testing.T) {
|
||||||
|
|
||||||
func TestConfigValidate_countBadContext(t *testing.T) {
|
func TestConfigValidate_countBadContext(t *testing.T) {
|
||||||
c := testConfig(t, "validate-count-bad-context")
|
c := testConfig(t, "validate-count-bad-context")
|
||||||
expected := "count variables are only valid within resources"
|
|
||||||
err := c.Validate()
|
err := c.Validate()
|
||||||
if !strings.Contains(err.Error(), expected) {
|
|
||||||
t.Fatalf("expected: %q,\nto contain: %q", err, expected)
|
expected := []string{
|
||||||
|
"no_count_in_output: count variables are only valid within resources",
|
||||||
|
"no_count_in_module: count variables are only valid within resources",
|
||||||
|
}
|
||||||
|
for _, exp := range expected {
|
||||||
|
if !strings.Contains(err.Error(), exp) {
|
||||||
|
t.Fatalf("expected: %q,\nto contain: %q", err, exp)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
resource "aws_instance" "foo" {
|
resource "aws_instance" "foo" {
|
||||||
}
|
}
|
||||||
|
|
||||||
output "notgood" {
|
output "no_count_in_output" {
|
||||||
value = "${count.index}"
|
value = "${count.index}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module "no_count_in_module" {
|
||||||
|
source = "./child"
|
||||||
|
somevar = "${count.index}"
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue