terraform: when returning a raw attribute value, use hil conversion

Because we now rely on HIL to do the computed calculation, we must make
sure the type is correct (TypeUnknown). Before, we'd just check for the
UUID in the string.

This changes all variable returns in the interpolater to run it through
`hil.InterfaceToVariable` which handles this lookup for us.
This commit is contained in:
Mitchell Hashimoto 2016-11-10 17:14:20 -08:00
parent efd27e9e4e
commit 5643a7c28b
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 40 additions and 1 deletions

View File

@ -404,7 +404,8 @@ func (i *Interpolater) computeResourceVariable(
}
if attr, ok := r.Primary.Attributes[v.Field]; ok {
return &ast.Variable{Type: ast.TypeString, Value: attr}, nil
v, err := hil.InterfaceToVariable(attr)
return &v, err
}
// computed list or map attribute

View File

@ -569,6 +569,44 @@ func TestInterpolator_resourceMultiAttributesComputed(t *testing.T) {
})
}
func TestInterpolator_resourceAttributeComputed(t *testing.T) {
lock := new(sync.RWMutex)
// The state would never be written with an UnknownVariableValue in it, but
// it can/does exist that way in memory during the plan phase.
state := &State{
Modules: []*ModuleState{
&ModuleState{
Path: rootModulePath,
Resources: map[string]*ResourceState{
"aws_route53_zone.yada": &ResourceState{
Type: "aws_route53_zone",
Primary: &InstanceState{
ID: "z-abc123",
Attributes: map[string]string{
"id": config.UnknownVariableValue,
},
},
},
},
},
},
}
i := &Interpolater{
Module: testModule(t, "interpolate-multi-vars"),
StateLock: lock,
State: state,
}
scope := &InterpolationScope{
Path: rootModulePath,
}
testInterpolate(t, i, scope, "aws_route53_zone.yada.id", ast.Variable{
Value: config.UnknownVariableValue,
Type: ast.TypeUnknown,
})
}
func TestInterpolater_selfVarWithoutResource(t *testing.T) {
i := &Interpolater{}