How to Sync Terraform State with Existing Azure Infrastructure Using the Terraform Import Command

A detailed guide with two real-life examples.

David Olivas
CodeX

--

Photo by Shawn Ang on Unsplash

If you are reading this post, you probably are in a situation where you have to use Terraform to manage your cloud infrastructure. But there are existing resources, not created using Terraform, that need to be managed by it.

I will show you how to sync your Terraform state with existing resources in Azure specifically. However, the steps to achieve this are virtually the same for other cloud providers.

To sync our Terraform state we’ll be using the terraform import command. This command allows us to bring under Terraform management resources that already exist or were created by other means. There is one important thing to know about the usage of this command:

The current implementation of Terraform import can only import resources into the state. It does not generate configuration. A future version of Terraform will also generate configuration.

Because of this, prior to running terraform import it is necessary to write manually a…

--

--

David Olivas
CodeX
Writer for

Senior DevOps Engineer in Berlin. Cloud Enthusiast.… Taking a break, will post again by 2025.