Skip to content

Using Terraformer tool to copy complete existing infrastructure of an Azure account to another account

Terraformer is a tool which generates Terraform files (`.tf` and `.tfstate`) from existing infrastructure. You can use Terraformer to generate Terraform files for your Azure resources and then apply the generated files in another Azure account, recreating your whole infrastructure there as well.

Here’s a step-by-step guide on how to achieve this using Terraformer:

1. Install Terraformer: Follow the official installation guide to install Terraformer.

2. Authenticate to your Azure account: Ensure you’re authenticated to your source Azure account using the Azure CLI with `az login`.

3. Export your Azure resources with Terraformer:

terraformer import azure --resources="*" --regions="eastus,westus" --subscription-id="<SourceSubscriptionId>"

This command will import all resources in the specified regions (East US and West US in this example) within your source Azure account. Replace `<SourceSubscriptionId>` with your actual source subscription ID.

4. Change the Azure provider block in the generated `provider.tf` file to use the destination Azure account:

provider "azurerm" {
features {}
subscription_id = "<DestinationSubscriptionId>"
client_id = "<DestinationClientId>"
client_secret = "<DestinationClientSecret>"
tenant_id = "<DestinationTenantId>"
}

Replace the placeholder values with the destination Azure account’s Subscription ID, Client ID, Client Secret, and Tenant ID.

5. Run `terraform init` to initialize the Terraform workspace.

6. Review the generated Terraform files and make any necessary changes, such as updating resource names or configurations.

7. Deploy the resources to the destination Azure account with `terraform apply`.

Remember to follow best practices for handling sensitive data like the client secret in your Terraform files. You may use environment variables or Terraform `variable` blocks to keep sensitive information out of your files. Also, keep in mind that this process may not work seamlessly for all resources, and you may need to make adjustments depending on your specific use case.

Published inTutorials

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

WordPress Appliance - Powered by TurnKey Linux