简体   繁体   English

在 Terraform 中销毁一个 EC2 实例?

[英]Destroy an EC2 instance in Terraform?

I'm creating an EC2 instance and loading it up with some "on start" scripts as well as installing desired software.我正在创建一个 EC2 实例并使用一些“启动”脚本加载它并安装所需的软件。 This becomes the base image to be used when spinning up new instances.这成为启动新实例时要使用的基本映像。

Once created, I create an AMI.创建后,我将创建一个 AMI。 At this point, there is no need to keep the EC2 image used to create the AMI.此时,无需保留用于创建 AMI 的 EC2 映像。

So, the sequence is:所以,顺序是:

Create EC2
Install packages
Configure packages
Create AMI
Destroy EC2

How do I tell Terraform to then delete the EC2 in the final step?我如何告诉 Terraform 然后在最后一步删除 EC2?

Have you taken a look at Hashicorp's Packer tool?你看过 Hashicorp 的 Packer 工具吗? It specializes in building AMIs for use in Terraform and could save you a few manual steps here.它专门构建用于 Terraform 的 AMI,可以在此处为您节省一些手动步骤。

In the meantime though, you can issue a terraform destroy -target aws_instance.<NAME> (substitute your Terraformed EC2 instance's name) command to destroy your instance.但与此同时,您可以发出terraform destroy -target aws_instance.<NAME> (替换您的 Terraformed EC2 实例的名称)命令来销毁您的实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM