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

AWS, Azure Cloud and DevOps Coaching Online Classes | Dec 2021 Schedule

Are you in IT? Tired of your work? Are you not able to make any good progress in your career?  Are you not having a job? Looking for a b...