Hi all,
I wanted to get some advice from the community.
I’ve recently been tasked with bringing our existing Azure estate under Terraform management. Historically, most of our Azure resources have been deployed manually through the Azure portal (click-ops).
I’ve been using the Azure CLI and aztfexport within VS Code to export our existing resource groups into Terraform, using the --hcl-only parameter.
We have 25+ resource groups containing a mixture of different resource types, so the exports have resulted in a significant amount of Terraform code.
I’m now looking for advice on the best strategy for refactoring this into a more manageable structure. Ideally, I’d like to separate resources into logical .tf files, for example:
compute.tfnetworking.tfstorage.tfrecovery.tfmonitoring.tf
Once the code has been cleaned up and structured, my intention is to import the existing Azure resources into Terraform state and get to the point where terraform plan shows no changes before making any further changes through Terraform.
Has anyone gone through a similar brownfield Terraform adoption? I’d be interested to hear how you approached the refactoring and import process, particularly when dealing with a large number of existing resource groups and resources.
I’ve also had the suggestion of using Copilot to assist with some of the refactoring work. We have Microsoft 365 Copilot licensing as part of our E5 environment, however, I’m currently a little cautious about providing the full Terraform codebase directly to Copilot due to the amount of infrastructure and configuration information contained within it.
Has anyone used Copilot for this type of Terraform refactoring at scale? If so, I’d be interested to hear how you approached it