Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecation Warning For Outputs #36016

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions internal/configs/named_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,14 @@ type Output struct {
DependsOn []hcl.Traversal
Sensitive bool
Ephemeral bool
Deprecated string

Preconditions []*CheckRule

DescriptionSet bool
SensitiveSet bool
EphemeralSet bool
DeprecatedSet bool

DeclRange hcl.Range
}
Expand Down Expand Up @@ -402,6 +404,12 @@ func decodeOutputBlock(block *hcl.Block, override bool) (*Output, hcl.Diagnostic
o.EphemeralSet = true
}

if attr, exists := content.Attributes["deprecated"]; exists {
valDiags := gohcl.DecodeExpression(attr.Expr, nil, &o.Deprecated)
diags = append(diags, valDiags...)
o.DeprecatedSet = true
}

if attr, exists := content.Attributes["depends_on"]; exists {
deps, depsDiags := DecodeDependsOn(attr)
diags = append(diags, depsDiags...)
Expand Down Expand Up @@ -525,6 +533,9 @@ var outputBlockSchema = &hcl.BodySchema{
{
Name: "ephemeral",
},
{
Name: "deprecated",
},
},
Blocks: []hcl.BlockHeaderSchema{
{Type: "precondition"},
Expand Down
27 changes: 27 additions & 0 deletions internal/configs/named_values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,30 @@ func TestVariableInvalidDefault(t *testing.T) {
}
}
}

func TestOutputDeprecation(t *testing.T) {
src := `
output "foo" {
value = "bar"
deprecated = "This output is deprecated"
}
`

hclF, diags := hclsyntax.ParseConfig([]byte(src), "test.tf", hcl.InitialPos)
if diags.HasErrors() {
t.Fatal(diags.Error())
}

b, diags := parseConfigFile(hclF.Body, nil, false, false)
if diags.HasErrors() {
t.Fatalf("unexpected error: %q", diags)
}

if !b.Outputs[0].DeprecatedSet {
t.Fatalf("expected output to be deprecated")
}

if b.Outputs[0].Deprecated != "This output is deprecated" {
t.Fatalf("expected output to have deprecation message")
}
}
5 changes: 5 additions & 0 deletions internal/lang/marks/marks.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ func (m valueMark) GoString() string {
return "marks." + string(m)
}

type DeprecationMark struct {
AttrPath cty.Path
Message string
}

// Has returns true if and only if the cty.Value has the given mark.
func Has(val cty.Value, mark valueMark) bool {
return val.HasMark(mark)
Expand Down
5 changes: 3 additions & 2 deletions internal/plans/changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,16 +617,17 @@ func (c *Change) Encode(ty cty.Type) (*ChangeSrc, error) {
unmarkedAfter, marksesAfter := c.After.UnmarkDeepWithPaths()
sensitiveAttrsBefore, unsupportedMarksesBefore := marks.PathsWithMark(marksesBefore, marks.Sensitive)
sensitiveAttrsAfter, unsupportedMarksesAfter := marks.PathsWithMark(marksesAfter, marks.Sensitive)

if len(unsupportedMarksesBefore) != 0 {
return nil, fmt.Errorf(
"prior value %s: can't serialize value marked with %#v (this is a bug in Terraform)",
"prior value %s: cannot serialize value marked with %#v (this is a bug in Terraform)",
tfdiags.FormatCtyPath(unsupportedMarksesBefore[0].Path),
unsupportedMarksesBefore[0].Marks,
)
}
if len(unsupportedMarksesAfter) != 0 {
return nil, fmt.Errorf(
"new value %s: can't serialize value marked with %#v (this is a bug in Terraform)",
"new value %s: cannot serialize value marked with %#v (this is a bug in Terraform)",
tfdiags.FormatCtyPath(unsupportedMarksesAfter[0].Path),
unsupportedMarksesAfter[0].Marks,
)
Expand Down
2 changes: 1 addition & 1 deletion internal/stacks/stackplan/planned_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ func DynamicValueToTerraform1(val cty.Value, ty cty.Type) (*stacks.DynamicValue,
sensitivePaths, withOtherMarks := marks.PathsWithMark(markPaths, marks.Sensitive)
if len(withOtherMarks) != 0 {
return nil, withOtherMarks[0].Path.NewErrorf(
"can't serialize value marked with %#v (this is a bug in Terraform)",
"cannot serialize value marked with %#v (this is a bug in Terraform)",
withOtherMarks[0].Marks,
)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/terraform/context_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ The -target option is not for routine use, and is provided only for exceptional
panic("nil plan but no errors")
}

if plan != nil {
if plan != nil && plan.Changes != nil {
relevantAttrs, rDiags := c.relevantResourceAttrsForPlan(config, plan)
diags = diags.Append(rDiags)
plan.RelevantAttributes = relevantAttrs
Expand Down
Loading
Loading