fix: Remove deprecation marks when formatting output for the `console` command. (#38676)

This change introduces handling of deprecation marks to resolve the linked issue, where the `console` command would panic when displaying a deprecated field, either directly, as part of a whole resource, or when referenced within a resource/local/etc.

Deprecation marks aren't used to change how values are rendered, but they need to be removed before we use the cty library to get string representations of values.

I decided to only remove marks in the context of a deprecation mark being present; if a different type of mark is added in future then the engineer implementing it will need to make an explicit decision about how it should be handled in the context of `console`. If that isn't done then the panic from the cty library will re-appear.
pull/38683/head
Sarah French 5 days ago committed by GitHub
parent fb8d253b97
commit b2fc2caf72
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
kind: BUG FIXES
body: 'console: Fixed a panic caused by evaluating an expression involving deprecated values'
time: 2026-06-03T17:25:07.111161+01:00
custom:
Issue: "38676"

@ -20,12 +20,21 @@ func FormatValue(v cty.Value, indent int) string {
if !v.IsKnown() {
return "(known after apply)"
}
// Any marks on the value must either be used to return
// early or be removed. In future marks may used to cause
// values to be annotated, but the mark will still need to be
// removed before we can get a string representation of the value.
if marks.Has(v, marks.Sensitive) {
return "(sensitive value)"
}
if marks.Has(v, marks.Ephemeral) {
return "(ephemeral value)"
}
if marks.Has(v, marks.Deprecation) {
// Mark doesn't impact formatting, so remove to unblock normal formatting below
v, _ = v.Unmark()
}
if v.IsNull() {
ty := v.Type()
switch {

@ -181,6 +181,10 @@ EOT_`,
cty.StringVal("an ephemeral value").Mark(marks.Ephemeral),
"(ephemeral value)",
},
{
cty.StringVal("I'm a deprecated string value").Mark(marks.Deprecation),
`"I'm a deprecated string value"`, // We don't render deprecated values differently, but we need to ensure the deprecation mark doesn't interfere with formatting
},
}
for _, test := range tests {

Loading…
Cancel
Save