I'm looking to manage my existing Azure environment using Terraform, but I'm not sure about the best method to import my current resources and structure them into modules efficiently. Could anyone share some helpful tips or best practices for this process? Thanks!
5 Answers
Depending on how many resources you have, starting from scratch might be easier. Importing can often lead to challenges with managing hard-coded resource blocks. Consider creating a new main.tf file and using Copilot to set everything up with variables first, and then import the state if needed.
If you're just starting with the import process, you can use a tool called aztfexport, created by the same Microsoft team behind Bicep. It helps streamline the export of your Azure resources into a format Terraform can work with. Just keep in mind that after using it, you'll want to go through and tidy things up—like replacing any hard-coded IDs with resource references and creating modules out of repeated code.
I wouldn't recommend trying to fit everything into modules right off the bat. There may not be much commonality in how these resources are set up. Just import the resources directly to get them under Terraform management, and look into the newer import block method for better organization.
Hey, I can help you out! Just send me a message, and we can go over your setup together.
You can also use the terraform import command to take control of existing resources. Just remember, after importing, you’ll need to run the plan command several times to ensure everything is configured as you expect.
Exactly! It's a great starting point, but don't forget to refine the setup afterwards to make it more manageable.