How do I initiate Azure Site Recovery failover using Terraform?

Glenn Horton 60 Reputation points
2025-02-18T20:57:58.8666667+00:00

I have used Terraform to provision VMs, network and storage as well as set up Azure Site Recovery. Ideally, I could use Terraform to trigger failover also. So far, I've been unable to find any documentation related to triggering failover with Terraform. Is that possible?

Azure Site Recovery
Azure Site Recovery
An Azure native disaster recovery service. Previously known as Microsoft Azure Hyper-V Recovery Manager.
759 questions
{count} votes

Accepted answer
  1. Ashok Gandhi Kotnana 3,535 Reputation points Microsoft Vendor
    2025-02-19T18:11:05.22+00:00

    Hi Glenn Horton,

    Welcome to Microsoft Q&A Forum, thank you for posting your query here!

    You can achieve this by using the below functionality

    Terraform does not have a dedicated resource type like azurerm_site_recovery_failover for initiating a failover in Azure Site Recovery (ASR). However, you can still achieve this functionality within your Terraform workflow by using a null resource combined with an Azure PowerShell script, this will work.

    PowerShell script reference below link:

    https://docs.azure.cn/en-us/site-recovery/azure-to-azure-powershell#fail-over-to-azure

    Terraform Code by using a null resource

    resource "null_resource" "run_powershell_script" {
      provisioner "local-exec" {
        command = "powershell.exe -ExecutionPolicy Bypass -File ./script.ps1"
      }
    }
    

    Feel free to reach out if you have any further questions or need additional information—I’m happy to assist!

    Please provide your valuable comments User's image

    Please do not forget to "Accept the answer” and “upvote it” wherever the information provided helps you, this can be beneficial to other community members.it would be greatly appreciated and helpful to others.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

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