Junior — Middle
How can you introduce an existing resource created outside the infrastructure into Terraform?
sobes.tech AI
Answer from AI
To import a resource into Terraform that was created outside of Terraform (for example, manually through the cloud provider's console), the terraform import command is used. It links an existing external resource with the resource described in the Terraform configuration.
Steps:
- Describe the resource in the Terraform configuration file with the required type and name.
- Execute the import command, specifying the identifier of the existing resource and the resource name in Terraform.
Example:
terraform import aws_instance.my_instance i-1234567890abcdef0
After importing, Terraform will start managing this resource, but it is important to verify and update the configuration to match the current state of the resource.