Importing and exporting Terraform resources
Note
The code for this section is under the chap10/import-export
directory in the GitHub repository of this book. We recommend that you create a new project for this exercise.
In Chapter 2, Exploring Terraform, we discussed the concept of configuration drift: changes made outside of Terraform. Once we start using Terraform, we should not use the web console or gcloud
to manage cloud inafrastructure resources. However, what do we do when there is an existing cloud resource we want to manage using Terraform?
Terraform provides the capability to import existing infrastructure resources. What this means is that we can bring existing resources into the realm of Terraform by using the command terraform import
(learn more about it from here – https://developer.hashicorp.com/terraform/cli/import). However, this is often easier said than done. We should resort to importing existing resources only as a last option because bringing an...