diff --git a/.appveyor.yml b/.appveyor.yml
index 0b365f1..0a58f15 100644
--- a/.appveyor.yml
+++ b/.appveyor.yml
@@ -1,13 +1,29 @@
#---------------------------------#
# Build Image #
#---------------------------------#
-image: Visual Studio 2017
+image: Visual Studio 2022
+
+#---------------------------------#
+# Install .NET #
+#---------------------------------#
+install:
+ - ps: $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetsdk"
+ - ps: mkdir $env:DOTNET_INSTALL_DIR -Force | Out-Null
+ - ps: Invoke-WebRequest -Uri "https://dotnet.microsoft.com/download/dotnet/scripts/v1/dotnet-install.ps1" -OutFile "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1"
+ - ps: '& "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1" -Channel 2.1 -InstallDir $env:DOTNET_INSTALL_DIR'
+ - ps: '& "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1" -Channel 3.1 -InstallDir $env:DOTNET_INSTALL_DIR'
+ - ps: '& "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1" -Channel 5.0 -InstallDir $env:DOTNET_INSTALL_DIR'
+ - ps: '& "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1" -Channel 6.0 -InstallDir $env:DOTNET_INSTALL_DIR'
+ - ps: '& "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1" -Channel 7.0 -InstallDir $env:DOTNET_INSTALL_DIR'
+ - ps: '& "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1" -Channel 8.0 -InstallDir $env:DOTNET_INSTALL_DIR'
+ - ps: $env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path"
+ - ps: dotnet --info
#---------------------------------#
# Build Script #
#---------------------------------#
build_script:
- - ps: .\build.ps1 -Target AppVeyor
+ - ps: .\build.ps1 --target=CI
#---------------------------------#
# Tests
@@ -40,7 +56,7 @@ branches:
# Build Cache #
#---------------------------------#
cache:
-- tools -> recipe.cake, tools/packages.config
+- tools -> recipe.cake
#---------------------------------#
# Skip builds for doc changes #
diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json
new file mode 100644
index 0000000..4903ba5
--- /dev/null
+++ b/.config/dotnet-tools.json
@@ -0,0 +1,12 @@
+{
+ "version": 1,
+ "isRoot": true,
+ "tools": {
+ "cake.tool": {
+ "version": "1.3.0",
+ "commands": [
+ "dotnet-cake"
+ ]
+ }
+ }
+}
\ No newline at end of file
diff --git a/.github/renovate.json b/.github/renovate.json
new file mode 100644
index 0000000..3fd97a5
--- /dev/null
+++ b/.github/renovate.json
@@ -0,0 +1,14 @@
+{
+ "$schema": "https://docs.renovatebot.com/renovate-schema.json",
+ "extends": [
+ "github>cake-contrib/renovate-presets:cake-recipe",
+ "github>cake-contrib/renovate-presets:github-actions" ],
+ "packageRules": [
+ {
+ "description": "Updates to Cake.Core references are breaking.",
+ "matchPackageNames": ["Cake.Core"],
+ "matchUpdateTypes": ["major"],
+ "labels": ["Breaking Change"]
+ }
+ ]
+}
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 0000000..5b453d2
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -0,0 +1,84 @@
+name: Build
+
+on:
+ push:
+ branches:
+ - master
+ - develop
+ - "feature/**"
+ - "release/**"
+ - "hotfix/**"
+ tags:
+ - "*"
+ paths-ignore:
+ - "README.md"
+ pull_request:
+
+jobs:
+ build:
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ os: [ windows-2022, ubuntu-22.04, macos-12 ]
+
+ env:
+ AZURE_PASSWORD: ${{ secrets.AZURE_PASSWORD }}
+ AZURE_SOURCE: ${{ secrets.AZURE_SOURCE }}
+ AZURE_USER: ${{ secrets.AZURE_USER }}
+ COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
+ GITHUB_PAT: ${{ secrets.GH_TOKEN }}
+ GITTER_ROOM_ID: ${{ secrets.GITTER_ROOM_ID }}
+ GITTER_TOKEN: ${{ secrets.GITTER_TOKEN }}
+ GPR_PASSWORD: ${{ secrets.GPR_PASSWORD }}
+ GPR_SOURCE: ${{ secrets.GPR_SOURCE }}
+ GPR_USER: ${{ secrets.GPR_USER }}
+ NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
+ NUGET_SOURCE: "https://api.nuget.org/v3/index.json"
+ TWITTER_ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }}
+ TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }}
+ TWITTER_CONSUMER_KEY: ${{ secrets.TWITTER_CONSUMER_KEY }}
+ TWITTER_CONSUMER_SECRET: ${{ secrets.TWITTER_CONSUMER_SECRET }}
+ WYAM_ACCESS_TOKEN: ${{ secrets.WYAM_ACCESS_TOKEN }}
+ WYAM_DEPLOY_BRANCH: "gh-pages"
+ WYAM_DEPLOY_REMOTE: ${{ github.event.repository.html_url }}
+
+ steps:
+ - name: Checkout the repository
+ uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
+ - name: Fetch all tags and branches
+ run: git fetch --prune --unshallow
+ - uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4.0.0
+ with:
+ dotnet-version: |
+ 2.1.818
+ 3.1.x
+ 5.0.x
+ 6.0.x
+ 7.0.x
+ 8.0.x
+ - name: Cache Tools
+ uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
+ with:
+ path: tools
+ key: ${{ runner.os }}-tools-${{ hashFiles('recipe.cake') }}
+ - name: Build project
+ uses: cake-build/cake-action@a6eb054329257c9e70a6c6bf01747ad6e1d9d52b # v1
+ with:
+ script-path: recipe.cake
+ target: CI
+ cake-version: tool-manifest
+ - name: Upload Issues
+ uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4
+ with:
+ if-no-files-found: warn
+ name: ${{ matrix.os }} Issues
+ path: |
+ BuildArtifacts/report.html
+ BuildArtifacts/**/coverlet/*.xml
+ - name: Upload Packages
+ uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4
+ if: runner.os == 'Windows'
+ with:
+ if-no-files-found: warn
+ name: package
+ path: BuildArtifacts/Packages/**/*
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
new file mode 100644
index 0000000..2bcd15c
--- /dev/null
+++ b/.github/workflows/codeql-analysis.yml
@@ -0,0 +1,67 @@
+# For most projects, this workflow file will not need changing; you simply need
+# to commit it to your repository.
+#
+# You may wish to alter this file to override the set of languages analyzed,
+# or to provide custom queries or build logic.
+name: "CodeQL"
+
+on:
+ push:
+ branches: [develop]
+ pull_request:
+ # The branches below must be a subset of the branches above
+ branches: [develop]
+ schedule:
+ - cron: '0 15 * * 6'
+ workflow_dispatch:
+
+jobs:
+ analyze:
+ name: Analyze
+ runs-on: ubuntu-22.04
+
+ strategy:
+ fail-fast: false
+ matrix:
+ # Override automatic language detection by changing the below list
+ # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
+ language: ['csharp']
+ # Learn more...
+ # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
+ with:
+ fetch-depth: 0
+ - uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4.0.0
+ with:
+ dotnet-version: |
+ 5.0.x
+ 8.0.x
+
+ - name: Cache Tools
+ uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
+ with:
+ path: tools
+ key: ${{ runner.os }}-tools-${{ hashFiles('recipe.cake') }}
+
+ # Initializes the CodeQL tools for scanning.
+ - name: Initialize CodeQL
+ uses: github/codeql-action/init@9fdb3e49720b44c48891d036bb502feb25684276 # v3
+ with:
+ languages: ${{ matrix.language }}
+ # If you wish to specify custom queries, you can do so here or in a config file.
+ # By default, queries listed here will override any specified in a config file.
+ # Prefix the list here with "+" to use these queries and those in the config file.
+ # queries: ./path/to/local/query, your-org/your-repo/queries@main
+
+ - name: Build project
+ uses: cake-build/cake-action@a6eb054329257c9e70a6c6bf01747ad6e1d9d52b # v1
+ with:
+ script-path: recipe.cake
+ target: DotNetCore-Build
+ cake-version: tool-manifest
+
+ - name: Perform CodeQL Analysis
+ uses: github/codeql-action/analyze@9fdb3e49720b44c48891d036bb502feb25684276 # v3
diff --git a/build.ps1 b/build.ps1
index a6d30c4..35df8f8 100644
--- a/build.ps1
+++ b/build.ps1
@@ -1,184 +1,11 @@
-##########################################################################
-# This is the Cake bootstrapper script for PowerShell.
-# This file was downloaded from https://github.com/cake-build/resources
-# Feel free to change this file to fit your needs.
-##########################################################################
+Set-Location -LiteralPath $PSScriptRoot
-<#
-.SYNOPSIS
-This is a Powershell script to bootstrap a Cake build.
-.DESCRIPTION
-This Powershell script will download NuGet if missing, restore NuGet tools (including Cake)
-and execute your Cake build script with the parameters you provide.
-.PARAMETER Script
-The build script to execute.
-.PARAMETER Target
-The build script target to run.
-.PARAMETER Configuration
-The build configuration to use.
-.PARAMETER Verbosity
-Specifies the amount of information to be displayed.
-.PARAMETER Experimental
-Tells Cake to use the latest Roslyn release.
-.PARAMETER WhatIf
-Performs a dry run of the build script.
-No tasks will be executed.
-.PARAMETER Mono
-Tells Cake to use the Mono scripting engine.
-.PARAMETER SkipToolPackageRestore
-Skips restoring of packages.
-.PARAMETER ScriptArgs
-Remaining arguments are added here.
-.LINK
-http://cakebuild.net
-#>
+$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = '1'
+$env:DOTNET_CLI_TELEMETRY_OPTOUT = '1'
+$env:DOTNET_NOLOGO = '1'
-[CmdletBinding()]
-Param(
- [string]$Script = "recipe.cake",
- [string]$Target = "Default",
- [ValidateSet("Release", "Debug")]
- [string]$Configuration = "Release",
- [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
- [string]$Verbosity = "Verbose",
- [switch]$Experimental,
- [Alias("DryRun","Noop")]
- [switch]$WhatIf,
- [switch]$Mono,
- [switch]$SkipToolPackageRestore,
- [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
- [string[]]$ScriptArgs
-)
+dotnet tool restore
+if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
-[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null
-function MD5HashFile([string] $filePath)
-{
- if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf))
- {
- return $null
- }
-
- [System.IO.Stream] $file = $null;
- [System.Security.Cryptography.MD5] $md5 = $null;
- try
- {
- $md5 = [System.Security.Cryptography.MD5]::Create()
- $file = [System.IO.File]::OpenRead($filePath)
- return [System.BitConverter]::ToString($md5.ComputeHash($file))
- }
- finally
- {
- if ($file -ne $null)
- {
- $file.Dispose()
- }
- }
-}
-
-Write-Host "Preparing to run build script..."
-
-if(!$PSScriptRoot){
- $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
-}
-
-$TOOLS_DIR = Join-Path $PSScriptRoot "tools"
-$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe"
-$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe"
-$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
-$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config"
-$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum"
-
-# Should we use mono?
-$UseMono = "";
-if($Mono.IsPresent) {
- Write-Verbose -Message "Using the Mono based scripting engine."
- $UseMono = "-mono"
-}
-
-# Should we use the new Roslyn?
-$UseExperimental = "";
-if($Experimental.IsPresent -and !($Mono.IsPresent)) {
- Write-Verbose -Message "Using experimental version of Roslyn."
- $UseExperimental = "-experimental"
-}
-
-# Is this a dry run?
-$UseDryRun = "";
-if($WhatIf.IsPresent) {
- $UseDryRun = "-dryrun"
-}
-
-# Make sure tools folder exists
-if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) {
- Write-Verbose -Message "Creating tools directory..."
- New-Item -Path $TOOLS_DIR -Type directory | out-null
-}
-
-# Make sure that packages.config exist.
-if (!(Test-Path $PACKAGES_CONFIG)) {
- Write-Verbose -Message "Downloading packages.config..."
- try { (New-Object System.Net.WebClient).DownloadFile("http://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch {
- Throw "Could not download packages.config."
- }
-}
-
-# Try find NuGet.exe in path if not exists
-if (!(Test-Path $NUGET_EXE)) {
- Write-Verbose -Message "Trying to find nuget.exe in PATH..."
- $existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_) }
- $NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1
- if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) {
- Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)."
- $NUGET_EXE = $NUGET_EXE_IN_PATH.FullName
- }
-}
-
-# Try download NuGet.exe if not exists
-if (!(Test-Path $NUGET_EXE)) {
- Write-Verbose -Message "Downloading NuGet.exe..."
- try {
- (New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE)
- } catch {
- Throw "Could not download NuGet.exe."
- }
-}
-
-# Save nuget.exe path to environment to be available to child processed
-$ENV:NUGET_EXE = $NUGET_EXE
-
-# Restore tools from NuGet?
-if(-Not $SkipToolPackageRestore.IsPresent) {
- Push-Location
- Set-Location $TOOLS_DIR
-
- # Check for changes in packages.config and remove installed tools if true.
- [string] $md5Hash = MD5HashFile($PACKAGES_CONFIG)
- if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or
- ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) {
- Write-Verbose -Message "Missing or changed package.config hash..."
- Remove-Item * -Recurse -Exclude packages.config,nuget.exe
- }
-
- Write-Verbose -Message "Restoring tools from NuGet..."
- $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -PreRelease -OutputDirectory `"$TOOLS_DIR`" -Source https://www.myget.org/F/cake/api/v3/index.json"
-
- if ($LASTEXITCODE -ne 0) {
- Throw "An error occured while restoring NuGet tools."
- }
- else
- {
- $md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII"
- }
- Write-Verbose -Message ($NuGetOutput | out-string)
- Pop-Location
-}
-
-# Make sure that Cake has been installed.
-if (!(Test-Path $CAKE_EXE)) {
- Throw "Could not find Cake.exe at $CAKE_EXE"
-}
-
-# Start Cake
-Write-Host "Running build script..."
-Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs"
-exit $LASTEXITCODE
+dotnet cake recipe.cake @args
+if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
diff --git a/build.sh b/build.sh
index 7fc4599..9863e90 100755
--- a/build.sh
+++ b/build.sh
@@ -1,117 +1,12 @@
#!/usr/bin/env bash
+set -euox pipefail
-##########################################################################
-# This is the Cake bootstrapper script for Linux and OS X.
-# This file was downloaded from https://github.com/cake-build/resources
-# Feel free to change this file to fit your needs.
-##########################################################################
+cd "$(dirname "${BASH_SOURCE[0]}")"
-# Define directories.
-SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
-TOOLS_DIR=$SCRIPT_DIR/tools
-ADDINS_DIR=$TOOLS_DIR/Addins
-MODULES_DIR=$TOOLS_DIR/Modules
-NUGET_EXE=$TOOLS_DIR/nuget.exe
-CAKE_EXE=$TOOLS_DIR/Cake/Cake.exe
-PACKAGES_CONFIG=$TOOLS_DIR/packages.config
-PACKAGES_CONFIG_MD5=$TOOLS_DIR/packages.config.md5sum
-ADDINS_PACKAGES_CONFIG=$ADDINS_DIR/packages.config
-MODULES_PACKAGES_CONFIG=$MODULES_DIR/packages.config
+export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
+export DOTNET_CLI_TELEMETRY_OPTOUT=1
+export DOTNET_NOLOGO=1
-# Define md5sum or md5 depending on Linux/OSX
-MD5_EXE=
-if [[ "$(uname -s)" == "Darwin" ]]; then
- MD5_EXE="md5 -r"
-else
- MD5_EXE="md5sum"
-fi
+dotnet tool restore
-# Define default arguments.
-SCRIPT="recipe.cake"
-CAKE_ARGUMENTS=()
-
-# Parse arguments.
-for i in "$@"; do
- case $1 in
- -s|--script) SCRIPT="$2"; shift ;;
- --) shift; CAKE_ARGUMENTS+=("$@"); break ;;
- *) CAKE_ARGUMENTS+=("$1") ;;
- esac
- shift
-done
-
-# Make sure the tools folder exist.
-if [ ! -d "$TOOLS_DIR" ]; then
- mkdir "$TOOLS_DIR"
-fi
-
-# Make sure that packages.config exist.
-if [ ! -f "$TOOLS_DIR/packages.config" ]; then
- echo "Downloading packages.config..."
- curl -Lsfo "$TOOLS_DIR/packages.config" https://cakebuild.net/download/bootstrapper/packages
- if [ $? -ne 0 ]; then
- echo "An error occurred while downloading packages.config."
- exit 1
- fi
-fi
-
-# Download NuGet if it does not exist.
-if [ ! -f "$NUGET_EXE" ]; then
- echo "Downloading NuGet..."
- curl -Lsfo "$NUGET_EXE" https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
- if [ $? -ne 0 ]; then
- echo "An error occurred while downloading nuget.exe."
- exit 1
- fi
-fi
-
-# Restore tools from NuGet.
-pushd "$TOOLS_DIR" >/dev/null
-if [ ! -f "$PACKAGES_CONFIG_MD5" ] || [ "$( cat "$PACKAGES_CONFIG_MD5" | sed 's/\r$//' )" != "$( $MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' )" ]; then
- find . -type d ! -name . ! -name 'Cake.Bakery' | xargs rm -rf
-fi
-
-mono "$NUGET_EXE" install -ExcludeVersion
-if [ $? -ne 0 ]; then
- echo "Could not restore NuGet tools."
- exit 1
-fi
-
-$MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' >| "$PACKAGES_CONFIG_MD5"
-
-popd >/dev/null
-
-# Restore addins from NuGet.
-if [ -f "$ADDINS_PACKAGES_CONFIG" ]; then
- pushd "$ADDINS_DIR" >/dev/null
-
- mono "$NUGET_EXE" install -ExcludeVersion
- if [ $? -ne 0 ]; then
- echo "Could not restore NuGet addins."
- exit 1
- fi
-
- popd >/dev/null
-fi
-
-# Restore modules from NuGet.
-if [ -f "$MODULES_PACKAGES_CONFIG" ]; then
- pushd "$MODULES_DIR" >/dev/null
-
- mono "$NUGET_EXE" install -ExcludeVersion
- if [ $? -ne 0 ]; then
- echo "Could not restore NuGet modules."
- exit 1
- fi
-
- popd >/dev/null
-fi
-
-# Make sure that Cake has been installed.
-if [ ! -f "$CAKE_EXE" ]; then
- echo "Could not find Cake.exe at '$CAKE_EXE'."
- exit 1
-fi
-
-# Start Cake
-exec mono "$CAKE_EXE" $SCRIPT "${CAKE_ARGUMENTS[@]}"
+dotnet cake recipe.cake "$@"
diff --git a/docs/input/docs/usage/examples.md b/docs/input/docs/usage/examples.md
index 3f2d441..41a1c98 100644
--- a/docs/input/docs/usage/examples.md
+++ b/docs/input/docs/usage/examples.md
@@ -143,4 +143,17 @@ Task("Destroy")
};
TerraformDestroy(settings);
});
+```
+
+
+## TerraformValidate
+
+```csharp
+#addin Cake.Terraform
+
+Task("Validate")
+ .Does(() =>
+{
+ TerraformValidate();
+});
```
\ No newline at end of file
diff --git a/nuspec/nuget/Cake.Terraform.nuspec b/nuspec/nuget/Cake.Terraform.nuspec
deleted file mode 100644
index 005d096..0000000
--- a/nuspec/nuget/Cake.Terraform.nuspec
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
- Cake.Terraform
- 0.0.0
- Erik van Brakel
- Erik van Brakel
- Cake Terraform Addin.
- Cake AddIn that extends Cake with ability to execute terraform commands.
- https://github.com/cake-contrib/Cake.Terraform/
- https://cdn.jsdelivr.net/gh/cake-contrib/graphics/png/cake-contrib-medium.png
- false
- MIT
-
- Copyright (c) 2017 - Present
- Cake, Script, Build, Terraform, Hashicorp
-
-
-
-
-
-
-
-
diff --git a/recipe.cake b/recipe.cake
index 7314e1d..5c383e2 100644
--- a/recipe.cake
+++ b/recipe.cake
@@ -1,4 +1,4 @@
-#load nuget:?package=Cake.Recipe&version=1.0.0
+#load nuget:?package=Cake.Recipe&version=3.1.1
Environment.SetVariableNames();
@@ -8,21 +8,21 @@ BuildParameters.SetParameters(context: Context,
title: "Cake.Terraform",
repositoryOwner: "cake-contrib",
repositoryName: "Cake.Terraform",
- appVeyorAccountName: "cakecontrib",
webHost: "cake-contrib.github.io",
webLinkRoot: "Cake.Terraform",
webBaseEditUrl: "https://github.com/cake-contrib/Cake.Terraform/tree/develop/docs/input",
- shouldRunGitVersion: true);
+ shouldRunDotNetCorePack: true,
+ shouldRunCodecov: false
+ //preferredBuildProviderType: BuildProviderType.GitHubActions,
+ //preferredBuildAgentOperatingSystem: PlatformFamily.Linux
+ );
BuildParameters.PrintParameters(Context);
-ToolSettings.SetToolSettings(context: Context,
- dupFinderExcludePattern: new string[] {
- BuildParameters.RootDirectoryPath + "/src/Cake.Terraform.Tests/**/*.cs"
- },
- dupFinderThrowExceptionOnFindingDuplicates: false,
- testCoverageFilter: "+[*]* -[xunit.*]* -[Cake.Core]* -[Cake.Testing]* -[*.Tests]* ",
- testCoverageExcludeByAttribute: "*.ExcludeFromCodeCoverage*",
- testCoverageExcludeByFile: "*/*Designer.cs;*/*.g.cs;*/*.g.i.cs");
+ToolSettings.SetToolPreprocessorDirectives(
+ gitReleaseManagerGlobalTool: "#tool dotnet:?package=GitReleaseManager.Tool&version=0.17.0");
+
+ToolSettings.SetToolSettings(context: Context);
Build.RunDotNetCore();
+
diff --git a/src/Cake.Terraform.Tests/Cake.Terraform.Tests.csproj b/src/Cake.Terraform.Tests/Cake.Terraform.Tests.csproj
index c670ae2..7274d57 100644
--- a/src/Cake.Terraform.Tests/Cake.Terraform.Tests.csproj
+++ b/src/Cake.Terraform.Tests/Cake.Terraform.Tests.csproj
@@ -1,15 +1,30 @@
- net461
+
+ netcoreapp3.1
+ net461;net5.0
-
-
-
-
-
+
+
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
+
+
+
+
+
diff --git a/src/Cake.Terraform.Tests/TerraformApplyTests.cs b/src/Cake.Terraform.Tests/TerraformApplyTests.cs
index 3c24f7f..2107459 100644
--- a/src/Cake.Terraform.Tests/TerraformApplyTests.cs
+++ b/src/Cake.Terraform.Tests/TerraformApplyTests.cs
@@ -142,6 +142,22 @@ public void Should_Append_Auto_Approve_When_AutoApprove_Is_True()
Assert.Contains("-auto-approve", result.Args);
}
+ [Fact]
+ public void Should_Append_Destroy_When_AutoApprove_Is_True()
+ {
+ var fixture = new Fixture
+ {
+ Settings = new TerraformApplySettings
+ {
+ Destroy = true
+ }
+ };
+
+ var result = fixture.Run();
+
+ Assert.Contains("-destroy", result.Args);
+ }
+
[Fact]
public void Should_set_plan_path()
{
@@ -157,7 +173,7 @@ public void Should_set_plan_path()
Assert.Equal("apply \"plan.out\"", result.Args);
}
- [Fact]
+ [Fact]
public void Should_set_parallelism()
{
var fixture = new Fixture
@@ -171,6 +187,32 @@ public void Should_set_parallelism()
Assert.Contains("-parallelism=42", result.Args);
}
+
+ [Fact]
+ public void Should_omit_input_flag_by_default()
+ {
+ var fixture = new Fixture();
+
+ var result = fixture.Run();
+
+ Assert.DoesNotContain("-input", result.Args);
+ }
+
+ [Fact]
+ public void Should_include_input_flag_when_setting_is_false()
+ {
+ var fixture = new Fixture
+ {
+ Settings = new TerraformApplySettings
+ {
+ Input = false
+ }
+ };
+
+ var result = fixture.Run();
+
+ Assert.Contains("-input", result.Args);
+ }
}
}
}
diff --git a/src/Cake.Terraform.Tests/TerraformEnvListTests.cs b/src/Cake.Terraform.Tests/TerraformEnvListTests.cs
index abf19c7..972f910 100644
--- a/src/Cake.Terraform.Tests/TerraformEnvListTests.cs
+++ b/src/Cake.Terraform.Tests/TerraformEnvListTests.cs
@@ -1,7 +1,6 @@
using Cake.Core;
using Cake.Terraform.EnvList;
using Cake.Testing;
-using Cake.Testing.Fixtures;
using Xunit;
namespace Cake.Terraform.Tests
diff --git a/src/Cake.Terraform.Tests/TerraformInitTests.cs b/src/Cake.Terraform.Tests/TerraformInitTests.cs
index 0af54b4..ce48d6c 100644
--- a/src/Cake.Terraform.Tests/TerraformInitTests.cs
+++ b/src/Cake.Terraform.Tests/TerraformInitTests.cs
@@ -163,6 +163,58 @@ public void Should_include_force_copy_flag_when_setting_is_true()
Assert.Contains("-force-copy", result.Args);
}
+
+ [Fact]
+ public void Should_omit_input_flag_by_default()
+ {
+ var fixture = new Fixture();
+
+ var result = fixture.Run();
+
+ Assert.DoesNotContain("-input", result.Args);
+ }
+
+ [Fact]
+ public void Should_include_input_flag_when_setting_is_false()
+ {
+ var fixture = new Fixture
+ {
+ Settings = new TerraformInitSettings
+ {
+ Input = false
+ }
+ };
+
+ var result = fixture.Run();
+
+ Assert.Contains("-input", result.Args);
+ }
+
+ [Fact]
+ public void Should_omit_backend_flag_by_default()
+ {
+ var fixture = new Fixture();
+
+ var result = fixture.Run();
+
+ Assert.DoesNotContain("-backend", result.Args);
+ }
+
+ [Fact]
+ public void Should_include_backend_flag_when_setting_is_false()
+ {
+ var fixture = new Fixture
+ {
+ Settings = new TerraformInitSettings
+ {
+ Backend = false
+ }
+ };
+
+ var result = fixture.Run();
+
+ Assert.Contains("-backend", result.Args);
+ }
}
}
}
\ No newline at end of file
diff --git a/src/Cake.Terraform.Tests/TerraformOutputTests.cs b/src/Cake.Terraform.Tests/TerraformOutputTests.cs
new file mode 100644
index 0000000..f7bf081
--- /dev/null
+++ b/src/Cake.Terraform.Tests/TerraformOutputTests.cs
@@ -0,0 +1,205 @@
+using System;
+using System.Collections.Generic;
+using Cake.Core;
+using Cake.Terraform.Output;
+using Cake.Testing;
+using Xunit;
+
+namespace Cake.Terraform.Tests
+{
+ public class TerraformOutputTests
+ {
+ class Fixture : TerraformFixture
+ {
+ public Fixture(PlatformFamily platformFamily = PlatformFamily.Windows) : base(platformFamily) { }
+
+ public List ToolOutput { get; set; } = new List { "foo = 123", "bar = abc" };
+ public string Outputs { get; private set; } = null;
+
+ protected override void RunTool()
+ {
+ ProcessRunner.Process.SetStandardOutput(ToolOutput);
+
+ var tool = new TerraformOutputRunner(FileSystem, Environment, ProcessRunner, Tools);
+
+ Outputs = tool.Run(Settings);
+ }
+ }
+
+ public class TheExecutable
+ {
+ [Fact]
+ public void Should_throw_if_terraform_runner_was_not_found()
+ {
+ var fixture = new Fixture();
+ fixture.GivenDefaultToolDoNotExist();
+
+ var result = Record.Exception(() => fixture.Run());
+
+ Assert.IsType(result);
+ Assert.Equal("Terraform: Could not locate executable.", result.Message);
+ }
+
+ [Theory]
+ [InlineData("/bin/tools/terraform/terraform.exe", "/bin/tools/terraform/terraform.exe")]
+ [InlineData("/bin/tools/terraform/terraform", "/bin/tools/terraform/terraform")]
+ public void Should_use_terraform_from_tool_path_if_provided(string toolPath, string expected)
+ {
+ var fixture = new Fixture() {Settings = {ToolPath = toolPath}};
+ fixture.GivenSettingsToolPathExist();
+
+ var result = fixture.Run();
+
+ Assert.Equal(expected, result.Path.FullPath);
+ }
+
+ [Fact]
+ public void Should_find_terraform_if_tool_path_not_provided()
+ {
+ var fixture = new Fixture();
+
+ var result = fixture.Run();
+
+ Assert.Equal("/Working/tools/terraform.exe", result.Path.FullPath);
+ }
+
+ [Fact]
+ public void Should_throw_if_process_has_a_non_zero_exit_code()
+ {
+ var fixture = new Fixture();
+ fixture.GivenProcessExitsWithCode(1);
+
+ var result = Record.Exception(() => fixture.Run());
+
+ Assert.IsType(result);
+ Assert.Equal("Terraform: Process returned an error (exit code 1).", result.Message);
+ }
+
+ [Fact]
+ public void Should_find_linux_executable()
+ {
+ var fixture = new Fixture(PlatformFamily.Linux);
+ fixture.Environment.Platform.Family = PlatformFamily.Linux;
+
+ var result = fixture.Run();
+
+ Assert.Equal("/Working/tools/terraform", result.Path.FullPath);
+ }
+
+ [Fact]
+ public void Should_call_only_command_if_no_settings_specified()
+ {
+ var fixture = new Fixture();
+
+ var result = fixture.Run();
+
+ Assert.Equal("output -no-color", result.Args);
+ }
+
+ [Fact]
+ public void Should_request_json_if_specified()
+ {
+ var fixture = new Fixture { Settings = new TerraformOutputSettings { Json = true } };
+
+ var result = fixture.Run();
+
+ Assert.Equal("output -no-color -json", result.Args);
+ }
+
+ [Fact]
+ public void Should_request_raw_if_specified()
+ {
+ var fixture = new Fixture { Settings = new TerraformOutputSettings { Raw = true } };
+
+ var result = fixture.Run();
+
+ Assert.Equal("output -no-color -raw", result.Args);
+ }
+
+ [Fact]
+ public void Should_request_raw_over_json_if_both_are_specified()
+ {
+ var fixture = new Fixture { Settings = new TerraformOutputSettings { Raw = true, Json = true} };
+
+ var result = fixture.Run();
+
+ Assert.Equal("output -no-color -raw", result.Args);
+ }
+
+ [Fact]
+ public void Should_request_specific_state_path_if_specified()
+ {
+ var fixture = new Fixture { Settings = new TerraformOutputSettings { StatePath = "some_path"} };
+
+ var result = fixture.Run();
+
+ Assert.Equal("output -no-color -state=some_path", result.Args);
+ }
+
+ [Fact]
+ public void Should_request_particular_output_if_specified()
+ {
+ var fixture = new Fixture { Settings = new TerraformOutputSettings { OutputName = "some_output"} };
+
+ var result = fixture.Run();
+
+ Assert.Equal("output -no-color some_output", result.Args);
+ }
+
+ [Fact]
+ public void Should_combine_output_lines_into_string()
+ {
+ var fixture = new Fixture();
+
+ fixture.Run();
+
+ Assert.Equal("foo = 123\nbar = abc", fixture.Outputs);
+ }
+
+ [Fact]
+ public void Should_raise_exception_if_output_not_found()
+ {
+ var fixture = new Fixture
+ {
+ ToolOutput = new List
+ {
+ "The output variable requested could not be found in the state",
+ "file. If you recently added this to your configuration, be",
+ "sure to run `terraform apply`, since the state won't be updated",
+ "with new output variables until that command is run."
+ }
+ };
+
+ var exception = Assert.Throws(() => fixture.Run());
+ Assert.Equal(
+ "The output variable requested could not be found in the state\nfile. If you recently added this to your configuration, be\nsure to run `terraform apply`, since the state won't be updated\nwith new output variables until that command is run.",
+ exception.Message);
+ }
+
+ [Fact]
+ public void Should_not_raise_exception_if_output_not_found_and_validation_disabled()
+ {
+ var fixture = new Fixture
+ {
+ ToolOutput = new List
+ {
+ "The output variable requested could not be found in the state",
+ "file. If you recently added this to your configuration, be",
+ "sure to run `terraform apply`, since the state won't be updated",
+ "with new output variables until that command is run."
+ },
+ Settings = new TerraformOutputSettings
+ {
+ ValidateToolOutput = false
+ }
+ };
+
+ fixture.Run();
+
+ Assert.Equal(
+ "The output variable requested could not be found in the state\nfile. If you recently added this to your configuration, be\nsure to run `terraform apply`, since the state won't be updated\nwith new output variables until that command is run.",
+ fixture.Outputs);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Cake.Terraform.Tests/TerraformPlanTests.cs b/src/Cake.Terraform.Tests/TerraformPlanTests.cs
index f5c079c..1e95eee 100644
--- a/src/Cake.Terraform.Tests/TerraformPlanTests.cs
+++ b/src/Cake.Terraform.Tests/TerraformPlanTests.cs
@@ -205,6 +205,32 @@ public void Should_not_set_destroy_flag_if_set_to_false()
Assert.DoesNotContain("-destroy", result.Args);
}
+
+ [Fact]
+ public void Should_omit_input_flag_by_default()
+ {
+ var fixture = new Fixture();
+
+ var result = fixture.Run();
+
+ Assert.DoesNotContain("-input", result.Args);
+ }
+
+ [Fact]
+ public void Should_include_input_flag_when_setting_is_false()
+ {
+ var fixture = new Fixture
+ {
+ Settings = new TerraformPlanSettings
+ {
+ Input = false
+ }
+ };
+
+ var result = fixture.Run();
+
+ Assert.Contains("-input", result.Args);
+ }
}
}
}
\ No newline at end of file
diff --git a/src/Cake.Terraform.Tests/TerraformValidateTests.cs b/src/Cake.Terraform.Tests/TerraformValidateTests.cs
new file mode 100644
index 0000000..745458d
--- /dev/null
+++ b/src/Cake.Terraform.Tests/TerraformValidateTests.cs
@@ -0,0 +1,97 @@
+using System.Collections.Generic;
+using Cake.Core;
+using Cake.Terraform.Validate;
+using Cake.Testing;
+using Xunit;
+
+namespace Cake.Terraform.Tests
+{
+ public class TerraformValidateTests
+ {
+ class Fixture : TerraformFixture
+ {
+ public Fixture(PlatformFamily platformFamily = PlatformFamily.Windows) : base(platformFamily) { }
+
+ protected override void RunTool()
+ {
+ ProcessRunner.Process.SetStandardOutput(new List { "default" });
+
+ var tool = new TerraformValidateRunner(FileSystem, Environment, ProcessRunner, Tools);
+
+ tool.Run(Settings);
+ }
+ }
+
+ public class TheExecutable
+ {
+ [Fact]
+ public void Should_throw_if_terraform_runner_was_not_found()
+ {
+ var fixture = new Fixture();
+ fixture.GivenDefaultToolDoNotExist();
+
+ var result = Record.Exception(() => fixture.Run());
+
+ Assert.IsType(result);
+ Assert.Equal("Terraform: Could not locate executable.", result.Message);
+ }
+
+ [Theory]
+ [InlineData("/bin/tools/terraform/terraform.exe", "/bin/tools/terraform/terraform.exe")]
+ [InlineData("/bin/tools/terraform/terraform", "/bin/tools/terraform/terraform")]
+ public void Should_use_terraform_from_tool_path_if_provided(string toolPath, string expected)
+ {
+ var fixture = new Fixture() { Settings = { ToolPath = toolPath } };
+ fixture.GivenSettingsToolPathExist();
+
+ var result = fixture.Run();
+
+ Assert.Equal(expected, result.Path.FullPath);
+ }
+
+ [Fact]
+ public void Should_find_terraform_if_tool_path_not_provided()
+ {
+ var fixture = new Fixture();
+
+ var result = fixture.Run();
+
+ Assert.Equal("/Working/tools/terraform.exe", result.Path.FullPath);
+ }
+
+ [Fact]
+ public void Should_throw_if_process_has_a_non_zero_exit_code()
+ {
+ var fixture = new Fixture();
+ fixture.GivenProcessExitsWithCode(1);
+
+ var result = Record.Exception(() => fixture.Run());
+
+ Assert.IsType(result);
+ Assert.Equal("Terraform: Process returned an error (exit code 1).", result.Message);
+ }
+
+ [Fact]
+ public void Should_find_linux_executable()
+ {
+ var fixture = new Fixture(PlatformFamily.Linux);
+ fixture.Environment.Platform.Family = PlatformFamily.Linux;
+
+
+ var result = fixture.Run();
+
+ Assert.Equal("/Working/tools/terraform", result.Path.FullPath);
+ }
+
+ [Fact]
+ public void Should_set_workspace_and_list_parameter()
+ {
+ var fixture = new Fixture();
+
+ var result = fixture.Run();
+
+ Assert.Contains("validate", result.Args);
+ }
+ }
+ }
+}
diff --git a/src/Cake.Terraform.sln b/src/Cake.Terraform.sln
index f38f01f..dc1bbf6 100644
--- a/src/Cake.Terraform.sln
+++ b/src/Cake.Terraform.sln
@@ -1,28 +1,28 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 15
-VisualStudioVersion = 15.0.26228.12
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cake.Terraform", "Cake.Terraform\Cake.Terraform.csproj", "{C6E9A60F-9055-4E54-9E29-7F277875ABC1}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cake.Terraform.Tests", "Cake.Terraform.Tests\Cake.Terraform.Tests.csproj", "{AB9EDCDE-48B6-4B6E-B0B6-28CF549A6591}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Release|Any CPU = Release|Any CPU
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {C6E9A60F-9055-4E54-9E29-7F277875ABC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {C6E9A60F-9055-4E54-9E29-7F277875ABC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {C6E9A60F-9055-4E54-9E29-7F277875ABC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {C6E9A60F-9055-4E54-9E29-7F277875ABC1}.Release|Any CPU.Build.0 = Release|Any CPU
- {AB9EDCDE-48B6-4B6E-B0B6-28CF549A6591}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {AB9EDCDE-48B6-4B6E-B0B6-28CF549A6591}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {AB9EDCDE-48B6-4B6E-B0B6-28CF549A6591}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {AB9EDCDE-48B6-4B6E-B0B6-28CF549A6591}.Release|Any CPU.Build.0 = Release|Any CPU
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
-EndGlobal
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+VisualStudioVersion = 15.0.26228.12
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cake.Terraform", "Cake.Terraform\Cake.Terraform.csproj", "{C6E9A60F-9055-4E54-9E29-7F277875ABC1}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cake.Terraform.Tests", "Cake.Terraform.Tests\Cake.Terraform.Tests.csproj", "{AB9EDCDE-48B6-4B6E-B0B6-28CF549A6591}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {C6E9A60F-9055-4E54-9E29-7F277875ABC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C6E9A60F-9055-4E54-9E29-7F277875ABC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C6E9A60F-9055-4E54-9E29-7F277875ABC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C6E9A60F-9055-4E54-9E29-7F277875ABC1}.Release|Any CPU.Build.0 = Release|Any CPU
+ {AB9EDCDE-48B6-4B6E-B0B6-28CF549A6591}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {AB9EDCDE-48B6-4B6E-B0B6-28CF549A6591}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {AB9EDCDE-48B6-4B6E-B0B6-28CF549A6591}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {AB9EDCDE-48B6-4B6E-B0B6-28CF549A6591}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/src/Cake.Terraform/Apply/TerraformApplyRunner.cs b/src/Cake.Terraform/Apply/TerraformApplyRunner.cs
index 9d9319a..d90d077 100644
--- a/src/Cake.Terraform/Apply/TerraformApplyRunner.cs
+++ b/src/Cake.Terraform/Apply/TerraformApplyRunner.cs
@@ -17,6 +17,11 @@ public void Run(TerraformApplySettings settings)
var builder = new ProcessArgumentBuilder()
.Append("apply");
+ if (settings.Destroy)
+ {
+ builder.Append("-destroy");
+ }
+
// Order of AutoApprove and Plan are important.
if (settings.AutoApprove)
{
@@ -44,6 +49,11 @@ public void Run(TerraformApplySettings settings)
builder.AppendSwitchQuoted("-var", $"{inputVariable.Key}={inputVariable.Value}");
}
+ if (!settings.Input)
+ {
+ builder.AppendSwitch("-input", "=", settings.Input.ToString());
+ }
+
Run(settings, builder);
}
}
diff --git a/src/Cake.Terraform/Apply/TerraformApplySettings.cs b/src/Cake.Terraform/Apply/TerraformApplySettings.cs
index 3cf537f..0e29f9f 100644
--- a/src/Cake.Terraform/Apply/TerraformApplySettings.cs
+++ b/src/Cake.Terraform/Apply/TerraformApplySettings.cs
@@ -5,6 +5,11 @@ namespace Cake.Terraform.Apply
{
public class TerraformApplySettings : TerraformSettings
{
+ public TerraformApplySettings()
+ {
+ this.Input = true;
+ }
+
public int Parallelism { get; set; }
public FilePath Plan { get; set; }
@@ -25,5 +30,17 @@ public class TerraformApplySettings : TerraformSettings
/// https://www.terraform.io/docs/commands/apply.html#auto-approve
///
public bool AutoApprove { get; set; }
+
+ ///
+ /// Ask for input for variables if not directly set.
+ /// https://www.terraform.io/docs/commands/apply.html#input-true
+ ///
+ public bool Input { get; set; }
+
+ ///
+ /// Does destory
+ /// https://www.terraform.io/docs/commands/destroy.html
+ ///
+ public bool Destroy { get; set; }
}
}
\ No newline at end of file
diff --git a/src/Cake.Terraform/Cake.Terraform.csproj b/src/Cake.Terraform/Cake.Terraform.csproj
index 749cf9a..c063ba5 100644
--- a/src/Cake.Terraform/Cake.Terraform.csproj
+++ b/src/Cake.Terraform/Cake.Terraform.csproj
@@ -1,12 +1,44 @@
- net461;netstandard2.0
+ net461;netstandard2.0;net5.0
+
+
+
+
+
+ Erik van Brakel
+ opyright (c) 2017 - Present — Erik van Brakel
+ Cake AddIn that extends Cake with ability to execute terraform commands.
+ MIT
+ https://github.com/cake-contrib/Cake.Terraform
+ cake;build;cake-build;script;addin;cake-addin;terraform;hashicorp
+ $(PackageProjectUrl).git
+ $(PackageProjectUrl)/releases
+ 0.0.0
+ README.md
+
+
+
+
+ 0.1.3
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
- 0.33.0
+ 1.0.0
+
+
+ 1.5.1
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
diff --git a/src/Cake.Terraform/Init/TerraformInitRunner.cs b/src/Cake.Terraform/Init/TerraformInitRunner.cs
index 1d653c5..0dc8d32 100644
--- a/src/Cake.Terraform/Init/TerraformInitRunner.cs
+++ b/src/Cake.Terraform/Init/TerraformInitRunner.cs
@@ -32,6 +32,16 @@ public void Run(TerraformInitSettings settings)
builder.Append("-reconfigure");
}
+ if (!settings.Input)
+ {
+ builder.AppendSwitch("-input", "=", settings.Input.ToString());
+ }
+
+ if (!settings.Backend)
+ {
+ builder.AppendSwitch("-backend", "=", settings.Backend.ToString());
+ }
+
Run(settings, builder);
}
}
diff --git a/src/Cake.Terraform/Init/TerraformInitSettings.cs b/src/Cake.Terraform/Init/TerraformInitSettings.cs
index bb4b3e8..9659be4 100644
--- a/src/Cake.Terraform/Init/TerraformInitSettings.cs
+++ b/src/Cake.Terraform/Init/TerraformInitSettings.cs
@@ -4,6 +4,12 @@ namespace Cake.Terraform.Init
{
public class TerraformInitSettings : TerraformSettings
{
+ public TerraformInitSettings()
+ {
+ this.Input = true;
+ this.Backend = true;
+ }
+
///
/// A set of backend config key-value overrides to be passed to `terraform init`
/// https://www.terraform.io/docs/commands/init.html#backend-config-value
@@ -22,5 +28,17 @@ public class TerraformInitSettings : TerraformSettings
/// https://www.terraform.io/docs/commands/init.html#force-copy
///
public bool ForceCopy { get; set; }
+
+ ///
+ /// Ask for input if necessary. If false, will error if input was required.
+ /// https://www.terraform.io/docs/commands/init.html#input-true
+ ///
+ public bool Input { get; set; }
+
+ ///
+ /// Configure the backend for this configuration.
+ /// https://www.terraform.io/docs/commands/init.html#backend-initialization
+ ///
+ public bool Backend { get; set; }
}
}
diff --git a/src/Cake.Terraform/Output/TerraformOutputRunner.cs b/src/Cake.Terraform/Output/TerraformOutputRunner.cs
new file mode 100644
index 0000000..2f0d7f2
--- /dev/null
+++ b/src/Cake.Terraform/Output/TerraformOutputRunner.cs
@@ -0,0 +1,93 @@
+using System;
+using System.Linq;
+using System.Text;
+using Cake.Core;
+using Cake.Core.IO;
+using Cake.Core.Tooling;
+
+namespace Cake.Terraform.Output
+{
+ public class TerraformOutputRunner : TerraformRunner
+ {
+ public TerraformOutputRunner(IFileSystem fileSystem, ICakeEnvironment environment, IProcessRunner processRunner, IToolLocator tools)
+ : base(fileSystem, environment, processRunner, tools)
+ {
+ }
+
+ private static string RemoveWhitespace(string x)
+ {
+ return x
+ .Replace("\n", "")
+ .Replace("\r", "")
+ .Replace(" ", "");
+ }
+
+ private void ConfirmSuccess(string output)
+ {
+ string outputNotFoundErrorString = RemoveWhitespace("The output variable requested could not be found in the state file. If you recently added this to your configuration, be sure to run `terraform apply`, since the state won't be updated with new output variables until that command is run.");
+
+ if (RemoveWhitespace(output) == outputNotFoundErrorString)
+ {
+ throw new ArgumentException(output);
+ }
+ }
+
+ public string Run(TerraformOutputSettings settings)
+ {
+ var arguments = new ProcessArgumentBuilder()
+ .Append("output")
+ .Append("-no-color");
+
+ if (settings.StatePath != null)
+ {
+ arguments.Append($"-state={settings.StatePath}");
+ }
+
+ if (settings.Raw)
+ {
+ arguments.Append("-raw");
+ }
+ else if (settings.Json)
+ {
+ arguments.Append("-json");
+ }
+
+ if (settings.OutputName != null)
+ {
+ arguments.Append(settings.OutputName);
+ }
+
+ var processSettings = new ProcessSettings
+ {
+ RedirectStandardOutput = true
+ };
+
+ string output = null;
+ Run(settings, arguments, processSettings, x =>
+ {
+ var outputLines = x.GetStandardOutput().ToList();
+ int lineCount = outputLines.Count();
+
+ var builder = new StringBuilder();
+ for (int i = 0; i < lineCount; i++)
+ {
+ builder.Append(outputLines[i]);
+
+ if (i < lineCount - 1)
+ {
+ builder.Append("\n"); // OS consistent
+ }
+ }
+
+ output = builder.ToString();
+ });
+
+ if (settings.ValidateToolOutput)
+ {
+ ConfirmSuccess(output);
+ }
+
+ return output;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Cake.Terraform/Output/TerraformOutputSettings.cs b/src/Cake.Terraform/Output/TerraformOutputSettings.cs
new file mode 100644
index 0000000..7bc3234
--- /dev/null
+++ b/src/Cake.Terraform/Output/TerraformOutputSettings.cs
@@ -0,0 +1,11 @@
+namespace Cake.Terraform.Output
+{
+ public class TerraformOutputSettings : TerraformSettings
+ {
+ public string OutputName { get; set; }
+ public bool Json { get; set; }
+ public bool Raw { get; set; }
+ public string StatePath { get; set; }
+ public bool ValidateToolOutput { get; set; } = true;
+ }
+}
\ No newline at end of file
diff --git a/src/Cake.Terraform/Plan/TerraformPlanRunner.cs b/src/Cake.Terraform/Plan/TerraformPlanRunner.cs
index c1be060..3bea879 100644
--- a/src/Cake.Terraform/Plan/TerraformPlanRunner.cs
+++ b/src/Cake.Terraform/Plan/TerraformPlanRunner.cs
@@ -43,6 +43,11 @@ public void Run(TerraformPlanSettings settings)
}
}
+ if (!settings.Input)
+ {
+ builder.AppendSwitch("-input", "=", settings.Input.ToString());
+ }
+
Run(settings, builder);
}
diff --git a/src/Cake.Terraform/Plan/TerraformPlanSettings.cs b/src/Cake.Terraform/Plan/TerraformPlanSettings.cs
index bf43fb8..096e9ab 100644
--- a/src/Cake.Terraform/Plan/TerraformPlanSettings.cs
+++ b/src/Cake.Terraform/Plan/TerraformPlanSettings.cs
@@ -5,6 +5,11 @@ namespace Cake.Terraform.Plan
{
public class TerraformPlanSettings : TerraformSettings
{
+ public TerraformPlanSettings()
+ {
+ this.Input = true;
+ }
+
public FilePath OutFile { get; set; }
public int Parallelism { get; set; }
@@ -24,5 +29,11 @@ public class TerraformPlanSettings : TerraformSettings
/// If set to true, generates a plan to destroy all the known resources
///
public bool Destroy { get; set; }
+
+ ///
+ /// Ask for input for variables if not directly set.
+ /// https://www.terraform.io/docs/commands/plan.html#input-true
+ ///
+ public bool Input { get; set; }
}
}
\ No newline at end of file
diff --git a/src/Cake.Terraform/TerraformAliases.cs b/src/Cake.Terraform/TerraformAliases.cs
index de4fcbc..43cab81 100644
--- a/src/Cake.Terraform/TerraformAliases.cs
+++ b/src/Cake.Terraform/TerraformAliases.cs
@@ -8,9 +8,11 @@
using Cake.Terraform.EnvNew;
using Cake.Terraform.EnvSelect;
using Cake.Terraform.Init;
+using Cake.Terraform.Output;
using Cake.Terraform.Plan;
using Cake.Terraform.Refresh;
using Cake.Terraform.Show;
+using Cake.Terraform.Validate;
namespace Cake.Terraform
{
@@ -147,5 +149,25 @@ public static void TerraformRefresh(this ICakeContext context, TerraformRefreshS
var runner = new TerraformRefreshRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
runner.Run(settings);
}
+
+ [CakeMethodAlias]
+ public static void TerraformValidate(this ICakeContext context)
+ {
+ TerraformValidate(context, new TerraformValidateSettings());
+ }
+
+ [CakeMethodAlias]
+ public static void TerraformValidate(this ICakeContext context, TerraformValidateSettings settings)
+ {
+ var runner = new TerraformValidateRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
+ runner.Run(settings);
+ }
+
+ [CakeMethodAlias]
+ public static string TerraformOutput(this ICakeContext context, TerraformOutputSettings settings)
+ {
+ var runner = new TerraformOutputRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
+ return runner.Run(settings);
+ }
}
}
diff --git a/src/Cake.Terraform/Validate/TerraformValidateRunner.cs b/src/Cake.Terraform/Validate/TerraformValidateRunner.cs
new file mode 100644
index 0000000..5774771
--- /dev/null
+++ b/src/Cake.Terraform/Validate/TerraformValidateRunner.cs
@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Cake.Core;
+using Cake.Core.IO;
+using Cake.Core.Tooling;
+using Cake.Terraform.Init;
+
+namespace Cake.Terraform.Validate
+{
+ public class TerraformValidateRunner : TerraformRunner
+ {
+ public TerraformValidateRunner(IFileSystem fileSystem, ICakeEnvironment environment, IProcessRunner processRunner, IToolLocator tools)
+ : base(fileSystem, environment, processRunner, tools)
+ {
+ }
+
+ public void Run(TerraformValidateSettings settings)
+ {
+ var builder = new ProcessArgumentBuilder().Append("validate");
+
+
+ Run(settings, builder);
+ }
+ }
+
+ public class TerraformValidateSettings : TerraformSettings
+ {
+ }
+}
diff --git a/src/Directory.Build.targets b/src/Directory.Build.targets
new file mode 100644
index 0000000..cc9cf53
--- /dev/null
+++ b/src/Directory.Build.targets
@@ -0,0 +1,27 @@
+
+
+
+
+
+ $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb
+ true
+ true
+ $([System.IO.Path]::Combine('$(IntermediateOutputPath)','$(TargetFrameworkMoniker).AssemblyAttributes$(DefaultLanguageSourceExtension)'))
+
+
+
+
+
+
+
+
+
+
+ <_LocalTopLevelSourceRoot Include="@(SourceRoot)" Condition="'%(SourceRoot.NestedRoot)' == ''"/>
+
+
+
diff --git a/tools/packages.config b/tools/packages.config
deleted file mode 100644
index f27ab48..0000000
--- a/tools/packages.config
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-