Skip to content

Commit

Permalink
Continue parsing module files on error (hashicorp#1172)
Browse files Browse the repository at this point in the history
* Add test case with invalid symlink in module

* Continue if we encounter an inaccessible file
  • Loading branch information
dbanck authored Feb 13, 2023
1 parent f4bc3e4 commit b214b93
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion internal/terraform/parser/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ func ParseModuleFiles(fs FS, modPath string) (ast.ModFiles, ast.ModDiags, error)

src, err := fs.ReadFile(fullPath)
if err != nil {
return nil, nil, err
// If a file isn't accessible, continue with reading the
// remaining module files
continue
}

filename := ast.ModFilename(name)
Expand Down
9 changes: 9 additions & 0 deletions internal/terraform/parser/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ func TestParseModuleFiles(t *testing.T) {
},
},
},
{
"invalid-links",
map[string]struct{}{
"resources.tf": {},
},
map[string]hcl.Diagnostics{
"resources.tf": nil,
},
},
}

fs := osFs{}
Expand Down
9 changes: 9 additions & 0 deletions internal/terraform/parser/testdata/invalid-links/resources.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "aws_instance" "web" {
ami = "ami-a0cfeed8"
instance_type = "t2.micro"
user_data = file("init-script.sh")

tags = {
Name = random_pet.name.id
}
}

0 comments on commit b214b93

Please sign in to comment.