我是 Terraform 的新手,所以我希望问题是我做错了什么。
我有一些实例需要附加单独的 EBS 卷。这些被定义为三个独立的 Terraform 资源:
aws_instance
aws_ebs_volume
aws_volume_attachment
当实例启动时,在 AWS 控制台中,卷表示它们具有“终止时删除”保护,但 Terraform 仍然会销毁它们:
如果您在 aws_instance 资源定义中使用“block_device”映射,您可以防止它被终止:
https://www.terraform.io/docs/providers/aws/r/instance.html#delete_on_termination-1
但是这个选项没有出现在 ebs_volume 资源中:
https://www.terraform.io/docs/providers/aws/r/ebs_volume.html
如何阻止 Terraform 删除我的 EBS 卷?
我试过这样做,但它只是阻止了 terraform 销毁作业的运行:
lifecycle = {
prevent_destroy = true
}
谢谢
最佳答案
它完全按照文档中的说明进行操作,因此 Terraform 不允许 terraform destroy
,如果您需要它来执行此操作,那么我建议将这些资源移动到它们自己的 terraform 目录中来自其他资源。
prevent_destroy (bool) - This flag provides extra protection against the destruction of a given resource. When this is set to true, any plan that includes a destroy of this resource will return an error message.
关于amazon-web-services - Terraform - AWS - 如何防止 EBS 卷被删除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47432238/