amazon-web-services - Terraform - AWS - 如何防止 EBS 卷被删除?

标签 amazon-web-services volume terraform terminate amazon-ebs

我是 Terraform 的新手,所以我希望问题是我做错了什么。

我有一些实例需要附加单独的 EBS 卷。这些被定义为三个独立的 Terraform 资源:

aws_instance
aws_ebs_volume
aws_volume_attachment

当实例启动时,在 AWS 控制台中,卷表示它们具有“终止时删除”保护,但 Terraform 仍然会销毁它们:

aws ebs volume screenshot

如果您在 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/

相关文章:

azure - 使用 Terraform 增加 AKS 的 default_node_pool 中的 max_pod 数量时,必须重新创建集群本身

terraform - 如何使用 Terraform 缓存下载的 ISO?

terraform-ecs。已注册的容器实例显示 0

python-3.x - 无法删除安全组: An error occurred (DependencyViolation) when calling the DeleteSecurityGroup operation

javascript - 如何从客户端向树莓派发送数据?

java - 如何使用aws java sdk将文件从S3存储桶从一个区域复制到另一个区域?

android - 多 Activity 应用程序中的setVolumeControlStream()

python - AWS Lambda : OpenBLAS WARNING - could not determine the L2 cache size on this system, 假设为 256k - 使用 Google 自定义搜索 API 时

c++ - 如何使用 C++ 查找 WAV 文件的最高音量级别

docker - 将主机目录绑定(bind)挂载到正在运行的 docker 容器的卷中