hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.45k stars 9.51k forks source link

Terraform crashed #32872

Open kural82 opened 1 year ago

kural82 commented 1 year ago

Is there an existing issue for this?

Community Note

Terraform Version

Terraform v1.3.9

AzureRM Provider Version

v3.46.0

Affected Resource(s)/Data Source(s)

azurerm storage account

Terraform Configuration Files

resource "azurerm_storage_container" "example" {
  name                  = "content"
  storage_account_name  = "storageaccountnametest19"
  container_access_type = "private"
}

terraform {
  backend "azurerm" {
    resource_group_name  = "example<>resources"
    storage_account_name = "storageaccountnametest19"
    container_name       = "content"
    key                  = "terraform.tfstate"
  }
}

Debug Output/Panic Output

Error releasing the state lock
│ 
│ Error message: failed to retrieve lock info: blobs.Client#GetProperties: Failure sending request: StatusCode=0 -- Original Error: Head
│ "https://storageaccountnametest19.blob.core.windows.net/content/terraform.tfstate": dial tcp: lookup storageaccountnametest19.blob.core.windows.net: no such host
│ 
│ Terraform acquires a lock when accessing your state to prevent others
│ running Terraform to potentially modify the state at the same time. An
│ error occurred while releasing this lock. This could mean that the lock
│ did or did not release properly. If the lock didn't release properly,
│ Terraform may not be able to run future commands since it'll appear as if
│ the lock is held.
│ 
│ In this scenario, please call the "force-unlock" command to unlock the
│ state manually. This is a very dangerous operation since if it is done
│ erroneously it could result in two people modifying state at the same time.
│ Only call this command if you're certain that the unlock above failed and
│ that no one else is holding a lock.
╵

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Terraform crashed! This is always indicative of a bug within Terraform.
Please report the crash with Terraform[1] so that we can fix this.

When reporting bugs, please include your terraform version, the stack trace
shown below, and any additional information which may help replicate the issue.

[1]: https://github.com/hashicorp/terraform/issues

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

runtime error: invalid memory address or nil pointer dereference
goroutine 14 [running]:
runtime/debug.Stack()
        /usr/local/go/src/runtime/debug/stack.go:24 +0x65
runtime/debug.PrintStack()
        /usr/local/go/src/runtime/debug/stack.go:16 +0x19
github.com/hashicorp/terraform/internal/logging.PanicHandler()
        /Users/distiller/project/project/internal/logging/panic.go:55 +0x153
panic({0x2e445e0, 0x4a4c010})
        /usr/local/go/src/runtime/panic.go:884 +0x212
github.com/hashicorp/terraform/internal/backend/remote-state/azure.(*RemoteClient).Put(0xc0002242d0, {0xc00064f980, 0x1859, 0x1980})
        /Users/distiller/project/project/internal/backend/remote-state/azure/client.go:88 +0x583
github.com/hashicorp/terraform/internal/states/remote.(*State).PersistState(0xc000a09260, 0x3072d00?)
        /Users/distiller/project/project/internal/states/remote/state.go:202 +0x5c5
github.com/hashicorp/terraform/internal/states/statemgr.WriteAndPersist({0x2dd6d4c0, 0xc000a09260}, 0x2?, 0xc00034de90?)
        /Users/distiller/project/project/internal/states/statemgr/helper.go:53 +0x53
github.com/hashicorp/terraform/internal/backend/local.(*Local).opApply(0x0?, {0x3777278, 0xc000725940}, {0x3777278, 0xc000725980}, 0xc000217e60, 0xc000725900)
        /Users/distiller/project/project/internal/backend/local/backend_apply.go:201 +0x1075
github.com/hashicorp/terraform/internal/backend/local.(*Local).Operation.func1()
        /Users/distiller/project/project/internal/backend/local/backend.go:323 +0xc3
created by github.com/hashicorp/terraform/internal/backend/local.(*Local).Operation
        /Users/distiller/project/project/internal/backend/local/backend.go:316 +0x44a

Expected Behaviour

Just deleting the resources after running terraform destroy

Actual Behaviour

terraform crashed

Steps to Reproduce

No response

Important Factoids

No response

References

No response

sebader commented 1 year ago

The storage account that you want to use for your backend needs to exist before you run terraform. TF itself cannot create that storage account

storageaccountnametest19.blob.core.windows.net: no such host

lonegunmanb commented 1 year ago

Hi @kural82, thanks for reporting this crash, according to the dump stack:

github.com/hashicorp/terraform/internal/backend/remote-state/azure.(*RemoteClient).Put(0xc0002242d0, {0xc00064f980, 0x1859, 0x1980}) /Users/distiller/project/project/internal/backend/remote-state/azure/client.go:88 +0x583

The code that crashed Terraform is in Terraform core

I'd like to submit a pr to fix this issue, would you please copy this issue to Terraform repo and close this one so I can reference your pr at Terraform repo? Thanks!


I've opened a pr to fix this issue, please ping me there once you've opened a new issue there, thanks @kural82!