Also, if you’re using a remote backend, like Scalr or Terraform Cloud, this makes it easier to do the import as you don’t have to specify something like a custom hook or any other workaround to do the import.
Below is a simple example of importing an ec2 instance into state.
I am first going to define the import block with reference to the provider resource (or module) that you want the instance to be imported to:
Now, you’ll need to define the Terraform code that the import block is reference:
Where the full main.tf is:
Now all you have to do is run your standard Terraform commands and the resources will be imported upon an apply:
That’s it! With just a few lines of code we have imported the resources in a safer and more predictable way. Get started using the Import Block feature in Scalr today!