Merge pull request #11864 from hashicorp/b-config-list

config: Resource.Count should type check
This commit is contained in:
Mitchell Hashimoto 2017-02-13 08:47:54 -08:00 committed by GitHub
commit 911717c9d5
3 changed files with 30 additions and 1 deletions

View File

@ -212,7 +212,14 @@ func (r *Module) Id() string {
// Count returns the count of this resource.
func (r *Resource) Count() (int, error) {
v, err := strconv.ParseInt(r.RawCount.Value().(string), 0, 0)
raw := r.RawCount.Value()
count, ok := r.RawCount.Value().(string)
if !ok {
return 0, fmt.Errorf(
"expected count to be a string or int, got %T", raw)
}
v, err := strconv.ParseInt(count, 0, 0)
if err != nil {
return 0, err
}

View File

@ -11,6 +11,7 @@ import (
"strings"
"testing"
"github.com/hashicorp/hil/ast"
"github.com/hashicorp/terraform/helper/logging"
)
@ -98,6 +99,24 @@ func TestConfigCount_string(t *testing.T) {
}
}
// Terraform GH-11800
func TestConfigCount_list(t *testing.T) {
c := testConfig(t, "count-list")
// The key is to interpolate so it doesn't fail parsing
c.Resources[0].RawCount.Interpolate(map[string]ast.Variable{
"var.list": ast.Variable{
Value: []ast.Variable{},
Type: ast.TypeList,
},
})
_, err := c.Resources[0].Count()
if err == nil {
t.Fatal("should error")
}
}
func TestConfigCount_var(t *testing.T) {
c := testConfig(t, "count-var")
_, err := c.Resources[0].Count()

View File

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