Public/Terraform/Invoke-TerraformValidate.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
function Invoke-TerraformValidate { [CmdletBinding()] param ( # The path to the Terraform Configuration to validate [Parameter( Mandatory = $false, Position = 0 )] [ValidateNotNullOrEmpty()] [string] $TerraformConfigPath = $PWD, # The Path to the Terraform binary [Parameter( Mandatory = $false, ValueFromPipelineByPropertyName = $true )] [ValidateNotNullOrEmpty()] [string] $TerraformPath = 'terraform', # Whether or not to enable color output, defaults to false so as not to break CI/CD tools [Parameter( Mandatory = $false, ValueFromPipelineByPropertyName = $true )] [bool] $EnableColor = $false ) $ValidateArgs = @('validate') if (-not $EnableColor) { $ValidateArgs += '-no-color' } try { $ValidateParams = @{ FilePath = $TerraformPath ArgumentList = $ValidateArgs WorkingDirectory = $TerraformConfigPath SuppressOutput = $true } if ($VerbosePreference -eq 'Continue') { $ValidateParams.Remove('SuppressOutput') } Invoke-NativeCommand @ValidateParams } catch { Write-Error $_.Exception.Message } } |