我不小心创建了一个 Terraform 状态资源aws_security_group.db_security_group
。它是从重命名资源的中止尝试创建的。但是,在我的 HCL 文件本身中,资源定义是
resource "aws_security_group" "sandbox_db_security_group" {
name = "${var.sg_name}"
vpc_id = "${var.sg_vpc_id}"
}
我想从 Terraform 管理中删除此状态。所以首先,我列出了我的状态:
[terragrunt] 2019/12/02 09:10:12 Running command: terraform state list
aws_security_group.db_security_group
aws_security_group.sandbox_db_security_group
然后我删除状态:
[terragrunt] 2019/12/02 09:13:26 Running command: terraform state rm aws_security_group.db_security_group
Acquiring state lock. This may take a few moments...
1 items removed.
Item removal successful.
Releasing state lock. This may take a few moments...
但是,如果我随后运行相同的状态列表命令,我会看到我的资源仍然存在:
[terragrunt] 2019/12/02 09:14:52 Running command: terraform state list
aws_security_group.db_security_group
aws_security_group.sandbox_db_security_group
当我显示资源时,什么也没有出现:
[terragrunt] 2019/12/02 09:17:34 Running command: terraform state show aws_security_group.db_security_group
**NO OUTPUT**
当我显示时aws_security_group.sandbox_db_security_group
,我确实得到了预期的安全组资源信息。
更令人担忧的是,当我运行时terragrunt plan
,我会感到恐慌:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x1813b38]
goroutine 702 [running]:
github.com/hashicorp/terraform/terraform.(*NodeRefreshableManagedResourceInstance).evalTreeManagedResourceNoState(0xc000328308, 0x30, 0x2255780)
/private/tmp/terraform@0.11-20190523-67936-10xg42a/terraform-0.11.14/src/github.com/hashicorp/terraform/terraform/node_resource_refresh.go:238 +0x328
github.com/hashicorp/terraform/terraform.(*NodeRefreshableManagedResourceInstance).EvalTree(0xc000328308, 0x234b640, 0xc000328308)
/private/tmp/terraform@0.11-20190523-67936-10xg42a/terraform-0.11.14/src/github.com/hashicorp/terraform/terraform/node_resource_refresh.go:98 +0x6e
github.com/hashicorp/terraform/terraform.(*Graph).walk.func1(0x234b640, 0xc000328308, 0x0, 0x0)
/private/tmp/terraform@0.11-20190523-67936-10xg42a/terraform-0.11.14/src/github.com/hashicorp/terraform/terraform/graph.go:113 +0x94d
github.com/hashicorp/terraform/dag.(*Walker).walkVertex(0xc000369b90, 0x234b640, 0xc000328308, 0xc0002e2240)
/private/tmp/terraform@0.11-20190523-67936-10xg42a/terraform-0.11.14/src/github.com/hashicorp/terraform/dag/walk.go:387 +0x33b
created by github.com/hashicorp/terraform/dag.(*Walker).Update
/private/tmp/terraform@0.11-20190523-67936-10xg42a/terraform-0.11.14/src/github.com/hashicorp/terraform/dag/walk.go:310 +0xa4f
!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!
我怀疑这是这个资源的结果,它实际上并不存在,但在 Terraform 的 DAG 中仍然有一些内存引用。无论如何,我该如何真正删除这个该死的资源?