Walk me through how you would refactor a legacy, manually configured infrastructure into a fully automated Terraform deployment.