Skip to content

Commit ca2148c

Browse files
add support for deprecated variables and outputs
1 parent 477360e commit ca2148c

7 files changed

Lines changed: 147 additions & 3 deletions

File tree

tfconfig/load_hcl.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,13 @@ func LoadModuleFromFile(file *hcl.File, mod *Module) hcl.Diagnostics {
373373
v.Description = description
374374
}
375375

376+
if attr, defined := content.Attributes["deprecated"]; defined {
377+
var deprecated string
378+
valDiags := gohcl.DecodeExpression(attr.Expr, nil, &deprecated)
379+
diags = append(diags, valDiags...)
380+
v.Deprecated = deprecated
381+
}
382+
376383
if attr, defined := content.Attributes["default"]; defined {
377384
// To avoid the caller needing to deal with cty here, we'll
378385
// use its JSON encoding to convert into an
@@ -427,6 +434,13 @@ func LoadModuleFromFile(file *hcl.File, mod *Module) hcl.Diagnostics {
427434
o.Description = description
428435
}
429436

437+
if attr, defined := content.Attributes["deprecated"]; defined {
438+
var deprecated string
439+
valDiags := gohcl.DecodeExpression(attr.Expr, nil, &deprecated)
440+
diags = append(diags, valDiags...)
441+
o.Deprecated = deprecated
442+
}
443+
430444
if attr, defined := content.Attributes["sensitive"]; defined {
431445
var sensitive bool
432446
valDiags := gohcl.DecodeExpression(attr.Expr, nil, &sensitive)

tfconfig/output.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type Output struct {
88
Name string `json:"name"`
99
Description string `json:"description,omitempty"`
1010
Sensitive bool `json:"sensitive,omitempty"`
11+
Deprecated string `json:"deprecated,omitempty"`
1112
Pos SourcePos `json:"pos"`
1213
Type string `json:"type,omitempty"`
1314
}

tfconfig/schema.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ var variableSchema = &hcl.BodySchema{
8686
{
8787
Name: "sensitive",
8888
},
89+
{
90+
Name: "deprecated",
91+
},
8992
},
9093
}
9194

@@ -100,6 +103,9 @@ var outputSchema = &hcl.BodySchema{
100103
{
101104
Name: "type",
102105
},
106+
{
107+
Name: "deprecated",
108+
},
103109
},
104110
}
105111

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"path": "testdata/deprecated",
3+
"required_providers": {},
4+
"variables": {
5+
"old_api_key": {
6+
"name": "old_api_key",
7+
"type": "string",
8+
"description": "API key for the old service",
9+
"default": null,
10+
"required": true,
11+
"deprecated": "Use var.new_api_key instead, this will be removed in v2.0",
12+
"pos": {
13+
"filename": "testdata/deprecated/deprecated.tf",
14+
"line": 3
15+
}
16+
},
17+
"legacy_endpoint": {
18+
"name": "legacy_endpoint",
19+
"description": "Legacy endpoint URL",
20+
"default": "https://old.example.com",
21+
"required": false,
22+
"deprecated": "This endpoint is deprecated and will be removed",
23+
"pos": {
24+
"filename": "testdata/deprecated/deprecated.tf",
25+
"line": 9
26+
}
27+
},
28+
"current_setting": {
29+
"name": "current_setting",
30+
"type": "string",
31+
"description": "A current setting that is not deprecated",
32+
"default": "default_value",
33+
"required": false,
34+
"pos": {
35+
"filename": "testdata/deprecated/deprecated.tf",
36+
"line": 15
37+
}
38+
}
39+
},
40+
"outputs": {
41+
"old_result": {
42+
"name": "old_result",
43+
"description": "The old result output",
44+
"deprecated": "Use output.new_result instead",
45+
"pos": {
46+
"filename": "testdata/deprecated/deprecated.tf",
47+
"line": 21
48+
}
49+
},
50+
"legacy_data": {
51+
"name": "legacy_data",
52+
"description": "Legacy data output",
53+
"sensitive": true,
54+
"deprecated": "This output is deprecated, use modern_data",
55+
"pos": {
56+
"filename": "testdata/deprecated/deprecated.tf",
57+
"line": 27
58+
}
59+
},
60+
"current_output": {
61+
"name": "current_output",
62+
"description": "A current output that is not deprecated",
63+
"pos": {
64+
"filename": "testdata/deprecated/deprecated.tf",
65+
"line": 34
66+
}
67+
}
68+
},
69+
"managed_resources": {},
70+
"data_resources": {},
71+
"module_calls": {}
72+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
# Module `testdata/deprecated`
3+
4+
## Input Variables
5+
* `current_setting` (default `"default_value"`): A current setting that is not deprecated
6+
* `legacy_endpoint` (default `"https://old.example.com"`): Legacy endpoint URL
7+
* `old_api_key` (required): API key for the old service
8+
9+
## Output Values
10+
* `current_output`: A current output that is not deprecated
11+
* `legacy_data`: Legacy data output
12+
* `old_result`: The old result output
13+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Test file with deprecated variables and outputs
2+
3+
variable "old_api_key" {
4+
type = string
5+
description = "API key for the old service"
6+
deprecated = "Use var.new_api_key instead, this will be removed in v2.0"
7+
}
8+
9+
variable "legacy_endpoint" {
10+
description = "Legacy endpoint URL"
11+
default = "https://old.example.com"
12+
deprecated = "This endpoint is deprecated and will be removed"
13+
}
14+
15+
variable "current_setting" {
16+
description = "A current setting that is not deprecated"
17+
type = string
18+
default = "default_value"
19+
}
20+
21+
output "old_result" {
22+
description = "The old result output"
23+
value = var.old_api_key
24+
deprecated = "Use output.new_result instead"
25+
}
26+
27+
output "legacy_data" {
28+
description = "Legacy data output"
29+
value = var.legacy_endpoint
30+
sensitive = true
31+
deprecated = "This output is deprecated, use modern_data"
32+
}
33+
34+
output "current_output" {
35+
description = "A current output that is not deprecated"
36+
value = var.current_setting
37+
}

tfconfig/variable.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ type Variable struct {
1313
// the native Go type system. The conversion from the value given in
1414
// configuration may be slightly lossy. Only values that can be
1515
// serialized by json.Marshal will be included here.
16-
Default interface{} `json:"default"`
17-
Required bool `json:"required"`
18-
Sensitive bool `json:"sensitive,omitempty"`
16+
Default interface{} `json:"default"`
17+
Required bool `json:"required"`
18+
Sensitive bool `json:"sensitive,omitempty"`
19+
Deprecated string `json:"deprecated,omitempty"`
1920

2021
Pos SourcePos `json:"pos"`
2122
}

0 commit comments

Comments
 (0)