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:
parent
efd27e9e4e
commit
5643a7c28b
|
@ -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
|
||||
|
|
|
@ -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{}
|
||||
|
||||
|
|
Loading…
Reference in New Issue