如代码和 plan 输出所示,只是把代码中的资源名从 aws_instance.web 改成了 aws_instance.app,terraform plan 就要删除并重建现有的 EC2 实例。希望保留实例本身,只把状态中的名称对应到新地址。不在代码中添加 moved 块,只用 CLI 操作完成。应执行哪条命令?
图
# Before
resource "aws_instance" "web" {
ami = "ami-0abc1234def567890"
instance_type = "t3.micro"
}
# After (only the resource name was changed)
resource "aws_instance" "app" {
ami = "ami-0abc1234def567890"
instance_type = "t3.micro"
}
$ terraform plan
...
Plan: 1 to add, 0 to change, 1 to destroy.