@@ -51,22 +51,35 @@ func TerraformVet(t testing.TB, terraformDir, policyPath, project string) error
5151 return err
5252 }
5353 jsonFile , err := utils .WriteTmpFileWithExtension (jsonPlan , "json" )
54- defer os .Remove (jsonFile )
55- defer os .Remove (options .PlanFilePath )
54+
55+ defer func () {
56+ err := os .Remove (jsonFile )
57+ if err != nil {
58+ fmt .Fprintf (os .Stderr , "Error removing file: %s\n " , err )
59+ }
60+ }()
61+
62+ defer func () {
63+ err := os .Remove (options .PlanFilePath )
64+ if err != nil {
65+ fmt .Fprintf (os .Stderr , "Error removing file: %s\n " , err )
66+ }
67+ }()
68+
5669 if err != nil {
5770 return err
5871 }
5972 command := fmt .Sprintf ("beta terraform vet %s --policy-library=%s --project=%s --quiet" , jsonFile , policyPath , project )
6073 result , err := gcloud .RunCmdE (t , command )
61- if err != nil && ! ( strings .Contains (err .Error (), "Validating resources" ) && strings .Contains (err .Error (), "done" )) {
74+ if err != nil && ( ! strings .Contains (err .Error (), "Validating resources" ) || ! strings .Contains (err .Error (), "done" )) {
6275 return err
6376 }
6477 if ! gjson .Valid (result ) {
65- return fmt .Errorf ("Error parsing output, invalid json: %s" , result )
78+ return fmt .Errorf ("error parsing output, invalid json: %s" , result )
6679 }
6780
6881 if len (gjson .Parse (result ).Array ()) > 0 {
69- return fmt .Errorf ("Policy violations found: %s" , result )
82+ return fmt .Errorf ("policy violations found: %s" , result )
7083 }
7184 fmt .Println ("" )
7285 fmt .Println ("# The configuration passed tf vet." )
0 commit comments