Skip to content

Commit 1c09455

Browse files
authored
[QT-529] Always generate a Terraform configuration files (#81)
Enos scenarios always override the CLI configuration file to ensure that we don't accidentally inherit global configuration. Previously we relied on simply setting the environment variable and geneating actual contents only if they were set in the scenario. Terraform 1.4.2 changed the behavior to warn if the environment variable was set to a non-existent file. Now we always create the file even if it's blank. Signed-off-by: Ryan Cragun <[email protected]>
1 parent dd2a404 commit 1c09455

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

internal/generate/generate.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,21 @@ func (g *Generator) TerraformModuleDir() string {
158158
// file.
159159
func (g *Generator) generateCLIConfig() error {
160160
if g.Scenario.TerraformCLI == nil || g.Scenario.TerraformCLI.ConfigVal.IsNull() {
161-
return nil
161+
// Always generate a configuration file even if we have not been configured
162+
// with any configuration content. Enos scenarios are always configured
163+
// with a CLI file so that we don't accidentally inherit something
164+
// unexpected from common Terraform configuration directories.
165+
// Starting with Terraform 1.4.2 this is actually a requirement as
166+
// it will warn if the file override does not exist.
167+
168+
// Make sure our out directory exists and is a directory
169+
err := g.ensureOutDir()
170+
if err != nil {
171+
return err
172+
}
173+
174+
// Write our RC file to disk
175+
return g.write(g.TerraformRCPath(), nil)
162176
}
163177

164178
rc := hclwrite.NewEmptyFile()

0 commit comments

Comments
 (0)