Skip to content

fix: Nil pointer dereference in atlantis version command#5971

Merged
jamengual merged 2 commits intorunatlantis:mainfrom
Adamovix:fix-terraform-version-panic
Nov 20, 2025
Merged

fix: Nil pointer dereference in atlantis version command#5971
jamengual merged 2 commits intorunatlantis:mainfrom
Adamovix:fix-terraform-version-panic

Conversation

@Adamovix
Copy link
Contributor

@Adamovix Adamovix commented Nov 20, 2025

what

Fixes #5972

Initialize DefaultTFDistribution field in VersionStepRunner to match pattern used by InitStepRunner, ApplyStepRunner, and ImportStepRunner.

why

Without this field, atlantis version command causes two bugs:

Bug 1: Nil pointer panic

  • When terraform binary cache is empty (after Atlantis restart, upgrade, or cache clear)
  • Panic at terraform_client.go:509 when calling dist.BinName() on nil distribution

Bug 2: Command failure on fresh instances

  • On fresh Atlantis instances with existing PRs
  • Fails with "no such file or directory" / "no projects to run version in"

tests

Reproduction:

  1. Clear cached binaries: rm -rf ~/.atlantis/bin/*
  2. Run atlantis version

Result:

  • Before fix: Panic with nil pointer dereference
  • After fix: Downloads required terraform version and executes successfully

Tested on locally built Docker image with fix applied.

references

### What
Fix nil pointer panic in VersionStepRunner

Initialize DefaultTFDistribution field in VersionStepRunner to match pattern used by InitStepRunner, ApplyStepRunner, and ImportStepRunner.

### Why
Without this field, version command panics with nil pointer dereference at terraform_client.go:509 when terraform binary cache is empty (after Atlantis restart, upgrade, or cache clear).

### Tests
Reproduction: Clear cache on Atlantis instance (rm -rf ~/.atlantis/bin/*), run `atlantis version`
Result: Panic before fix, works correctly after fix. Tested on locally build docker image with a fixed code.

### References

Signed-off-by: Adam Gościcki <adamgoscicki@gmail.com>
@github-actions github-actions bot added the go Pull requests that update Go code label Nov 20, 2025
@dosubot dosubot bot added bug Something isn't working go Pull requests that update Go code labels Nov 20, 2025
@bschaatsbergen bschaatsbergen self-requested a review November 20, 2025 12:28
@bschaatsbergen bschaatsbergen self-assigned this Nov 20, 2025
bschaatsbergen
bschaatsbergen previously approved these changes Nov 20, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 20, 2025
Signed-off-by: Adamovix <adamgoscicki@gmail.com>
@jamengual jamengual merged commit 94b8d37 into runatlantis:main Nov 20, 2025
41 checks passed
@jamengual
Copy link
Contributor

Thanks @Adamovix for the contribution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update Go code lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nil Pointer Dereference in atlantis version command execution

3 participants