Skip to content

Commit

Permalink
Merge pull request #14 from pearcec/dev/0.5.0
Browse files Browse the repository at this point in the history
Dev/0.5.0
  • Loading branch information
pearcec authored Apr 16, 2021
2 parents 33b07ab + 5345b6e commit 22982bc
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.5.0]

### Changed

- `Invoke-Terraform` recursively searches up for `.terraform-version` stopping at root ([#12](https://github.com/pearcec/Invoke-Terraform/issues/12))

## [0.4.0]

### Added
Expand Down
2 changes: 1 addition & 1 deletion Invoke-Terraform/Invoke-Terraform.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'Invoke-Terraform.psm1'

# Version number of this module.
ModuleVersion = '0.4.0'
ModuleVersion = '0.5.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
22 changes: 22 additions & 0 deletions Invoke-Terraform/Private/Get-TerraformVersion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Function Get-TerraformVersion {
param(
[parameter(Mandatory)]
[string]$Path
)

$terraformVersionFile = Join-Path -Path $Path -ChildPath .terraform-version
if (Test-Path -Path $terraformVersionFile -PathType Leaf) {
return $terraformVersionFile
}

$Parent = Split-Path $Path
if ($Parent -eq $Home) {
return $null
}
if ($Parent) {
return Get-TerraformVersion $Parent
}

# Shouldn't get here
return $null
}
5 changes: 3 additions & 2 deletions Invoke-Terraform/Public/Invoke-Terraform.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ Function Invoke-Terraform {
$TFArgs = $args
}

if ((Test-Path .terraform-version) -and (-not $TFVersion)) {
$TFVersion = Get-Content .terraform-version
$terraformVersionFile = Get-TerraformVersion -Path (Get-Item .).FullName
if ($terraformVersionFile -and (-not $TFVersion)) {
$TFVersion = Get-Content $terraformVersionFile
# TODO regex validate the version
Write-Verbose "Found .terraform-version $TFVersion"
}
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/Invoke-Terraform.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,13 @@ Describe 'Invoke-Terraform' {
Invoke-Terraform 0.14.6 -version | Out-File TestDrive:\version-0.14.6.txt
(Get-Content TestDrive:\version-0.14.6.txt)[0] | Should -Match 0.14.6
}
It 'has version 0.14.1 from .terraform-version' {
Set-TerraformVersion -TFVersion 0.14.5 -Confirm:$false
Set-TerraformAutoDownload -AutoDownload $true -Confirm:$false
$terraformVersionFile = [IO.Path]::Combine('..', '.terraform-version')
'0.14.1' | Out-File -Path $terraformVersionFile
Invoke-Terraform -version | Out-File TestDrive:\version-0.14.1.txt
(Get-Content TestDrive:\version-0.14.1.txt)[0] | Should -Match 0.14.1
Remove-Item -Force -Path $terraformVersionFile
}
}

0 comments on commit 22982bc

Please sign in to comment.