Can i update an existing ec2 instance with terraform

不问归期 提交于 2019-12-24 09:07:47

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/47720442/can-i-update-an-existing-ec2-instance-with-terraform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!