Merge pull request #11864 from hashicorp/b-config-list
config: Resource.Count should type check
This commit is contained in:
commit
911717c9d5
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
resource "foo" "bar" {
|
||||
count = "${var.list}"
|
||||
}
|
Loading…
Reference in New Issue