Skip to content

Commit 0b15151

Browse files
authored
stacks: remove support for deprecated .tfstack extension (#37617)
* stacks: remove support for deprecated .tfstack extension * also remove from comments and readme
1 parent 3ae4616 commit 0b15151

File tree

6 files changed

+17
-155
lines changed

6 files changed

+17
-155
lines changed

internal/stacks/stackconfig/config_test.go

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,51 +14,6 @@ import (
1414
"github.com/hashicorp/terraform/internal/tfdiags"
1515
)
1616

17-
func TestLoadConfigDirDeprecated(t *testing.T) {
18-
bundle, err := sourcebundle.OpenDir("testdata/basics-bundle")
19-
if err != nil {
20-
t.Fatal(err)
21-
}
22-
23-
rootAddr := sourceaddrs.MustParseSource("git::https://example.com/deprecated.git").(sourceaddrs.RemoteSource)
24-
_, gotDiags := LoadConfigDir(rootAddr, bundle)
25-
26-
wantDiags := tfdiags.Diagnostics{
27-
tfdiags.Sourceless(tfdiags.Warning, "Deprecated filename usage", "This configuration is using the deprecated .tfstack.hcl or .tfstack.json file extensions. This will not be supported in a future version of Terraform, please update your files to use the latest .tfcomponent.hcl or .tfcomponent.json file extensions."),
28-
}
29-
30-
count := len(wantDiags)
31-
if len(gotDiags) > count {
32-
count = len(gotDiags)
33-
}
34-
35-
for i := 0; i < count; i++ {
36-
if i >= len(wantDiags) {
37-
t.Errorf("unexpected diagnostic:\n%s", gotDiags[i])
38-
continue
39-
}
40-
41-
if i >= len(gotDiags) {
42-
t.Errorf("missing diagnostic:\n%s", wantDiags[i])
43-
continue
44-
}
45-
46-
got, want := gotDiags[i], wantDiags[i]
47-
48-
if got, want := got.Severity(), want.Severity(); got != want {
49-
t.Errorf("diagnostics[%d] severity\ngot: %s\nwant: %s", i, got, want)
50-
}
51-
52-
if got, want := got.Description().Summary, want.Description().Summary; got != want {
53-
t.Errorf("diagnostics[%d] summary\ngot: %s\nwant: %s", i, got, want)
54-
}
55-
56-
if got, want := got.Description().Detail, want.Description().Detail; got != want {
57-
t.Errorf("diagnostics[%d] detail\ngot: %s\nwant: %s", i, got, want)
58-
}
59-
}
60-
}
61-
6217
func TestLoadConfigDirErrors(t *testing.T) {
6318
bundle, err := sourcebundle.OpenDir("testdata/basics-bundle")
6419
if err != nil {

internal/stacks/stackconfig/file.go

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -155,34 +155,28 @@ func DecodeFileBody(body hcl.Body, fileAddr sourceaddrs.FinalSource) (*File, tfd
155155
return ret, diags
156156
}
157157

158-
// ParseFileSource parses the given source code as the content of a Stacks
159-
// component file and then delegates the result to [DecodeFileBody] for
160-
// analysis, returning that final result.
161-
//
162-
// For now, we support both the .tfstack. and .tfcomponent. file suffixes while
163-
// the former is still in the process of being deprecated. It is not valid for
164-
// a single stack to mix and match the two options. We are, therefore, accepting
165-
// a "prior suffix" argument which lets us know which suffix was used by other
166-
// files in this stack.
158+
// ParseFileSource parses the given source code as the content of either a
159+
// .tfcomponent.hcl or .tfcomponent.json file, and then delegates the result to
160+
// [DecodeFileBody] for analysis, returning that final result.
167161
//
168162
// ParseFileSource chooses between native vs. JSON syntax based on the suffix
169163
// of the filename in the given source address, which must be either
170-
// ".[tfstack|tfcomponent].hcl" or ".[tfstack|tfcomponent].json".
171-
func ParseFileSource(src []byte, suffix string, fileAddr sourceaddrs.FinalSource) (*File, tfdiags.Diagnostics) {
164+
// ".tfcomponent.hcl" or ".tfcomponent.json".
165+
func ParseFileSource(src []byte, fileAddr sourceaddrs.FinalSource) (*File, tfdiags.Diagnostics) {
172166
var diags tfdiags.Diagnostics
173167

174168
filename := sourceaddrs.FinalSourceFilename(fileAddr)
175169

176170
var body hcl.Body
177-
switch {
178-
case strings.HasSuffix(filename, fmt.Sprintf(".%s.hcl", suffix)):
171+
switch validFilenameSuffix(filename) {
172+
case ".tfcomponent.hcl":
179173
hclFile, hclDiags := hclsyntax.ParseConfig(src, fileAddr.String(), hcl.InitialPos)
180174
diags = diags.Append(hclDiags)
181175
if diags.HasErrors() {
182176
return nil, diags
183177
}
184178
body = hclFile.Body
185-
case strings.HasSuffix(filename, fmt.Sprintf(".%s.json", suffix)):
179+
case ".tfcomponent.json":
186180
hclFile, hclDiags := hcljson.Parse(src, fileAddr.String())
187181
diags = diags.Append(hclDiags)
188182
if diags.HasErrors() {
@@ -194,8 +188,8 @@ func ParseFileSource(src []byte, suffix string, fileAddr sourceaddrs.FinalSource
194188
tfdiags.Error,
195189
"Unsupported file type",
196190
fmt.Sprintf(
197-
"Cannot load %s as a stack configuration file: filename must have either a .%s.hcl or .%s.json suffix.",
198-
fileAddr, suffix, suffix,
191+
"Cannot load %s as a stack configuration file: filename must have either a .tfcomponent.hcl or .tfcomponent.json suffix.",
192+
fileAddr,
199193
),
200194
))
201195
return nil, diags
@@ -209,23 +203,15 @@ func ParseFileSource(src []byte, suffix string, fileAddr sourceaddrs.FinalSource
209203
// validFilenameSuffix returns ".tfcomponent.hcl" or ".tfcomponent.json" if the
210204
// given filename ends with that suffix, and otherwise returns an empty
211205
// string to indicate that the suffix was invalid.
212-
//
213-
// We still support the deprecated .tfstack suffix for the time being.
214206
func validFilenameSuffix(filename string) string {
215207
const nativeSuffix = ".tfcomponent.hcl"
216208
const jsonSuffix = ".tfcomponent.json"
217-
const deprecatedNativeSuffix = ".tfstack.hcl"
218-
const deprecatedJsonSuffix = ".tfstack.json"
219209

220210
switch {
221-
case strings.HasSuffix(filename, deprecatedNativeSuffix):
222-
return "tfstack"
223-
case strings.HasSuffix(filename, deprecatedJsonSuffix):
224-
return "tfstack"
225211
case strings.HasSuffix(filename, nativeSuffix):
226-
return "tfcomponent"
212+
return nativeSuffix
227213
case strings.HasSuffix(filename, jsonSuffix):
228-
return "tfcomponent"
214+
return jsonSuffix
229215
default:
230216
return ""
231217
}

internal/stacks/stackconfig/stack.go

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,12 @@ func LoadSingleStackConfig(sourceAddr sourceaddrs.FinalSource, sources *sourcebu
9090
Declarations: makeDeclarations(),
9191
}
9292

93-
var priorSuffix string
9493
for _, entry := range allEntries {
95-
suffix := validFilenameSuffix(entry.Name())
96-
if suffix == "" {
94+
if suffix := validFilenameSuffix(entry.Name()); suffix == "" {
9795
// not a file we're interested in, then
9896
continue
9997
}
10098

101-
if priorSuffix == "" {
102-
priorSuffix = suffix
103-
} else if priorSuffix != suffix {
104-
diags = diags.Append(tfdiags.Sourceless(
105-
tfdiags.Error,
106-
"Invalid stack configuration directory",
107-
"This stack configuration has mixed the deprecated .tfstack.hcl or .tfstack.json file extensions with the latest .tfcomponent.hcl or .tfcomponent.json file extensions. Update all files to the latest .tfcomponent file extension.",
108-
))
109-
continue
110-
}
111-
11299
asLocalSourcePath := "./" + filepath.Base(entry.Name())
113100
relSource, err := sourceaddrs.ParseLocalSource(asLocalSourcePath)
114101
if err != nil {
@@ -143,7 +130,7 @@ func LoadSingleStackConfig(sourceAddr sourceaddrs.FinalSource, sources *sourcebu
143130
))
144131
}
145132

146-
file, moreDiags := ParseFileSource(src, priorSuffix, fileSourceAddr)
133+
file, moreDiags := ParseFileSource(src, fileSourceAddr)
147134
diags = diags.Append(moreDiags)
148135
if moreDiags.HasErrors() {
149136
// We'll still try to analyze other files, so we can gather up
@@ -176,13 +163,5 @@ func LoadSingleStackConfig(sourceAddr sourceaddrs.FinalSource, sources *sourcebu
176163
pc.ProviderAddr = providerAddr
177164
}
178165

179-
if priorSuffix == "tfstack" {
180-
diags = diags.Append(&hcl.Diagnostic{
181-
Severity: hcl.DiagWarning,
182-
Summary: "Deprecated filename usage",
183-
Detail: "This configuration is using the deprecated .tfstack.hcl or .tfstack.json file extensions. This will not be supported in a future version of Terraform, please update your files to use the latest .tfcomponent.hcl or .tfcomponent.json file extensions.",
184-
})
185-
}
186-
187166
return ret, diags
188167
}

internal/stacks/stackconfig/testdata/basics-bundle/deprecated/component/main.tf

Lines changed: 0 additions & 17 deletions
This file was deleted.

internal/stacks/stackconfig/testdata/basics-bundle/deprecated/main.tfstack.hcl

Lines changed: 0 additions & 41 deletions
This file was deleted.

internal/stacks/stackruntime/internal/stackeval/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ There are various pairs of types in this package that represent a static object
3939
in the configuration and dynamic instances of that object respectively.
4040

4141
For example, `InputVariableConfig` directly represents a `variable` block
42-
from a `.tfstack.hcl` file, while `InputVariable` represents the possibly-many
43-
dynamic instances of that object that can be caused by being within a stack
44-
that was called using `for_each`.
42+
from a `.tfcomponent.hcl` file, while `InputVariable` represents the
43+
possibly-many dynamic instances of that object that can be caused by being
44+
within a stack that was called using `for_each`.
4545

4646
In general, the static types are responsible for "static validation"-type tasks,
4747
such as checking whether expressions refer to instances of other configuration

0 commit comments

Comments
 (0)