Skip to content

Commit

Permalink
Merge pull request #4 from ptavares/sparkles/switch_tfsec_to_trivy
Browse files Browse the repository at this point in the history
💥 switch tfsec to trivy
  • Loading branch information
ptavares committed Mar 10, 2024
2 parents d025f27 + 6e5adc6 commit 781c389
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
![PowerShell Gallery Version (including pre-releases)](https://img.shields.io/powershellgallery/v/terraform-tools)
![PowerShell Gallery](https://img.shields.io/powershellgallery/dt/terraform-tools)


## Description
## Description

A [PowerShell](https://www.powershellgallery.com/packages/terraform-tools/) module for [Terraform](https://www.terraform.io/), a tool from [Hashicorp](https://www.hashicorp.com/) for managing infrastructure safely and efficiently.

It will install the following [Terraform](https://www.terraform.io/) tools :

- [terraform-switcher](https://github.com/warrensbox/terraform-switcher)
- [terraform-docs](https://github.com/terraform-docs/terraform-docs)
- [tfsec](https://github.com/aquasecurity/tfsec)
- [trivy](https://github.com/aquasecurity/trivy)
- [tflint](https://github.com/terraform-linters/tflint)
- [tfautomv](https://github.com/busser/tfautomv)

Expand All @@ -25,7 +25,7 @@ It also provides some useful terraform aliases for everyday use.

Install or update from [PowerShell Gallery](https://www.powershellgallery.com/packages/terraform-tools/)

- Install
- Install

```powershell
Install-Module terraform-tools -Scope CurrentUser -AllowClobber
Expand Down Expand Up @@ -130,4 +130,4 @@ Update-TerraformTools

## License

[MIT](./LICENCE)
[MIT](./LICENCE)
32 changes: 20 additions & 12 deletions terraform-tools/terraform-tools.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# =========================================================
$API_GITUB = "https://api.github.com/repos"
$TF_DOCS_RELEASE = "terraform-docs/terraform-docs/releases"
$TF_SEC_RELEASE = "aquasecurity/tfsec/releases"
$TF_TRIVY_RELEASE = "aquasecurity/trivy/releases"
$TF_LINT_RELEASE = "terraform-linters/tflint/releases"
$TF_AUTO_MV_RELEASE = "busser/tfautomv/releases"
$TF_SWITCHER_RELEASE = "warrensbox/terraform-switcher/releases"
Expand All @@ -24,7 +24,7 @@ $env:TF_TOOLS_HOME = "$env:USERPROFILE\.terrafom-tools"
# Define Module file to store tools version
# =========================================================
$TF_DOCS_VERSION_FILE = Join-Path $env:TF_TOOLS_HOME "version_tfdocs.txt"
$TF_SEC_VERSION_FILE = Join-Path $env:TF_TOOLS_HOME "version_tfsec.txt"
$TF_TRIVY_VERSION_FILE = Join-Path $env:TF_TOOLS_HOME "version_trivy.txt"
$TF_LINT_VERSION_FILE = Join-Path $env:TF_TOOLS_HOME "version_tflint.txt"
$TF_AUTO_MV_VERSION_FILE = Join-Path $env:TF_TOOLS_HOME "version_tfautomv.txt"
$TF_SWITCHER_VERSION_FILE = Join-Path $env:TF_TOOLS_HOME "version_tfswitch.txt"
Expand Down Expand Up @@ -128,11 +128,19 @@ function Install-DownloadTerraformTools {
Remove-Item "$DestDir\*.zip"
$Version | Out-File $TF_DOCS_VERSION_FILE
}
"tfsec" {
$url = "https://github.com/$TF_SEC_RELEASE/download/$Version/tfsec-checkgen-windows-$architecture.exe"
Invoke-RestMethod -Uri $url -OutFile "$DestDir\tfsec.exe"
Set-ItemProperty -Path "$DestDir\tfsec.exe" -Name IsReadOnly -Value $false
$Version | Out-File $TF_SEC_VERSION_FILE
"trivy" {
if ($architecture -eq "amd64") {
$architecture = "64bit"
}
else {
$architecture = "32bit"
}
$SimpleVersion = $Version.Substring(1) + "_windows"
$url = "https://github.com/$TF_TRIVY_RELEASE/download/$Version/trivy_$SimpleVersion-$architecture.zip"
Invoke-RestMethod -Uri $url -OutFile "$DestDir\tmp.zip"
Expand-Archive -Path "$DestDir\tmp.zip"-DestinationPath $DestDir -Force | Out-Null
Remove-Item "$DestDir\*.zip"
$Version | Out-File $TF_TRIVY_VERSION_FILE
}
"tflint" {
$url = "https://github.com/$TF_LINT_RELEASE/download/$Version/tflint_windows_$architecture.zip"
Expand Down Expand Up @@ -213,8 +221,8 @@ function Install-TerraformTools {

# Install tfdocs
Install-TerraformTool "tfdocs" $TF_DOCS_RELEASE
# Install tfsec
Install-TerraformTool "tfsec" $TF_SEC_RELEASE
# Install trivy
Install-TerraformTool "trivy" $TF_TRIVY_RELEASE
# Install tflint
Install-TerraformTool "tflint" $TF_LINT_RELEASE
# Install tfautomv
Expand Down Expand Up @@ -282,8 +290,8 @@ function Update-TerraformTools {

# Update tfdocs
Update-TerraformTool -ToolName "tfdocs" -ReleaseFile $TF_DOCS_VERSION_FILE -ReleaseURL $TF_DOCS_RELEASE
# Update tfsec
Update-TerraformTool -ToolName "tfsec" -ReleaseFile $TF_SEC_VERSION_FILE -ReleaseURL $TF_SEC_RELEASE
# Update trivy
Update-TerraformTool -ToolName "trivy" -ReleaseFile $TF_TRIVY_VERSION_FILE -ReleaseURL $TF_TRIVY_RELEASE
# Update tflint
Update-TerraformTool -ToolName "tflint" -ReleaseFile $TF_LINT_VERSION_FILE -ReleaseURL $TF_LINT_RELEASE
# Update tfautomv
Expand Down Expand Up @@ -314,7 +322,7 @@ function TerraformToolsLoads {
Write-TerraformToolLog "Blue" "Expanding user PATH with tools..."
# Export PATH
TerraformToolsAddToPath "$env:TF_TOOLS_HOME\tfdocs"
TerraformToolsAddToPath "$env:TF_TOOLS_HOME\tfsec"
TerraformToolsAddToPath "$env:TF_TOOLS_HOME\trivy"
TerraformToolsAddToPath "$env:TF_TOOLS_HOME\tflint"
TerraformToolsAddToPath "$env:TF_TOOLS_HOME\tfautomv"
TerraformToolsAddToPath "$env:TF_TOOLS_HOME\tfswitch"
Expand Down

0 comments on commit 781c389

Please sign in to comment.