diff --git a/internal/deprecation/schema.go b/internal/deprecation/schema.go index 6fb2b765b3..79bca750e5 100644 --- a/internal/deprecation/schema.go +++ b/internal/deprecation/schema.go @@ -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 diff --git a/internal/terraform/context_validate_test.go b/internal/terraform/context_validate_test.go index 3b10cc6591..40413d8437 100644 --- a/internal/terraform/context_validate_test.go +++ b/internal/terraform/context_validate_test.go @@ -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},