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 Answers
3
votes
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.