From 8c91d99842d2c8f162c65dffa3daf14ff7f0c6ce Mon Sep 17 00:00:00 2001 From: Antoine Milochau <48644548+amilochau@users.noreply.github.com> Date: Mon, 8 Jan 2024 07:39:19 +0400 Subject: [PATCH 01/17] Run 'terraform plan' on 'build-terraform' --- build/terraform/README.md | 1 + build/terraform/action.yml | 4 ++++ build/terraform/build-terraform.ps1 | 24 ++++++++++++++++++++++++ deploy/terraform/action.yml | 4 ++-- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/build/terraform/README.md b/build/terraform/README.md index 5642122..0d73174 100644 --- a/build/terraform/README.md +++ b/build/terraform/README.md @@ -33,6 +33,7 @@ jobs: | ----- | ----------- | -------- | ------------- | ------- | | `modulesPath` | The path to the Terraform modules to build | *false* | `.tf` | | `modulesPathDepth` | The path to the projects to test - can be a .csproj or a .sln file | *false* | `1` | +| `workspaceName` | The name of the Terraform workspace where to plan changes | *false* | `""` | | `verbosity` | The verbosity of the scripts | *false* | `minimal` | Set to `minimal`, `normal` or `detailed` | ### Outputs diff --git a/build/terraform/action.yml b/build/terraform/action.yml index ac70599..edf7f96 100644 --- a/build/terraform/action.yml +++ b/build/terraform/action.yml @@ -8,6 +8,9 @@ inputs: modulesPathDepth: description: The depth of the path search, to find the Terraform modules to build default: '1' + workspaceName: + description: The name of the Terraform workspace where to plan changes + default: '' verbosity: description: The verbosity of the scripts default: minimal @@ -25,4 +28,5 @@ runs: run: ${{ github.action_path }}/build-terraform.ps1 ` -modulesPath "${{ inputs.modulesPath }}" ` -modulesPathDepth "${{ inputs.modulesPathDepth }}" ` + -workspaceName "${{ inputs.workspaceName }}" ` -verbosity ${{ inputs.verbosity }} diff --git a/build/terraform/build-terraform.ps1 b/build/terraform/build-terraform.ps1 index 936bb38..22b82ee 100644 --- a/build/terraform/build-terraform.ps1 +++ b/build/terraform/build-terraform.ps1 @@ -5,6 +5,8 @@ The path to the Terraform modules to build .PARAMETER modulesPathDepth The depth of the path search, to find the Terraform modules to build + .PARAMETER workspaceName + The name of the Terraform workspace .PARAMETER verbosity The verbosity level #> @@ -16,6 +18,9 @@ Param( [parameter(Mandatory = $true)] [int]$modulesPathDepth, + + [parameter(Mandatory = $true)] + [string]$workspaceName, [parameter(Mandatory = $true)] [ValidateSet('minimal', 'normal', 'detailed')] @@ -61,6 +66,25 @@ $childItems | Foreach-Object -ThrottleLimit 5 -Parallel { Write-Output "::error title=Terraform failed::Terraform validation failed" throw 1 } + + if ($workspaceName) { + Write-Output "Terraform workspace selection..." + terraform workspace select $workspaceName -no-color 2>&1 # @todo Add ' -or-create' back + if (!$?) { + Write-Output "::error title=Terraform failed::Terraform workspace selection failed" + throw 1 + } + + Write-Output "Terraform plan..." + $planResult = terraform plan -var-file="hosts/$workspaceName.tfvars" -input=false -no-color -lock=false 2>&1 + if (!$?) { + Write-Output $planResult + Write-Output "::error title=Terraform failed::Terraform plan failed" + throw 1 + } + + Write-Output $planResult + } } Write-Output '==========' diff --git a/deploy/terraform/action.yml b/deploy/terraform/action.yml index d4d2466..7f2b4f8 100644 --- a/deploy/terraform/action.yml +++ b/deploy/terraform/action.yml @@ -23,7 +23,7 @@ runs: - name: Build Terraform modules with script shell: pwsh run: ${{ github.action_path }}/deploy-terraform.ps1 ` - -modulePath ${{ inputs.modulePath }} - -workspaceName ${{ inputs.workspaceName }} + -modulePath ${{ inputs.modulePath }} ` + -workspaceName ${{ inputs.workspaceName }} ` -verbosity ${{ inputs.verbosity }} working-directory: ${{ inputs.modulePath }} From 60665bd90ab6df584c7ce0bd35362446f7ef5821 Mon Sep 17 00:00:00 2001 From: Antoine Milochau <48644548+amilochau@users.noreply.github.com> Date: Mon, 8 Jan 2024 07:42:18 +0400 Subject: [PATCH 02/17] Fix --- build/terraform/build-terraform.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build/terraform/build-terraform.ps1 b/build/terraform/build-terraform.ps1 index 22b82ee..ef81a01 100644 --- a/build/terraform/build-terraform.ps1 +++ b/build/terraform/build-terraform.ps1 @@ -19,7 +19,7 @@ Param( [parameter(Mandatory = $true)] [int]$modulesPathDepth, - [parameter(Mandatory = $true)] + [parameter(Mandatory = $false)] [string]$workspaceName, [parameter(Mandatory = $true)] @@ -29,6 +29,7 @@ Param( Write-Output "Modules path is: $modulesPath" Write-Output "Modules path depth is: $modulesPathDepth" +Write-Output "Workspace name is: $workspaceName" Write-Output "Verbosity is: $verbosity" Write-Output '==========' From 5f2352b1feb9aff3a848fe01337b59a4c778b449 Mon Sep 17 00:00:00 2001 From: Antoine Milochau <48644548+amilochau@users.noreply.github.com> Date: Mon, 8 Jan 2024 07:50:27 +0400 Subject: [PATCH 03/17] Fix --- build/terraform/build-terraform.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/terraform/build-terraform.ps1 b/build/terraform/build-terraform.ps1 index ef81a01..e521b2b 100644 --- a/build/terraform/build-terraform.ps1 +++ b/build/terraform/build-terraform.ps1 @@ -68,7 +68,7 @@ $childItems | Foreach-Object -ThrottleLimit 5 -Parallel { throw 1 } - if ($workspaceName) { + if (!!$workspaceName) { Write-Output "Terraform workspace selection..." terraform workspace select $workspaceName -no-color 2>&1 # @todo Add ' -or-create' back if (!$?) { From d7e7a6c84f3e7e01e6251cde7071b23bd674f3a5 Mon Sep 17 00:00:00 2001 From: Antoine Milochau <48644548+amilochau@users.noreply.github.com> Date: Mon, 8 Jan 2024 07:59:38 +0400 Subject: [PATCH 04/17] Test --- build/terraform/build-terraform.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build/terraform/build-terraform.ps1 b/build/terraform/build-terraform.ps1 index e521b2b..9b8bdb3 100644 --- a/build/terraform/build-terraform.ps1 +++ b/build/terraform/build-terraform.ps1 @@ -84,7 +84,10 @@ $childItems | Foreach-Object -ThrottleLimit 5 -Parallel { throw 1 } - Write-Output $planResult + Write-Output $planResult + } else { + Write-Output "No workspace defined." + Write-Output $workspaceName } } From 6af22c282675fbbd7fd8e9e01578887b020bfc89 Mon Sep 17 00:00:00 2001 From: Antoine Milochau <48644548+amilochau@users.noreply.github.com> Date: Mon, 8 Jan 2024 08:04:38 +0400 Subject: [PATCH 05/17] Fix --- build/terraform/build-terraform.ps1 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/build/terraform/build-terraform.ps1 b/build/terraform/build-terraform.ps1 index 9b8bdb3..47158aa 100644 --- a/build/terraform/build-terraform.ps1 +++ b/build/terraform/build-terraform.ps1 @@ -68,7 +68,7 @@ $childItems | Foreach-Object -ThrottleLimit 5 -Parallel { throw 1 } - if (!!$workspaceName) { + if (-not ([string]::IsNullOrWhiteSpace($workspaceName))) { Write-Output "Terraform workspace selection..." terraform workspace select $workspaceName -no-color 2>&1 # @todo Add ' -or-create' back if (!$?) { @@ -86,8 +86,7 @@ $childItems | Foreach-Object -ThrottleLimit 5 -Parallel { Write-Output $planResult } else { - Write-Output "No workspace defined." - Write-Output $workspaceName + Write-Output "No workspace defined: no plan performed." } } From 21c59b989f6b4ae52c782bdc9f749c42b1b15d4a Mon Sep 17 00:00:00 2001 From: Antoine Milochau <48644548+amilochau@users.noreply.github.com> Date: Mon, 8 Jan 2024 08:08:04 +0400 Subject: [PATCH 06/17] Test --- build/terraform/build-terraform.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build/terraform/build-terraform.ps1 b/build/terraform/build-terraform.ps1 index 47158aa..6ea3368 100644 --- a/build/terraform/build-terraform.ps1 +++ b/build/terraform/build-terraform.ps1 @@ -68,6 +68,7 @@ $childItems | Foreach-Object -ThrottleLimit 5 -Parallel { throw 1 } + Write-Output $workspaceName if (-not ([string]::IsNullOrWhiteSpace($workspaceName))) { Write-Output "Terraform workspace selection..." terraform workspace select $workspaceName -no-color 2>&1 # @todo Add ' -or-create' back @@ -87,6 +88,7 @@ $childItems | Foreach-Object -ThrottleLimit 5 -Parallel { Write-Output $planResult } else { Write-Output "No workspace defined: no plan performed." + Write-Output $workspaceName } } From 891d73b04feb4228decbbf7a93b65e28cfd886a3 Mon Sep 17 00:00:00 2001 From: Antoine Milochau <48644548+amilochau@users.noreply.github.com> Date: Mon, 8 Jan 2024 08:28:56 +0400 Subject: [PATCH 07/17] Test --- build/terraform/build-terraform.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build/terraform/build-terraform.ps1 b/build/terraform/build-terraform.ps1 index 6ea3368..02e1275 100644 --- a/build/terraform/build-terraform.ps1 +++ b/build/terraform/build-terraform.ps1 @@ -68,8 +68,8 @@ $childItems | Foreach-Object -ThrottleLimit 5 -Parallel { throw 1 } - Write-Output $workspaceName - if (-not ([string]::IsNullOrWhiteSpace($workspaceName))) { + Write-Output "$workspaceName" + if (-not ([string]::IsNullOrWhiteSpace("$workspaceName"))) { Write-Output "Terraform workspace selection..." terraform workspace select $workspaceName -no-color 2>&1 # @todo Add ' -or-create' back if (!$?) { @@ -88,7 +88,7 @@ $childItems | Foreach-Object -ThrottleLimit 5 -Parallel { Write-Output $planResult } else { Write-Output "No workspace defined: no plan performed." - Write-Output $workspaceName + Write-Output "$workspaceName" } } From d419779a24e08dddcfe14edf75c57eb75b4e784e Mon Sep 17 00:00:00 2001 From: Antoine Milochau <48644548+amilochau@users.noreply.github.com> Date: Mon, 8 Jan 2024 08:34:36 +0400 Subject: [PATCH 08/17] Test --- build/terraform/action.yml | 1 + build/terraform/build-terraform.ps1 | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/build/terraform/action.yml b/build/terraform/action.yml index edf7f96..275db58 100644 --- a/build/terraform/action.yml +++ b/build/terraform/action.yml @@ -10,6 +10,7 @@ inputs: default: '1' workspaceName: description: The name of the Terraform workspace where to plan changes + required: false default: '' verbosity: description: The verbosity of the scripts diff --git a/build/terraform/build-terraform.ps1 b/build/terraform/build-terraform.ps1 index 02e1275..6147a1a 100644 --- a/build/terraform/build-terraform.ps1 +++ b/build/terraform/build-terraform.ps1 @@ -19,7 +19,7 @@ Param( [parameter(Mandatory = $true)] [int]$modulesPathDepth, - [parameter(Mandatory = $false)] + [parameter(Mandatory = $true)] [string]$workspaceName, [parameter(Mandatory = $true)] @@ -69,7 +69,7 @@ $childItems | Foreach-Object -ThrottleLimit 5 -Parallel { } Write-Output "$workspaceName" - if (-not ([string]::IsNullOrWhiteSpace("$workspaceName"))) { + if (-not ([string]::IsNullOrWhiteSpace($workspaceName))) { Write-Output "Terraform workspace selection..." terraform workspace select $workspaceName -no-color 2>&1 # @todo Add ' -or-create' back if (!$?) { From db35e8f4527fd5f0880806f7c633988c293b2827 Mon Sep 17 00:00:00 2001 From: Antoine Milochau <48644548+amilochau@users.noreply.github.com> Date: Mon, 8 Jan 2024 08:40:51 +0400 Subject: [PATCH 09/17] Test --- build/terraform/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/terraform/action.yml b/build/terraform/action.yml index 275db58..5dd24eb 100644 --- a/build/terraform/action.yml +++ b/build/terraform/action.yml @@ -29,5 +29,5 @@ runs: run: ${{ github.action_path }}/build-terraform.ps1 ` -modulesPath "${{ inputs.modulesPath }}" ` -modulesPathDepth "${{ inputs.modulesPathDepth }}" ` - -workspaceName "${{ inputs.workspaceName }}" ` + -workspaceName ${{ inputs.workspaceName }} ` -verbosity ${{ inputs.verbosity }} From 13b4e29e3efd4af8c5e258c489de928fe304d049 Mon Sep 17 00:00:00 2001 From: Antoine Milochau <48644548+amilochau@users.noreply.github.com> Date: Mon, 8 Jan 2024 08:46:16 +0400 Subject: [PATCH 10/17] Test --- deploy/terraform/deploy-terraform.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/deploy/terraform/deploy-terraform.ps1 b/deploy/terraform/deploy-terraform.ps1 index dbc88cd..ea8b71d 100644 --- a/deploy/terraform/deploy-terraform.ps1 +++ b/deploy/terraform/deploy-terraform.ps1 @@ -24,6 +24,7 @@ Param( Write-Output "Modules path is: $modulesPath" Write-Output "Workspace name is: $workspaceName" +Write-Output "Workspace name is: $workspaceName" Write-Output "Verbosity is: $verbosity" Write-Output '==========' From 5ab71a4e9dcd73c5097282b080e06987d0bfc07e Mon Sep 17 00:00:00 2001 From: Antoine Milochau <48644548+amilochau@users.noreply.github.com> Date: Mon, 8 Jan 2024 08:51:14 +0400 Subject: [PATCH 11/17] Test --- build/terraform/build-terraform.ps1 | 1 + deploy/terraform/deploy-terraform.ps1 | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/build/terraform/build-terraform.ps1 b/build/terraform/build-terraform.ps1 index 6147a1a..bc85737 100644 --- a/build/terraform/build-terraform.ps1 +++ b/build/terraform/build-terraform.ps1 @@ -30,6 +30,7 @@ Param( Write-Output "Modules path is: $modulesPath" Write-Output "Modules path depth is: $modulesPathDepth" Write-Output "Workspace name is: $workspaceName" +Write-Output "Workspace name is: $workspaceName" Write-Output "Verbosity is: $verbosity" Write-Output '==========' diff --git a/deploy/terraform/deploy-terraform.ps1 b/deploy/terraform/deploy-terraform.ps1 index ea8b71d..dbc88cd 100644 --- a/deploy/terraform/deploy-terraform.ps1 +++ b/deploy/terraform/deploy-terraform.ps1 @@ -24,7 +24,6 @@ Param( Write-Output "Modules path is: $modulesPath" Write-Output "Workspace name is: $workspaceName" -Write-Output "Workspace name is: $workspaceName" Write-Output "Verbosity is: $verbosity" Write-Output '==========' From 02c5c89eec806e950a1356c19a981c76d3207e58 Mon Sep 17 00:00:00 2001 From: Antoine Milochau <48644548+amilochau@users.noreply.github.com> Date: Mon, 8 Jan 2024 08:54:55 +0400 Subject: [PATCH 12/17] Fix --- build/terraform/action.yml | 2 +- build/terraform/build-terraform.ps1 | 41 +++++++++++++---------------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/build/terraform/action.yml b/build/terraform/action.yml index 5dd24eb..275db58 100644 --- a/build/terraform/action.yml +++ b/build/terraform/action.yml @@ -29,5 +29,5 @@ runs: run: ${{ github.action_path }}/build-terraform.ps1 ` -modulesPath "${{ inputs.modulesPath }}" ` -modulesPathDepth "${{ inputs.modulesPathDepth }}" ` - -workspaceName ${{ inputs.workspaceName }} ` + -workspaceName "${{ inputs.workspaceName }}" ` -verbosity ${{ inputs.verbosity }} diff --git a/build/terraform/build-terraform.ps1 b/build/terraform/build-terraform.ps1 index bc85737..48ff891 100644 --- a/build/terraform/build-terraform.ps1 +++ b/build/terraform/build-terraform.ps1 @@ -19,7 +19,7 @@ Param( [parameter(Mandatory = $true)] [int]$modulesPathDepth, - [parameter(Mandatory = $true)] + [parameter(Mandatory = $false)] [string]$workspaceName, [parameter(Mandatory = $true)] @@ -30,7 +30,6 @@ Param( Write-Output "Modules path is: $modulesPath" Write-Output "Modules path depth is: $modulesPathDepth" Write-Output "Workspace name is: $workspaceName" -Write-Output "Workspace name is: $workspaceName" Write-Output "Verbosity is: $verbosity" Write-Output '==========' @@ -68,29 +67,27 @@ $childItems | Foreach-Object -ThrottleLimit 5 -Parallel { Write-Output "::error title=Terraform failed::Terraform validation failed" throw 1 } +} + +if (-not ([string]::IsNullOrWhiteSpace($workspaceName))) { + Write-Output "Terraform workspace selection..." + terraform workspace select $workspaceName -no-color 2>&1 # @todo Add ' -or-create' back + if (!$?) { + Write-Output "::error title=Terraform failed::Terraform workspace selection failed" + throw 1 + } - Write-Output "$workspaceName" - if (-not ([string]::IsNullOrWhiteSpace($workspaceName))) { - Write-Output "Terraform workspace selection..." - terraform workspace select $workspaceName -no-color 2>&1 # @todo Add ' -or-create' back - if (!$?) { - Write-Output "::error title=Terraform failed::Terraform workspace selection failed" - throw 1 - } - - Write-Output "Terraform plan..." - $planResult = terraform plan -var-file="hosts/$workspaceName.tfvars" -input=false -no-color -lock=false 2>&1 - if (!$?) { - Write-Output $planResult - Write-Output "::error title=Terraform failed::Terraform plan failed" - throw 1 - } - + Write-Output "Terraform plan..." + $planResult = terraform plan -var-file="hosts/$workspaceName.tfvars" -input=false -no-color -lock=false 2>&1 + if (!$?) { Write-Output $planResult - } else { - Write-Output "No workspace defined: no plan performed." - Write-Output "$workspaceName" + Write-Output "::error title=Terraform failed::Terraform plan failed" + throw 1 } + + Write-Output $planResult +} else { + Write-Output "No workspace defined: no plan performed." } Write-Output '==========' From c0f90d35dee356912c1bb1d5b028709d6704df64 Mon Sep 17 00:00:00 2001 From: Antoine Milochau <48644548+amilochau@users.noreply.github.com> Date: Mon, 8 Jan 2024 09:22:47 +0400 Subject: [PATCH 13/17] Fix --- build/terraform/build-terraform.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/terraform/build-terraform.ps1 b/build/terraform/build-terraform.ps1 index 48ff891..b96b48c 100644 --- a/build/terraform/build-terraform.ps1 +++ b/build/terraform/build-terraform.ps1 @@ -71,7 +71,7 @@ $childItems | Foreach-Object -ThrottleLimit 5 -Parallel { if (-not ([string]::IsNullOrWhiteSpace($workspaceName))) { Write-Output "Terraform workspace selection..." - terraform workspace select $workspaceName -no-color 2>&1 # @todo Add ' -or-create' back + terraform workspace select -or-create $workspaceName -no-color 2>&1 # @todo Add ' -or-create' back if (!$?) { Write-Output "::error title=Terraform failed::Terraform workspace selection failed" throw 1 From cc048d1b0342643771fe3df63bf23c8415938796 Mon Sep 17 00:00:00 2001 From: Antoine Milochau <48644548+amilochau@users.noreply.github.com> Date: Mon, 8 Jan 2024 13:52:56 +0400 Subject: [PATCH 14/17] Improve working drectories --- build/terraform/action.yml | 3 ++- build/terraform/build-terraform.ps1 | 8 +------- deploy/terraform/action.yml | 1 - deploy/terraform/deploy-terraform.ps1 | 6 ------ 4 files changed, 3 insertions(+), 15 deletions(-) diff --git a/build/terraform/action.yml b/build/terraform/action.yml index 275db58..212195a 100644 --- a/build/terraform/action.yml +++ b/build/terraform/action.yml @@ -27,7 +27,8 @@ runs: - name: Build Terraform modules with script shell: pwsh run: ${{ github.action_path }}/build-terraform.ps1 ` - -modulesPath "${{ inputs.modulesPath }}" ` -modulesPathDepth "${{ inputs.modulesPathDepth }}" ` -workspaceName "${{ inputs.workspaceName }}" ` -verbosity ${{ inputs.verbosity }} + working-directory: ${{ inputs.modulePath }} + diff --git a/build/terraform/build-terraform.ps1 b/build/terraform/build-terraform.ps1 index b96b48c..1aaae55 100644 --- a/build/terraform/build-terraform.ps1 +++ b/build/terraform/build-terraform.ps1 @@ -1,8 +1,6 @@ <# .SYNOPSIS This script builds and tests Terraform modules - .PARAMETER modulesPath - The path to the Terraform modules to build .PARAMETER modulesPathDepth The depth of the path search, to find the Terraform modules to build .PARAMETER workspaceName @@ -13,9 +11,6 @@ [CmdletBinding()] Param( - [parameter(Mandatory = $true)] - [string]$modulesPath, - [parameter(Mandatory = $true)] [int]$modulesPathDepth, @@ -27,7 +22,6 @@ Param( [string]$verbosity ) -Write-Output "Modules path is: $modulesPath" Write-Output "Modules path depth is: $modulesPathDepth" Write-Output "Workspace name is: $workspaceName" Write-Output "Verbosity is: $verbosity" @@ -36,7 +30,7 @@ Write-Output '==========' $sw = [Diagnostics.Stopwatch]::StartNew() $pathFilter = 'main.tf' -$childItems = Get-ChildItem -Path $modulesPath -Recurse -Depth $modulesPathDepth -Filter $pathFilter -Force +$childItems = Get-ChildItem -Recurse -Depth $modulesPathDepth -Filter $pathFilter -Force $childItemsCount = $childItems.Count Write-Output "Items found: $childItemsCount" diff --git a/deploy/terraform/action.yml b/deploy/terraform/action.yml index 7f2b4f8..df3c220 100644 --- a/deploy/terraform/action.yml +++ b/deploy/terraform/action.yml @@ -23,7 +23,6 @@ runs: - name: Build Terraform modules with script shell: pwsh run: ${{ github.action_path }}/deploy-terraform.ps1 ` - -modulePath ${{ inputs.modulePath }} ` -workspaceName ${{ inputs.workspaceName }} ` -verbosity ${{ inputs.verbosity }} working-directory: ${{ inputs.modulePath }} diff --git a/deploy/terraform/deploy-terraform.ps1 b/deploy/terraform/deploy-terraform.ps1 index dbc88cd..9639a81 100644 --- a/deploy/terraform/deploy-terraform.ps1 +++ b/deploy/terraform/deploy-terraform.ps1 @@ -1,8 +1,6 @@ <# .SYNOPSIS This script deploy a Terraform module - .PARAMETER modulePath - The path to the Terraform module to deploy .PARAMETER workspaceName The name of the Terraform workspace .PARAMETER verbosity @@ -11,9 +9,6 @@ [CmdletBinding()] Param( - [parameter(Mandatory = $true)] - [string]$modulePath, - [parameter(Mandatory = $true)] [string]$workspaceName, @@ -22,7 +17,6 @@ Param( [string]$verbosity ) -Write-Output "Modules path is: $modulesPath" Write-Output "Workspace name is: $workspaceName" Write-Output "Verbosity is: $verbosity" From 714902f28959cf0c7cf260a011e204d6cc798989 Mon Sep 17 00:00:00 2001 From: Antoine Milochau <48644548+amilochau@users.noreply.github.com> Date: Mon, 8 Jan 2024 13:55:18 +0400 Subject: [PATCH 15/17] Fix --- build/terraform/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/terraform/action.yml b/build/terraform/action.yml index 212195a..32ab1d6 100644 --- a/build/terraform/action.yml +++ b/build/terraform/action.yml @@ -30,5 +30,5 @@ runs: -modulesPathDepth "${{ inputs.modulesPathDepth }}" ` -workspaceName "${{ inputs.workspaceName }}" ` -verbosity ${{ inputs.verbosity }} - working-directory: ${{ inputs.modulePath }} + working-directory: ${{ inputs.modulesPath }} From 503b501bc6099a4f77c5d3035badaff5810ab0e2 Mon Sep 17 00:00:00 2001 From: Antoine Milochau <48644548+amilochau@users.noreply.github.com> Date: Mon, 8 Jan 2024 14:02:31 +0400 Subject: [PATCH 16/17] Fix --- build/terraform/build-terraform.ps1 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/build/terraform/build-terraform.ps1 b/build/terraform/build-terraform.ps1 index 1aaae55..82efa5b 100644 --- a/build/terraform/build-terraform.ps1 +++ b/build/terraform/build-terraform.ps1 @@ -64,8 +64,15 @@ $childItems | Foreach-Object -ThrottleLimit 5 -Parallel { } if (-not ([string]::IsNullOrWhiteSpace($workspaceName))) { + Write-Output "Terraform initialisation..." + terraform init -input=false -upgrade -no-color 2>&1 + if (!$?) { + Write-Output "::error title=Terraform failed::Terraform initialization failed" + throw 1 + } + Write-Output "Terraform workspace selection..." - terraform workspace select -or-create $workspaceName -no-color 2>&1 # @todo Add ' -or-create' back + terraform workspace select -or-create $workspaceName -no-color 2>&1 if (!$?) { Write-Output "::error title=Terraform failed::Terraform workspace selection failed" throw 1 From ea94f926beaba5a3c4ae4b009c12a7d6cc32d924 Mon Sep 17 00:00:00 2001 From: Antoine Milochau <48644548+amilochau@users.noreply.github.com> Date: Mon, 8 Jan 2024 14:08:23 +0400 Subject: [PATCH 17/17] Documentation improvement --- build/terraform/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/terraform/README.md b/build/terraform/README.md index 0d73174..871bd64 100644 --- a/build/terraform/README.md +++ b/build/terraform/README.md @@ -33,7 +33,7 @@ jobs: | ----- | ----------- | -------- | ------------- | ------- | | `modulesPath` | The path to the Terraform modules to build | *false* | `.tf` | | `modulesPathDepth` | The path to the projects to test - can be a .csproj or a .sln file | *false* | `1` | -| `workspaceName` | The name of the Terraform workspace where to plan changes | *false* | `""` | +| `workspaceName` | The name of the Terraform workspace where to plan changes | *false* | `""` | Requires valid credentials to access the state file | | `verbosity` | The verbosity of the scripts | *false* | `minimal` | Set to `minimal`, `normal` or `detailed` | ### Outputs