Skip to content

Commit bdb271f

Browse files
yhakbardenis256
andauthored
fix: Fixing .tf vs .tofu extension parity (#4794)
* fix: Using WalkDir over globs for finding TF Files * fix: Use util func * fix: Avoid breaking provider patch * fix: Adding tests * fix: Fixing order of `TestTofuFileExtensionRecognition` cases * fix: Revert disable of build flag * fix: Require both OpenTofu _and_ AWS for state encryption tests * Tests fixes * PR comment fixes * Revert "PR comment fixes" This reverts commit 5d84872. * Benchmark update * Benchmark simplifications * Updated cache tests * Asserts cleanup * Shared cache check * Regexp assert * simplified cache checking * Updated test for re-using versions * Updated tests * Regexp update --------- Co-authored-by: Denis O <denis.o@linux.com>
1 parent 180276f commit bdb271f

11 files changed

Lines changed: 1434 additions & 59 deletions

File tree

.github/workflows/integration-test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
- name: Fixtures with OpenTofu
1717
os: ubuntu
1818
target: ./test
19+
tags: tofu
1920
setup_scripts:
2021
- .github/scripts/setup/tofu-switch.sh
2122
- name: Fixtures with Latest OSS Terraform
@@ -60,7 +61,7 @@ jobs:
6061
- name: AWS Tofu
6162
os: ubuntu
6263
target: ./...
63-
tags: aws
64+
tags: 'aws,tofu'
6465
run: '^TestAws'
6566
secrets: [AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_TEST_S3_ASSUME_ROLE]
6667
setup_scripts:
@@ -112,12 +113,14 @@ jobs:
112113
- name: Provider Cache Server with Tofu
113114
os: ubuntu
114115
target: ./test
116+
tags: tofu
115117
setup_scripts:
116118
- .github/scripts/setup/provider-cache-server.sh
117119
- .github/scripts/setup/tofu-switch.sh
118120
- name: Provider Cache Dir with Tofu
119121
os: ubuntu
120122
target: ./test
123+
tags: tofu
121124
setup_scripts:
122125
- .github/scripts/setup/provider-cache-dir.sh
123126
- .github/scripts/setup/tofu-switch.sh

cli/commands/aws-provider-patch/aws-provider-patch.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"github.com/hashicorp/hcl/v2"
1111
"github.com/hashicorp/hcl/v2/hclwrite"
12-
"github.com/mattn/go-zglob"
1312
ctyjson "github.com/zclconf/go-cty/cty/json"
1413

1514
"github.com/gruntwork-io/terragrunt/cli/commands/run"
@@ -79,7 +78,7 @@ type TerraformModule struct {
7978
// configuration. To be more specific, it only returns the source files downloaded for module "xxx" { ... } blocks into
8079
// the .terraform/modules folder; it does NOT return Terraform files for the top-level (AKA "root") module.
8180
//
82-
// NOTE: this method only supports *.tf files right now. Terraform code defined in *.json files is not currently
81+
// NOTE: this method supports *.tf and *.tofu files. Terraform/OpenTofu code defined in *.json files is not currently
8382
// supported.
8483
func findAllTerraformFilesInModules(opts *options.TerragruntOptions) ([]string, error) {
8584
// Terraform downloads modules into the .terraform/modules folder. Unfortunately, it downloads not only the module
@@ -114,15 +113,17 @@ func findAllTerraformFilesInModules(opts *options.TerragruntOptions) ([]string,
114113
moduleAbsPath = util.JoinPath(opts.WorkingDir, moduleAbsPath)
115114
}
116115

117-
// Ideally, we'd use a builtin Go library like filepath.Glob here, but per https://github.com/golang/go/issues/11862,
118-
// the current go implementation doesn't support treating ** as zero or more directories, just zero or one.
119-
// So we use a third-party library.
120-
matches, err := zglob.Glob(moduleAbsPath + "/**/*.tf")
116+
moduleFiles, err := util.FindTFFiles(moduleAbsPath)
121117
if err != nil {
122118
return nil, errors.New(err)
123119
}
124120

125-
terraformFiles = append(terraformFiles, matches...)
121+
// Filter out JSON files (.tf.json, .tofu.json, or any .json) as hclwrite cannot parse JSON
122+
for _, file := range moduleFiles {
123+
if !strings.HasSuffix(file, ".json") {
124+
terraformFiles = append(terraformFiles, file)
125+
}
126+
}
126127
}
127128
}
128129

0 commit comments

Comments
 (0)