我不小心创建了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中仍具有一些内存引用。无论如何,我该如何删除该织补资源?
答案 0 :(得分:1)
我将删除所有临时的Terraform / terragrunt下载, 手动检查状态(您可能将其存储在s3上), 如有必要,在s3上手动删除/编辑(需要dynamodb条目编辑), 重新运行terragrunt init,然后进行计划。