core: allow partially-unknown lists from splat syntax

This was actually redundant anyway since HIL itself applied a similar
rule where any partially-unknown list would be automatically flattened
to a single unknown value.

However, now we're changing HIL to explicitly permit partially-unknown
lists so that we can allow the index operator [...] to succeed when
applied to one of the elements that _is_ known.

This, in conjunction with hashicorp/hil#51 and hashicorp/hil#52,
fixes #3449.
This commit is contained in:
Martin Atkins 2017-05-01 15:22:34 -07:00
parent edb362cfb3
commit b4df03bca4
3 changed files with 85 additions and 12 deletions

View File

@ -594,10 +594,6 @@ func (i *Interpolater) computeResourceMultiVariable(
}
if singleAttr, ok := r.Primary.Attributes[v.Field]; ok {
if singleAttr == config.UnknownVariableValue {
return &unknownVariable, nil
}
values = append(values, singleAttr)
continue
}
@ -613,10 +609,6 @@ func (i *Interpolater) computeResourceMultiVariable(
return nil, err
}
if multiAttr == unknownVariable {
return &unknownVariable, nil
}
values = append(values, multiAttr)
}

View File

@ -359,8 +359,81 @@ func TestInterpolater_resourceVariableMulti(t *testing.T) {
}
testInterpolate(t, i, scope, "aws_instance.web.*.foo", ast.Variable{
Value: config.UnknownVariableValue,
Type: ast.TypeList,
Value: []ast.Variable{
{
Type: ast.TypeUnknown,
Value: config.UnknownVariableValue,
},
},
})
}
func TestInterpolater_resourceVariableMultiPartialUnknown(t *testing.T) {
lock := new(sync.RWMutex)
state := &State{
Modules: []*ModuleState{
&ModuleState{
Path: rootModulePath,
Resources: map[string]*ResourceState{
"aws_instance.web.0": &ResourceState{
Type: "aws_instance",
Primary: &InstanceState{
ID: "bar",
Attributes: map[string]string{
"foo": "1",
},
},
},
"aws_instance.web.1": &ResourceState{
Type: "aws_instance",
Primary: &InstanceState{
ID: "bar",
Attributes: map[string]string{
"foo": config.UnknownVariableValue,
},
},
},
"aws_instance.web.2": &ResourceState{
Type: "aws_instance",
Primary: &InstanceState{
ID: "bar",
Attributes: map[string]string{
"foo": "2",
},
},
},
},
},
},
}
i := &Interpolater{
Module: testModule(t, "interpolate-resource-variable-multi"),
State: state,
StateLock: lock,
}
scope := &InterpolationScope{
Path: rootModulePath,
}
testInterpolate(t, i, scope, "aws_instance.web.*.foo", ast.Variable{
Type: ast.TypeList,
Value: []ast.Variable{
{
Type: ast.TypeString,
Value: "1",
},
{
Type: ast.TypeUnknown,
Value: config.UnknownVariableValue,
},
{
Type: ast.TypeString,
Value: "2",
},
},
})
}
@ -408,8 +481,13 @@ func TestInterpolater_resourceVariableMultiList(t *testing.T) {
}
testInterpolate(t, i, scope, "aws_instance.web.*.ip", ast.Variable{
Value: config.UnknownVariableValue,
Type: ast.TypeList,
Value: []ast.Variable{
{
Type: ast.TypeUnknown,
Value: config.UnknownVariableValue,
},
},
})
}

View File

@ -0,0 +1,3 @@
resource "aws_instance" "web" {
count = 3
}