Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 21, 2025

The $os variable was referenced before initialization in Get-TerraformTool.ps1, causing the PATH separator to default to Linux format (:) on all platforms instead of Windows (;), breaking terraform.exe discovery.

Changes

  • Move $osArchitecture = Get-OSArchitecture call before first usage (line 42, previously line 53)
  • Replace undefined $os with $osArchitecture.os in PATH separator logic

Before

$unzipdir = Join-Path -Path $toolsPath -ChildPath "terraform_$version"
if (Test-Path $unzipdir) {
    if($os -eq "windows") {  # $os undefined here
        $env:PATH = "$($unzipdir);$env:PATH"
    } else {
        $env:PATH = "$($unzipdir):$env:PATH"
    }
    return
}

$osArchitecture = Get-OSArchitecture  # Too late

After

$osArchitecture = Get-OSArchitecture  # Initialize first

$unzipdir = Join-Path -Path $toolsPath -ChildPath "terraform_$version"
if (Test-Path $unzipdir) {
    if($osArchitecture.os -eq "windows") {  # Properly initialized
        $env:PATH = "$($unzipdir);$env:PATH"
    } else {
        $env:PATH = "$($unzipdir):$env:PATH"
    }
    return
}

Note

The same issue exists in terraform-installer.yaml in the accelerator-bootstrap-modules repository and requires a separate fix there.

Fixes Azure/accelerator-bootstrap-modules#114

Original prompt

This section details on the original issue you should resolve

<issue_title>Bug: terraform.exe location cannot be found</issue_title>
<issue_description>### Is there an existing issue for this?

  • I have searched the existing issues

Infrastructure as Code Type? (Required)

terraform

PowerShell Module Version (Optional)

No response

Bootstrap Module Version (Optional)

No response

Starter Module? (Required)

terraform - platform_landing_zone

Starter Module Version (Optional)

No response

Input arguments of the ALZ-PowerShell-Module (Optional)

No response

Debug Output/Panic Output (Optional)

Expected Behaviour (Required)

In the accelerator, I corrected the following in the script "Get-TerraformTool.ps1":
In this script, starting at line 42, the downloaded ZIP file containing the terraform.exe file is extracted, and then the PATH variable is set depending on the OS (Windows or Linux). However, the variable '$os' used for this is only set in line 53 via the function "Get-OSArchitecture". This causes the PATH variable to be extended with the same format as for Linux, i.e., with the ":" character, even for Windows. As a result, when running terraform.exe, the location cannot be found.
I simply copied the command line "$osArchitecture = Get-OSArchitecture" to before the unzip step, i.e., to line 42...
I also noticed the same error in the YAML file 'terraform-installer.yaml' of the CI pipeline templates

  $unzipdir = Join-Path -Path $TOOLS_PATH -ChildPath "terraform_$TF_VERSION"
 if (Test-Path $unzipdir) {
   Write-Host "Terraform $TF_VERSION already installed."
   if($os -eq "windows") {
     $env:PATH = "$($unzipdir);$env:PATH"
   } else {
     $env:PATH = "$($unzipdir):$env:PATH"
   }
   Write-Host "##vso[task.setvariable variable=PATH]$env:PATH"
   return
 }

 $os = ""
 if ($IsWindows) {
   $os = "windows"
 }
 if($IsLinux) {
   $os = "linux"
 }
 if($IsMacOS) {
   $os = "darwin"
 }

Here too, the '$os' variable is accessed, even though it has not been initialized yet."

Actual Behaviour (Required)

the '$os' variable is accessed, even though it has not been initialized yet."

Steps to Reproduce (Optional)

No response

Important Factoids (Optional)

No response

References (Optional)

No response</issue_description>

<agent_instructions>You got this buddy!</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…rraformTool.ps1

Co-authored-by: jaredfholgate <1612200+jaredfholgate@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix bug with terraform.exe location in Get-TerraformTool.ps1 Fix: Undefined variable reference in Get-TerraformTool causing incorrect PATH separator on Windows Nov 21, 2025
Copilot AI requested a review from jaredfholgate November 21, 2025 17:49
Copilot finished work on behalf of jaredfholgate November 21, 2025 17:49
@jaredfholgate jaredfholgate marked this pull request as ready for review November 21, 2025 17:54
@jaredfholgate
Copy link
Member

@copilot fix the name of the pr to meet semantic versioning rules

Copy link
Contributor Author

Copilot AI commented Nov 21, 2025

@copilot fix the name of the pr to meet semantic versioning rules

Updated the PR title to use lowercase "fix:" prefix to comply with semantic versioning rules (Conventional Commits format). The PR title now follows the repository's convention as enforced by the semantic-pull-request action.

Copilot AI changed the title Fix: Undefined variable reference in Get-TerraformTool causing incorrect PATH separator on Windows fix: undefined variable reference in Get-TerraformTool causing incorrect PATH separator on Windows Nov 21, 2025
Copilot AI requested a review from jaredfholgate November 21, 2025 17:58
Copilot finished work on behalf of jaredfholgate November 21, 2025 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: terraform.exe location cannot be found

2 participants