Monday, June 7, 2021

How do you import existing resources into Terraform from AWS? | Terraform Import command

Let's say that you have created EC2 instances manually. If you like to attach your EC2 instance to Terraform you can use import command.

 The terraform import command is used to import existing infrastructure. The command currently can only import one resource at a time. This means you can't yet point Terraform import to an entire collection of resources such as an AWS VPC and import all of it. 

Watch the steps in YouTube Video:


To import a resource, create a tf file first write a resource block for it in your configuration, establishing the name by which it will be known to Terraform:


sudo vi myec2.tf

resource "aws_instance" "myinstance" {

  # ...instance configuration...leave this as it is

}


terraform import can be run to attach an existing EC2 instance to this resource configuration:


pick up the instance ID of EC2 instance you want to import and execute the below command:
terraform import aws_instance.myinstance i-abcd1234


No comments:

Post a Comment

DevOps Coaching Program Model Information | AWS Cloud Azure Cloud DevOps Coaching Program Model Information

Thanks for showing interest in learning DevOps. Believe it or not, anyone can become a successful DevOps engineer after finishing the excit...