Skip to content

fix: Use Terraform releases 'latest' endpoint to resolve null releases - #144

Merged
Qi Zhang (Zhangqi910) merged 1 commit into
mainfrom
dev/v-zqi/fixTFversion
Aug 20, 2026
Merged

Qi Zhang (Zhangqi910) merged 1 commit into
mainfrom
dev/v-zqi/fixTFversion

Conversation

@Zhangqi910

@Zhangqi910 Qi Zhang (Zhangqi910) commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #4242

When using the AzureDevOps Terraform pipeline template with terraformVersion: latest, the pipeline can fail on certain PowerShell versions (observed on PowerShell 5.1 during testing) with the error:

Line |
  14 |    $release = $releases[0]
     |    ~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot index into a null array.

Root Cause

The current implementation queries https://api.releases.hashicorp.com/v1/releases/terraform?limit=20 and filters the results with Where-Object -Property is_prerelease -EQ $false, then takes the first element ($releases[0]) as the latest release.

This logic can behave inconsistently across different PowerShell versions, depending on how the underlying HTTP client parses the response. On some versions, this results in $releases evaluating to $null, causing the subsequent index operation to throw.

Fix

Replace the ?limit=20 + filter/index approach with a direct call to the dedicated latest release endpoint:

https://api.releases.hashicorp.com/v1/releases/terraform/latest

This endpoint returns the latest stable Terraform release directly as a single JSON object, removing the need to filter/index an array and avoiding the version-specific parsing inconsistency entirely.

Changes

  • Updated alz/azuredevops/pipelines/terraform/templates/helpers/terraform-installer.yaml to call /v1/releases/terraform/latest instead of /v1/releases/terraform?limit=20 when $TF_VERSION -eq "latest".
  • Removed the now-unnecessary Where-Object -Property is_prerelease -EQ $false filtering and array indexing logic.

Testing

  • Verified the pipeline installs Terraform successfully on the PowerShell version where the issue was originally reproduced, with terraformVersion: latest.
  • Verified the pipeline continues to work correctly on other PowerShell versions.
  • Verified pinned version installs (terraformVersion: <specific version>) are unaffected.

@Zhangqi910
Qi Zhang (Zhangqi910) merged commit 3d2ccf0 into main Aug 20, 2026
10 checks passed
@Zhangqi910
Qi Zhang (Zhangqi910) deleted the dev/v-zqi/fixTFversion branch August 20, 2026 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

[Bug]: AzureDevOps getting latest terraform Version

2 participants