Plugin panics on terraform destroy after failed terraform apply
arianvp opened this issue ยท 7 comments
Community Note
- Please vote on this issue by adding a ๐ reaction to the original issue to help the community and maintainers prioritize this request.
- Please do not leave +1 or me too comments, they generate extra noise for issue followers and do not help prioritize the request.
- If you are interested in working on this issue or have submitted a pull request, please leave a comment.
Terraform Version
Terraform v1.0.8
on linux_amd64
+ provider registry.terraform.io/equinix/metal v3.2.0
+ provider registry.terraform.io/hashicorp/null v3.1.0
+ provider registry.terraform.io/hashicorp/random v3.1.0
+ provider registry.terraform.io/poseidon/ct v0.6.1
Affected Resource(s)
- metal_device
Terraform Configuration Files
https://github.com/arianvp/packet-ipv6-kubernetes/blob/metal/provision.tf
Debug Output
https://gist.github.com/arianvp/6c670ca5be1f4541c1c12d9b67942409
Panic Output
https://gist.github.com/arianvp/6c670ca5be1f4541c1c12d9b67942409
Expected Behavior
Resources get destroyed
Actual Behavior
Terraform panics
Steps to Reproduce
terraform apply
- get a:
metal_device.worker[1]: Creating...
metal_device.worker[0]: Creating...
โท
โ Error: Sorry! You have reached the maximum number of t1.small.x86 devices for this project (5). The Equinix Metal team has been notified of this and will be in touch shortly. If this is urgent, please email support@equinixmetal.com to request additional deployment capacity.
โ
โ
โ with metal_device.worker[0],
โ on provision.tf line 111, in resource "metal_device" "worker":
โ 111: resource "metal_device" "worker" {
โ
โต
โท
โ Error: Sorry! You have reached the maximum number of t1.small.x86 devices for this project (5). The Equinix Metal team has been notified of this and will be in touch shortly. If this is urgent, please email support@equinixmetal.com to request additional deployment capacity.
โ
โ
โ with metal_device.worker[1],
โ on provision.tf line 111, in resource "metal_device" "worker":
โ 111: resource "metal_device" "worker" {
- Ran out of capacity of
t1.small
instances - Decided to run
terraform destroy
to destroy the entire project - Terraform panics
References
- #0000
Hey @arianvp thanks for reporting and for the logs, I'll take a look.
Please remove X-Auth-Token lines from the 2nd gist, it's your EM token.
@displague The issue template says
Note: the debug log will contain your API key, please review the log and delete sensitive secrets before submitting.
Maybe we can change it to:
Note: the debug log will contain your API key, please search the log for "X-Auth-Token" (HTTP request header holding the API token) and remove it.
The nil deref comes from a very common cast from the Read method of device resource. The meta interface is passed to every provider method. It's quite strange, I've never seen it before. I also don't think that any provider checks the meta interface for nil.
func resourceMetalDeviceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*packngo.Client) // <<<<<<<<<<<<<<<<< HERE
@arianvp reading code and issues didn't help, so I will try to hit the limit for a project.
@arianvp @displague I spent some time debugging, and I got similar panic when getting HTTP error with empty error slice, like this:
---[ REQUEST ]---------------------------------------
DELETE /metal/v1/projects/0a286170-17fc-43a0-9b68-4ddfb41c4f4c HTTP/1.1
Host: api.equinix.com
User-Agent: HashiCorp Terraform/0.11+compatible (+https://www.terraform.io) Terraform Plugin SDK/2.7.0 terraform-provider-metal/dev packngo/v0.19.1
Connection: close
Accept: application/json
Content-Type: application/json
X-Consumer-Token: aZ9GmqHTPtxevvFq9SK3Pi2yr9YCbRzduCSXF2SNem5sjB91mDq7Th3ZwTtRqMWZ
Accept-Encoding: gzip
-----------------------------------------------------: timestamp=2021-10-18T18:19:22.374+0300
2021-10-18T18:19:23.206+0300 [INFO] provider.terraform-provider-metal: 2021/10/18 18:19:23 [DEBUG] Equinix Metal API Response Details:
---[ RESPONSE ]--------------------------------------
HTTP/1.1 422 Unprocessable Entity
Connection: close
Content-Length: 13
Cache-Control: no-cache
Content-Type: application/json; charset=utf-8
Date: Mon, 18 Oct 2021 15:19:23 GMT
Strict-Transport-Security: max-age=15724800; includeSubDomains
X-Request-Id: 6e1b741e5249ce3f03812ebad8fd1770
{
"errors": []
}
Terraform SDK then soemhow receives an empty error, or even some struct that is not the error actually.
The error handling is really hard to debug at this point, but I'll try to fix it and submit a PR with a fix. Once that's in, we will re-release and you can try again.