Merge pull request #12340 from hashicorp/jbardin/GH-12253

return 0 from resourceCountMax with a nil Resource
This commit is contained in:
James Bardin 2017-03-02 11:59:32 -05:00 committed by GitHub
commit e5e37b0025
2 changed files with 25 additions and 4 deletions

View File

@ -698,6 +698,10 @@ func (i *Interpolater) resourceCountMax(
// from the state. Plan and so on may not have any state yet so // from the state. Plan and so on may not have any state yet so
// we do a full interpolation. // we do a full interpolation.
if i.Operation != walkApply { if i.Operation != walkApply {
if cr == nil {
return 0, nil
}
count, err := cr.Count() count, err := cr.Count()
if err != nil { if err != nil {
return 0, err return 0, err

View File

@ -680,7 +680,7 @@ func TestInterpolator_interpolatedListOrder(t *testing.T) {
&ModuleState{ &ModuleState{
Path: rootModulePath, Path: rootModulePath,
Resources: map[string]*ResourceState{ Resources: map[string]*ResourceState{
"aws_route53_zone.list": &ResourceState{ "aws_route53_zone.yada": &ResourceState{
Type: "aws_route53_zone", Type: "aws_route53_zone",
Dependencies: []string{}, Dependencies: []string{},
Primary: &InstanceState{ Primary: &InstanceState{
@ -719,7 +719,7 @@ func TestInterpolator_interpolatedListOrder(t *testing.T) {
list := []interface{}{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"} list := []interface{}{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"}
testInterpolate(t, i, scope, "aws_route53_zone.list.foo", testInterpolate(t, i, scope, "aws_route53_zone.yada.foo",
interfaceToVariableSwallowError(list)) interfaceToVariableSwallowError(list))
} }
@ -844,7 +844,7 @@ func TestInterpolator_sets(t *testing.T) {
&ModuleState{ &ModuleState{
Path: rootModulePath, Path: rootModulePath,
Resources: map[string]*ResourceState{ Resources: map[string]*ResourceState{
"aws_network_interface.set": &ResourceState{ "aws_route53_zone.yada": &ResourceState{
Type: "aws_network_interface", Type: "aws_network_interface",
Dependencies: []string{}, Dependencies: []string{},
Primary: &InstanceState{ Primary: &InstanceState{
@ -872,10 +872,27 @@ func TestInterpolator_sets(t *testing.T) {
set := []interface{}{"10.42.16.179"} set := []interface{}{"10.42.16.179"}
testInterpolate(t, i, scope, "aws_network_interface.set.private_ips", testInterpolate(t, i, scope, "aws_route53_zone.yada.private_ips",
interfaceToVariableSwallowError(set)) interfaceToVariableSwallowError(set))
} }
// When a splat reference is made to a resource that is unknown, we should
// return an empty list rather than panicking.
func TestInterpolater_resourceUnknownVariableList(t *testing.T) {
i := &Interpolater{
Module: testModule(t, "plan-computed-data-resource"),
State: NewState(), // state,
StateLock: new(sync.RWMutex),
}
scope := &InterpolationScope{
Path: rootModulePath,
}
testInterpolate(t, i, scope, "aws_vpc.bar.*.foo",
interfaceToVariableSwallowError([]interface{}{}))
}
func testInterpolate( func testInterpolate(
t *testing.T, i *Interpolater, t *testing.T, i *Interpolater,
scope *InterpolationScope, scope *InterpolationScope,