use format.CtyPath for formatting go-cty paths

pull/38082/head
Daniel Schmidt 3 months ago
parent 7b28c88e66
commit 76747e174c

@ -5,8 +5,10 @@ package deprecation
import (
"fmt"
"strings"
"github.com/hashicorp/terraform/internal/configs/configschema"
"github.com/hashicorp/terraform/internal/lang/format"
"github.com/hashicorp/terraform/internal/lang/marks"
"github.com/zclconf/go-cty/cty"
)
@ -38,12 +40,12 @@ func MarkDeprecatedValues(val cty.Value, schema *configschema.Block, origin stri
attr := schema.AttributeByPath(p)
if attr != nil && attr.Deprecated {
v = v.Mark(marks.NewDeprecation(fmt.Sprintf("Deprecated resource attribute %q used", p), fmt.Sprintf("%s.%s", origin, p)))
v = v.Mark(marks.NewDeprecation(fmt.Sprintf("Deprecated resource attribute %q used", strings.TrimPrefix(format.CtyPath(p), ".")), fmt.Sprintf("%s%s", origin, format.CtyPath(p))))
}
block := schema.BlockByPath(p)
if block != nil && block.Deprecated {
v = v.Mark(marks.NewDeprecation(fmt.Sprintf("Deprecated resource block %q used", p), fmt.Sprintf("%s.%s", origin, p)))
v = v.Mark(marks.NewDeprecation(fmt.Sprintf("Deprecated resource block %q used", strings.TrimPrefix(format.CtyPath(p), ".")), fmt.Sprintf("%s%s", origin, format.CtyPath(p))))
}
return v, nil

@ -2485,7 +2485,7 @@ func TestContext2Validate_deprecatedAttr(t *testing.T) {
return tfdiags.Diagnostics{}.Append(&hcl.Diagnostic{
Severity: hcl.DiagWarning,
Summary: `Deprecated value used`,
Detail: `Deprecated resource attribute [{{} "foo"}] used`,
Detail: `Deprecated resource attribute "foo" used`,
Subject: &hcl.Range{
Filename: filepath.Join(c.Module.SourceDir, "main.tf"),
Start: hcl.Pos{Line: 5, Column: 28, Byte: 108},
@ -2514,7 +2514,7 @@ func TestContext2Validate_deprecatedAttr(t *testing.T) {
return tfdiags.Diagnostics{}.Append(&hcl.Diagnostic{
Severity: hcl.DiagWarning,
Summary: `Deprecated value used`,
Detail: `Deprecated resource attribute [{{} "foo"}] used`,
Detail: `Deprecated resource attribute "foo" used`,
Subject: &hcl.Range{
Filename: filepath.Join(m.Module.SourceDir, "main.tf"),
Start: hcl.Pos{Line: 6, Column: 23, Byte: 152},
@ -2543,7 +2543,7 @@ func TestContext2Validate_deprecatedAttr(t *testing.T) {
return tfdiags.Diagnostics{}.Append(&hcl.Diagnostic{
Severity: hcl.DiagWarning,
Summary: `Deprecated value used`,
Detail: `Deprecated resource attribute [{{} "foo"}] used`,
Detail: `Deprecated resource attribute "foo" used`,
Subject: &hcl.Range{
Filename: filepath.Join(m.Module.SourceDir, "main.tf"),
Start: hcl.Pos{Line: 6, Column: 26, Byte: 164},
@ -2570,7 +2570,7 @@ func TestContext2Validate_deprecatedAttr(t *testing.T) {
return tfdiags.Diagnostics{}.Append(&hcl.Diagnostic{
Severity: hcl.DiagWarning,
Summary: `Deprecated value used`,
Detail: `Deprecated resource attribute [{{} "foo"}] used`,
Detail: `Deprecated resource attribute "foo" used`,
Subject: &hcl.Range{
Filename: filepath.Join(c.Module.SourceDir, "main.tf"),
Start: hcl.Pos{Line: 5, Column: 23, Byte: 123},
@ -2601,7 +2601,7 @@ func TestContext2Validate_deprecatedAttr(t *testing.T) {
return tfdiags.Diagnostics{}.Append(&hcl.Diagnostic{
Severity: hcl.DiagWarning,
Summary: `Deprecated value used`,
Detail: `Deprecated resource attribute [{{} "foo"}] used`,
Detail: `Deprecated resource attribute "foo" used`,
Subject: &hcl.Range{
Filename: filepath.Join(c.Module.SourceDir, "main.tf"),
Start: hcl.Pos{Line: 5, Column: 21, Byte: 126},
@ -2635,7 +2635,7 @@ func TestContext2Validate_deprecatedAttr(t *testing.T) {
return tfdiags.Diagnostics{}.Append(&hcl.Diagnostic{
Severity: hcl.DiagWarning,
Summary: `Deprecated value used`,
Detail: `Deprecated resource attribute [{{} "foo"}] used`,
Detail: `Deprecated resource attribute "foo" used`,
Subject: &hcl.Range{
Filename: filepath.Join(c.Module.SourceDir, "main.tf"),
Start: hcl.Pos{Line: 9, Column: 31, Byte: 245},
@ -2666,7 +2666,7 @@ func TestContext2Validate_deprecatedAttr(t *testing.T) {
return tfdiags.Diagnostics{}.Append(&hcl.Diagnostic{
Severity: hcl.DiagWarning,
Summary: `Deprecated value used`,
Detail: `Deprecated resource attribute [{{} "foo"}] used`,
Detail: `Deprecated resource attribute "foo" used`,
Subject: &hcl.Range{
Filename: filepath.Join(c.Module.SourceDir, "main.tf"),
Start: hcl.Pos{Line: 6, Column: 31, Byte: 160},
@ -2713,7 +2713,7 @@ func TestContext2Validate_deprecatedAttr(t *testing.T) {
return tfdiags.Diagnostics{}.Append(&hcl.Diagnostic{
Severity: hcl.DiagWarning,
Summary: `Deprecated value used`,
Detail: `Deprecated resource attribute [{{} "foo"}] used`,
Detail: `Deprecated resource attribute "foo" used`,
Subject: &hcl.Range{
Filename: filepath.Join(c.Module.SourceDir, "main.tf"),
Start: hcl.Pos{Line: 5, Column: 45, Byte: 135},
@ -2722,7 +2722,7 @@ func TestContext2Validate_deprecatedAttr(t *testing.T) {
}).Append(&hcl.Diagnostic{
Severity: hcl.DiagWarning,
Summary: `Deprecated value used`,
Detail: `Deprecated resource attribute [{{} "foo"}] used`,
Detail: `Deprecated resource attribute "foo" used`,
Subject: &hcl.Range{
Filename: filepath.Join(c.Module.SourceDir, "main.tf"),
Start: hcl.Pos{Line: 5, Column: 45, Byte: 135},
@ -2753,7 +2753,7 @@ func TestContext2Validate_deprecatedAttr(t *testing.T) {
return tfdiags.Diagnostics{}.Append(&hcl.Diagnostic{
Severity: hcl.DiagWarning,
Summary: `Deprecated value used`,
Detail: `Deprecated resource attribute [{{} "foo"}] used`,
Detail: `Deprecated resource attribute "foo" used`,
Subject: &hcl.Range{
Filename: filepath.Join(c.Module.SourceDir, "main.tf"),
Start: hcl.Pos{Line: 7, Column: 29, Byte: 170},
@ -2786,7 +2786,7 @@ func TestContext2Validate_deprecatedAttr(t *testing.T) {
return tfdiags.Diagnostics{}.Append(&hcl.Diagnostic{
Severity: hcl.DiagWarning,
Summary: `Deprecated value used`,
Detail: `Deprecated resource attribute [{{} "foo"}] used`,
Detail: `Deprecated resource attribute "foo" used`,
Subject: &hcl.Range{
Filename: filepath.Join(c.Module.SourceDir, "main.tf"),
Start: hcl.Pos{Line: 6, Column: 23, Byte: 144},
@ -2819,7 +2819,7 @@ func TestContext2Validate_deprecatedAttr(t *testing.T) {
return tfdiags.Diagnostics{}.Append(&hcl.Diagnostic{
Severity: hcl.DiagWarning,
Summary: `Deprecated value used`,
Detail: `Deprecated resource attribute [{{} "foo"}] used`,
Detail: `Deprecated resource attribute "foo" used`,
Subject: &hcl.Range{
Filename: filepath.Join(c.Module.SourceDir, "main.tf"),
Start: hcl.Pos{Line: 6, Column: 36, Byte: 177},
@ -2828,7 +2828,7 @@ func TestContext2Validate_deprecatedAttr(t *testing.T) {
}).Append(&hcl.Diagnostic{
Severity: hcl.DiagWarning,
Summary: `Deprecated value used`,
Detail: `Deprecated resource attribute [{{} "foo"}] used`,
Detail: `Deprecated resource attribute "foo" used`,
Subject: &hcl.Range{
Filename: filepath.Join(c.Module.SourceDir, "main.tf"),
Start: hcl.Pos{Line: 9, Column: 26, Byte: 284},
@ -2843,7 +2843,7 @@ func TestContext2Validate_deprecatedAttr(t *testing.T) {
return tfdiags.Diagnostics{}.Append(&hcl.Diagnostic{
Severity: hcl.DiagWarning,
Summary: `Deprecated value used`,
Detail: `Deprecated resource attribute [{{} "foo"}] used`,
Detail: `Deprecated resource attribute "foo" used`,
Subject: &hcl.Range{
Filename: filepath.Join(c.Module.SourceDir, "main.tf"),
Start: hcl.Pos{Line: 6, Column: 36, Byte: 177},
@ -2852,7 +2852,7 @@ func TestContext2Validate_deprecatedAttr(t *testing.T) {
}).Append(&hcl.Diagnostic{
Severity: hcl.DiagWarning,
Summary: `Deprecated value used`,
Detail: `Deprecated resource attribute [{{} "foo"}] used`,
Detail: `Deprecated resource attribute "foo" used`,
Subject: &hcl.Range{
Filename: filepath.Join(c.Module.SourceDir, "main.tf"),
Start: hcl.Pos{Line: 9, Column: 26, Byte: 284},
@ -2881,7 +2881,7 @@ func TestContext2Validate_deprecatedAttr(t *testing.T) {
return tfdiags.Diagnostics{}.Append(&hcl.Diagnostic{
Severity: hcl.DiagWarning,
Summary: `Deprecated value used`,
Detail: `Deprecated resource attribute [{{} "foo"}] used`,
Detail: `Deprecated resource attribute "foo" used`,
Subject: &hcl.Range{
Filename: filepath.Join(c.Module.SourceDir, "main.tf"),
Start: hcl.Pos{Line: 6, Column: 24, Byte: 152},

Loading…
Cancel
Save