Share via

How to automate Azure site recovery using terraform with python /powershell script

Satish B 190 Reputation points
2026-05-23T05:54:18.34+00:00

Hi Team,

Iam new this earlier i have worked using arm templates. How to automate Azure site recovery using terraform with python /powershell script

Azure Site Recovery
Azure Site Recovery

An Azure native disaster recovery service. Previously known as Microsoft Azure Hyper-V Recovery Manager.

0 comments No comments

Answer accepted by question author

Marcin Policht 91,150 Reputation points MVP Volunteer Moderator
2026-05-23T11:04:28.6666667+00:00

Refer to https://medium.com/@javedkumail/automating-azure-disaster-recovery-with-terraform-and-azure-devops-af94cb3e3fcc

Overview of the Key Components

  • Terraform - Infrastructure as Code: Terraform allows us to define our cloud infrastructure in code, making our deployments reproducible, version-controlled, and easy to modify. - State Management: Using a storage account for our Terraform state ensures consistency and coordination across multiple deployments.
  • Azure DevOps - CI/CD Pipelines: Azure DevOps Pipelines automate the build, test, and deployment processes. They continuously integrate changes from your source code repository and deploy our infrastructure updates. - Version Control: Azure Repos offer a robust version control system, making collaboration and tracking changes to our Terraform files straightforward. - Managed Identity for Service Connection: Instead of using a service principle with hard-coded credentials, a Managed identity is leveraged to securely authenticate the pipeline with our Azure subscription.
  • Azure Site Recovery(ASR) - Disaster Recovery Orchestration: ASR provides automated replication of our critical workloads from the primary Azure region to secondary region. - Failover/Failback Operation: ASR manages the failover to the DR site during outages and allows for failback once the primary site is operational again.

If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

hth

Marcin

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. kagiyama yutaka 3,510 Reputation points
    2026-05-23T12:44:25.26+00:00

    I think you define the ASR setup in Terraform with the AzureRM provider, then just run terraform init / plan / apply from a tiny python or pwsh script that shells out to the Terraform CLI. If you want modules, the Azure Verified Module for the Recovery Services Vault works together with those ASR resources.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.