-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
10f04a1
commit b7ab258
Showing
4 changed files
with
54 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
- id: terraform-fmt | ||
name: Terraform Format | ||
description: The terraform fmt command is used to rewrite Terraform configuration files to a canonical format and style. | ||
entry: terraform-fmt | ||
exclude: \.terraform/.*$ | ||
files: (\.tf|\.tfvars)$ | ||
language: golang | ||
name: Terraform Format | ||
require_serial: true | ||
|
||
- id: terraform-validate | ||
description: The terraform validate command validates the configuration files in a directory, referring only to the configuration and not accessing any remote services such as remote state, provider APIs, etc. | ||
entry: terraform-validate | ||
exclude: \.terraform/.*$ | ||
files: (\.tf|\.tfvars)$ | ||
language: golang | ||
files: \.tf$ | ||
name: Terraform Validate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
|
||
"github.com/osinfra-io/pre-commit-hooks/internal/outputs" | ||
) | ||
|
||
func checkTerraformInstalled() bool { | ||
_, err := exec.LookPath("terraform") | ||
return err == nil | ||
} | ||
|
||
func main() { | ||
if !checkTerraformInstalled() { | ||
fmt.Println("Terraform is not installed or not in PATH.") | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Println(outputs.EmojiColorText(outputs.Running, "Running terraform validate...", outputs.Purple)) | ||
|
||
// Run terraform validate | ||
cmd := exec.Command("terraform", "validate") | ||
_, err := cmd.CombinedOutput() | ||
if err != nil { | ||
// Check if the error is an ExitError | ||
if _, ok := err.(*exec.ExitError); ok { | ||
// Handle specific exit codes if necessary | ||
fmt.Printf(outputs.EmojiColorText(outputs.Error, "Terraform validate failed: %v\n", outputs.Red), err) | ||
} else { | ||
fmt.Printf(outputs.EmojiColorText(outputs.Error, "Error running terraform validate: %v\n", outputs.Red), err) | ||
} | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Println(outputs.EmojiColorText(outputs.ThumbsUp, "Terraform validate completed successfully.", outputs.Green)) | ||
} |
File renamed without changes.