diff --git a/CHANGELOG.md b/CHANGELOG.md index d9ee3e4..99b81be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All notable changes to LibreDevOpsHelpers are recorded here. +## 3.0.1 + +### Fixed +- `Invoke-LdoTerraformPlanDestroy` now writes `tfplan-destroy.plan` by default, the file + `Invoke-LdoTerraformDestroy` applies by default. It wrote `tfplan.plan.destroy`, so the pair + called with their defaults (as every Libre DevOps module's `just destroy` does) planned one file + and then failed to find the other. A caller that names `-PlanFile` on both is unaffected. + ## 3.0.0 ### Changed diff --git a/LibreDevOpsHelpers/LibreDevOpsHelpers.Terraform/LibreDevOpsHelpers.Terraform.psm1 b/LibreDevOpsHelpers/LibreDevOpsHelpers.Terraform/LibreDevOpsHelpers.Terraform.psm1 index 23f09ea..ac17c9f 100644 --- a/LibreDevOpsHelpers/LibreDevOpsHelpers.Terraform/LibreDevOpsHelpers.Terraform.psm1 +++ b/LibreDevOpsHelpers/LibreDevOpsHelpers.Terraform/LibreDevOpsHelpers.Terraform.psm1 @@ -417,7 +417,8 @@ function Invoke-LdoTerraformPlanDestroy { Path to the Terraform configuration folder. .PARAMETER PlanFile - Output plan file name. Defaults to tfplan.plan.destroy. + Output plan file name. Defaults to tfplan-destroy.plan, the file Invoke-LdoTerraformDestroy + applies by default, so the pair works without naming it. .PARAMETER PlanArgs Additional arguments passed through to terraform plan. @@ -432,7 +433,7 @@ function Invoke-LdoTerraformPlanDestroy { [OutputType([void])] param( [Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$CodePath, - [string]$PlanFile = 'tfplan.plan.destroy', + [string]$PlanFile = 'tfplan-destroy.plan', [string[]]$PlanArgs = @() ) @@ -538,7 +539,7 @@ function Invoke-LdoTerraformDestroy { Additional arguments passed through to terraform apply. .EXAMPLE - Invoke-LdoTerraformDestroy -CodePath ./terraform -PlanFile tfplan.plan.destroy + Invoke-LdoTerraformDestroy -CodePath ./terraform -PlanFile tfplan-destroy.plan .OUTPUTS None diff --git a/LibreDevOpsHelpers/LibreDevOpsHelpers.psd1 b/LibreDevOpsHelpers/LibreDevOpsHelpers.psd1 index fe70b8c..3b213e2 100644 --- a/LibreDevOpsHelpers/LibreDevOpsHelpers.psd1 +++ b/LibreDevOpsHelpers/LibreDevOpsHelpers.psd1 @@ -12,7 +12,7 @@ RootModule = '.\LibreDevOpsHelpers.psm1' # Version number of this module. - ModuleVersion = '3.0.0' + ModuleVersion = '3.0.1' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/tests/Git.Tests.ps1 b/tests/Git.Tests.ps1 index 6d0131c..fe01d46 100644 --- a/tests/Git.Tests.ps1 +++ b/tests/Git.Tests.ps1 @@ -51,12 +51,18 @@ Describe 'Get-LdoGitBranch / Get-LdoGitRepositoryUrl (CI env)' { Describe 'Export-LdoGitContextToTfVar' { BeforeEach { $script:saved = @{ - GITHUB_REF_NAME = $env:GITHUB_REF_NAME - GITHUB_SERVER_URL = $env:GITHUB_SERVER_URL - GITHUB_REPOSITORY = $env:GITHUB_REPOSITORY + GITHUB_HEAD_REF = $env:GITHUB_HEAD_REF + BUILD_SOURCEBRANCHNAME = $env:BUILD_SOURCEBRANCHNAME + GITHUB_REF_NAME = $env:GITHUB_REF_NAME + GITHUB_SERVER_URL = $env:GITHUB_SERVER_URL + GITHUB_REPOSITORY = $env:GITHUB_REPOSITORY TF_VAR_deployed_branch = $env:TF_VAR_deployed_branch TF_VAR_deployed_repo = $env:TF_VAR_deployed_repo } + # A pull request build sets GITHUB_HEAD_REF, which the branch lookup prefers, so clear it + # (and the Azure DevOps one) for the GITHUB_REF_NAME below to be the answer. + $env:GITHUB_HEAD_REF = '' + $env:BUILD_SOURCEBRANCHNAME = '' $env:GITHUB_REF_NAME = 'main' $env:GITHUB_SERVER_URL = 'https://github.com' $env:GITHUB_REPOSITORY = 'libre-devops/terraform-azurerm-tags' diff --git a/tests/Terraform.Tests.ps1 b/tests/Terraform.Tests.ps1 index f2d04c4..88b757d 100644 --- a/tests/Terraform.Tests.ps1 +++ b/tests/Terraform.Tests.ps1 @@ -15,6 +15,18 @@ Describe 'Terraform module surface' { } } +Describe 'Destroy plan file defaults' { + It 'plans the file the destroy applies, so the pair works without naming it' { + $default = { + param([string]$Command) + $parameters = (Get-Command $Command).ScriptBlock.Ast.Body.ParamBlock.Parameters + ($parameters | Where-Object { $_.Name.VariablePath.UserPath -eq 'PlanFile' }).DefaultValue.Value + } + & $default 'Invoke-LdoTerraformPlanDestroy' | Should -Be 'tfplan-destroy.plan' + & $default 'Invoke-LdoTerraformDestroy' | Should -Be (& $default 'Invoke-LdoTerraformPlanDestroy') + } +} + Describe 'Invoke-LdoTerraformValidate' { It 'throws when the code path does not exist' { { Invoke-LdoTerraformValidate -CodePath (Join-Path ([System.IO.Path]::GetTempPath()) ([guid]::NewGuid())) } |