Skip to content

Commit 52bab4e

Browse files
Backport of Fix crash when showing a cloud plan without having a cloud backend into v1.14 (#37756)
* backport of commit f85b17c * backport of commit f86e0c0 --------- Co-authored-by: Daniel Banck <daniel@dbanck.de>
1 parent 74a8d2c commit 52bab4e

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: BUG FIXES
2+
body: Fix crash when showing a cloud plan without having a cloud backend
3+
time: 2025-10-09T14:46:45.59398+02:00
4+
custom:
5+
Issue: "37751"

internal/cloud/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ func (b *Cloud) Configure(obj cty.Value) tfdiags.Diagnostics {
437437
}
438438

439439
func (b *Cloud) AppName() string {
440-
if isValidAppName(b.appName) {
440+
if b != nil && isValidAppName(b.appName) {
441441
return b.appName
442442
}
443443
return "HCP Terraform"

internal/cloud/backend_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,3 +1705,15 @@ func TestCloud_ServiceDiscoveryAliases(t *testing.T) {
17051705
t.Fatalf("expected 1 alias but got %d", len(aliases))
17061706
}
17071707
}
1708+
1709+
// When a user tries to view a cloud plan without having a cloud backend in their
1710+
// configuration, a call to AppName() would fail with a nil pointer exception
1711+
// See: https://github.com/hashicorp/terraform/issues/37748
1712+
func TestCloud_AppName_with_nil(t *testing.T) {
1713+
var backend *Cloud = nil
1714+
1715+
name := backend.AppName()
1716+
if name != "HCP Terraform" {
1717+
t.Fatalf("expected name to be HCP Terraform, got %q", name)
1718+
}
1719+
}

0 commit comments

Comments
 (0)