使用"-replace"参数应用地形不会强制替换对象



在我的地形定义中,我定义了EC2:

resource "aws_instance" "eventhub_instance" {
ami                         = var.eh_instance_ami
instance_type               = var.eh_instance_type
count                       = 2
......

这些实例已经启动并运行。现在,我想运行terraform apply并强制重新创建那些实例。我的理解是,我可以使用-replace=ADDRESS来强制,所以我尝试:

terraform apply -auto-approve -var-file=vars/dev.terraform.tfvars -replace=aws_instance.eventhub_instance[0] -replace=aws_instance.eventhub_instance[1]

Terraform运行并结束

No changes. Your infrastructure matches the configuration.

为什么它不替换/重新创建EC2实例?

-replace=参数在planapply期间返回No changes时,则引用资源的命名空间可能不正确。您可以使用已弃用的terraform taint命令进行双重检查。

模块内资源的命名法要求命名空间前缀module.<declared module name>。在声明的模块名称为all的情况下,则为:

terraform apply -auto-approve -var-file=vars/dev.terraform.tfvars -replace=module.all.aws_instance.eventhub_instance[0] -replace=module.all.aws_instance.eventhub_instance[1]

最新更新