如何从 terraform 获取数据
我需要地形方面的帮助。
我使用 terraform 创建了一个 ec2 实例,创建实例后,我登录到 aws 控制台,并将存储添加到我创建的实例中。
现在我对 terraform 代码进行了一些更改,之后我运行了它显示的 terraform 计划,删除了存储。
如何在不删除存储的情况下运行 terraform apply。
I need a help in terraform.
I have created a ec2 instance using terraform ,after creating the instance I am login to the aws console and added the storage in the instance what I have created the instance.
Now I made some changes in to the terraform code, after that I ran the terraform plan it is showing, the deleting the storage.
How can I run the terraform apply without deleting the storage.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
手动更改 TF 管理的资源是一种很糟糕的做法,因为它会导致
漂移
。请查看 TF 文档如何处理该问题:Its a vary bad practice to manually change resource managed by TF as it results in a
drift
. Please check TF docs how to deal with that:正如另一个答案所述,由于您遇到的原因,手动更改 Terraform 托管资源是不好的做法。
您可以考虑的一种可能性是将您添加的存储置于 Terraform 的管理之下,这是通过 完成的
terraform import
命令。例如,假设您已添加 EBS 卷,则为 EBS 卷声明 Terraform 资源及其与您的实例的附件:
然后使用导入命令导入这些资源,每个资源所需的详细信息各不相同,但可以在每个资源的文档。
As the other answer states, it is bad practice to manually change a Terraform managed resource for the reason you are experiencing.
One possibility that you could look at is bringing the storage that you added under the management of Terraform, this is done by
terraform import
command.An example, assuming you have added an EBS volume, would be to declare a Terraform resource for the EBS volume and it's attachement to your instance:
and then import these using the import commands, the details required for each resource varies but can be found in the documentation for each resource.