Skip to content

Commit

Permalink
wont crash from parsing failure
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesWoolfenden committed Aug 4, 2022
1 parent c099b5b commit 18d281a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
7 changes: 5 additions & 2 deletions src/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

// GetResources retrieves all the resources in a tf file
func GetResources(file string) []Resource {
func GetResources(file string) ([]Resource, error) {

var results []Resource

Expand All @@ -26,6 +26,9 @@ func GetResources(file string) []Resource {
log.Printf("failed to parse %s", file)
}

if myCode == nil {
return nil, errors.New("parsing error: no code parsed")
}
Tree := myCode.Node.(*ast.ObjectList)

for _, item := range Tree.Items {
Expand All @@ -37,7 +40,7 @@ func GetResources(file string) []Resource {
}

// resources, filename, code
return results
return results, nil
}

// GetProvider retrieves the provider from the resource
Expand Down
8 changes: 7 additions & 1 deletion src/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pike

import (
"io/ioutil"
"log"
"path/filepath"
)

Expand All @@ -22,7 +23,12 @@ func Scan(dirname string) error {

for _, file := range files {

resources := GetResources(file)
resources, err := GetResources(file)

if err != nil {
//parse the other files
log.Print(err)
}

for _, resource := range resources {
hcltype := GetHCLType(resource)
Expand Down
6 changes: 3 additions & 3 deletions terraform/backup/aws_instance.a.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ resource "aws_instance" "name" {
#iam_instance_profile =
key_name = "test"
monitoring = false
# tags = {
# "createdby" = "james"
# }
tags = {
"createdby" = "james"
}
}
6 changes: 3 additions & 3 deletions terraform/backup/aws_lambda_function.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ resource "aws_lambda_function" "examplea" {
handler = "anyoldguff"
runtime = "python3.8"
filename = "todo.zip"
# tags = {
# createdby="james woolfenden"
# }
tags = {
createdby = "james woolfenden"
}
}
4 changes: 2 additions & 2 deletions terraform/backup/aws_network_acl.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "aws_network_acl" "example" {
vpc_id = "vpc-0c9622709bb598517"
vpc_id = aws_vpc.example.id

egress {
protocol = "tcp"
Expand All @@ -22,4 +22,4 @@ resource "aws_network_acl" "example" {
# tags = {
# Name = "main"
# }
}
}

0 comments on commit 18d281a

Please sign in to comment.