我可以使用Terraform更新现有的EC2实例吗 [英] Can i update an existing ec2 instance with terraform

查看:211
本文介绍了我可以使用Terraform更新现有的EC2实例吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以编辑现有资源示例:具有terraform模板的ec2实例。
例:我有一个使用AWS控制台创建的ec2实例,我可以使用terraform模板中的实例ID添加该ec2实例来添加新的安全组。我知道这无法通过云形成来完成。目前,我可以使用Ansible做到这一点,但我看不到使用terraform或cloudformation做到这一点的方法。

解决方案

是的,您可以!但是,您随后必须使用Terraform管理实例。没有办法只是对正在运行的实例执行此操作并每天称呼它-这就是各种SDK和AWS CLI的用途。



您要做什么寻找的是地形导入-要使用此功能,您需要定义Terraform配置中的资源,按所需方式映射所有内容,然后导入该资源。



由于您使用的是 EC2实例,它将类似于:

 地形导入aws_instance.web i-12345678 

一旦完成;如果您执行了地形计划,则可以看到忘记为此设置添加到配置中的属性-将其添加到其中,然后就可以开始管理该资源了。 / p>

Is it possible to edit an existing resource example: an ec2 instance with the terraform template. Ex: I have a ec2 instance created with aws console, can i add that ec2 instance to add a new security group using the instance id in terraform template. I know this can't be done with cloud formation. Currently I can do this with Ansible, but i don't see a way to do it with terraform or cloudformation

解决方案

Yes, you can! However you have to then manage the instance with Terraform. There's no way to just "Do this to a running instance" and call it a day - that's what the various SDKs are for and the AWS CLI.

What you're looking for is terraform import - to use this, you'll want to define a resource in your Terraform configuration, map up everything how you want, and then import that resource.

Since you're using an EC2 instance, it will look something like:

terraform import aws_instance.web i-12345678

Once this is done; if you do a terraform plan you can see what attributes you forgot to add to your configuration you setup for this - add those in, and then you can start managing this resource.

这篇关于我可以使用Terraform更新现有的EC2实例吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆