Fix crash when showing a cloud plan without having a cloud backend (#37751)

* Fix crash when showing a cloud plan without a cloud backend

* Add changelog
pull/37759/head
Daniel Banck 6 months ago committed by GitHub
parent 2714cfde69
commit cc30a8cf1d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
kind: BUG FIXES
body: Fix crash when showing a cloud plan without having a cloud backend
time: 2025-10-09T14:46:45.59398+02:00
custom:
Issue: "37751"

@ -437,7 +437,7 @@ func (b *Cloud) Configure(obj cty.Value) tfdiags.Diagnostics {
}
func (b *Cloud) AppName() string {
if isValidAppName(b.appName) {
if b != nil && isValidAppName(b.appName) {
return b.appName
}
return "HCP Terraform"

@ -1705,3 +1705,15 @@ func TestCloud_ServiceDiscoveryAliases(t *testing.T) {
t.Fatalf("expected 1 alias but got %d", len(aliases))
}
}
// When a user tries to view a cloud plan without having a cloud backend in their
// configuration, a call to AppName() would fail with a nil pointer exception
// See: https://github.com/hashicorp/terraform/issues/37748
func TestCloud_AppName_with_nil(t *testing.T) {
var backend *Cloud = nil
name := backend.AppName()
if name != "HCP Terraform" {
t.Fatalf("expected name to be HCP Terraform, got %q", name)
}
}

Loading…
Cancel
Save