Add `type` attribute to `output` blocks

pull/38280/head^2
Daniel Banck 1 year ago committed by Daniel Banck
parent d7baa140f8
commit 941dfcc82c

@ -388,12 +388,24 @@ type Output struct {
Ephemeral bool
Deprecated string
// ConstraintType is a type constraint which the result is guaranteed
// to conform to when used in the calling module.
ConstraintType cty.Type
// TypeDefaults describes any optional attribute defaults that should be
// applied to the Expr result before type conversion.
TypeDefaults *typeexpr.Defaults
Preconditions []*CheckRule
DescriptionSet bool
SensitiveSet bool
EphemeralSet bool
DeprecatedSet bool
// TypeSet is true if there was an explicit "type" argument in the
// configuration block. This is mainly to allow distinguish explicitly
// setting vs. just using the default type constraint when processing
// override files.
TypeSet bool
DeclRange hcl.Range
DeprecatedRange hcl.Range
@ -434,6 +446,19 @@ func decodeOutputBlock(block *hcl.Block, override bool) (*Output, hcl.Diagnostic
o.Expr = attr.Expr
}
if attr, exists := content.Attributes["type"]; exists {
ty, defaults, moreDiags := typeexpr.TypeConstraintWithDefaults(attr.Expr)
diags = append(diags, moreDiags...)
o.ConstraintType = ty
o.TypeDefaults = defaults
o.TypeSet = true
}
if o.ConstraintType == cty.NilType {
// If no constraint is given then the type will be inferred
// automatically from the value.
o.ConstraintType = cty.DynamicPseudoType
}
if attr, exists := content.Attributes["sensitive"]; exists {
valDiags := gohcl.DecodeExpression(attr.Expr, nil, &o.Sensitive)
diags = append(diags, valDiags...)
@ -587,6 +612,9 @@ var outputBlockSchema = &hcl.BodySchema{
{
Name: "deprecated",
},
{
Name: "type",
},
},
Blocks: []hcl.BlockHeaderSchema{
{Type: "precondition"},

@ -0,0 +1,11 @@
output "string" {
type = string
value = "Hello"
}
output "object" {
type = object({
name = optional(string, "Bart"),
})
value = {}
}
Loading…
Cancel
Save