Skip to content

azurermSqlFailoverGroup

Create a failover group of databases on a collection of Azure SQL servers.

-> Note: The azurermSqlFailoverGroup resource is deprecated in version 3.0 of the AzureRM provider and will be removed in version 4.0. Please use the azurermMssqlFailoverGroup resource instead.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm.
For a more precise conversion please use the --provider flag in convert.*/
const azurermResourceGroupExample = new azurerm.resourceGroup.ResourceGroup(
  this,
  "example",
  {
    location: "West Europe",
    name: "example-resources",
  }
);
const azurermSqlServerPrimary = new azurerm.sqlServer.SqlServer(
  this,
  "primary",
  {
    administrator_login: "sqladmin",
    administrator_login_password: "pa$$w0rd",
    location: azurermResourceGroupExample.location,
    name: "sql-primary",
    resource_group_name: azurermResourceGroupExample.name,
    version: "12.0",
  }
);
const azurermSqlServerSecondary = new azurerm.sqlServer.SqlServer(
  this,
  "secondary",
  {
    administrator_login: "sqladmin",
    administrator_login_password: "pa$$w0rd",
    location: azurermResourceGroupExample.location,
    name: "sql-secondary",
    resource_group_name: azurermResourceGroupExample.name,
    version: "12.0",
  }
);
const azurermSqlDatabaseDb1 = new azurerm.sqlDatabase.SqlDatabase(this, "db1", {
  location: azurermSqlServerPrimary.location,
  name: "db1",
  resource_group_name: azurermSqlServerPrimary.resourceGroupName,
  server_name: azurermSqlServerPrimary.name,
});
const azurermSqlFailoverGroupExample =
  new azurerm.sqlFailoverGroup.SqlFailoverGroup(this, "example_4", {
    databases: [azurermSqlDatabaseDb1.id],
    name: "example-failover-group",
    partner_servers: [
      {
        id: azurermSqlServerSecondary.id,
      },
    ],
    read_write_endpoint_failover_policy: [
      {
        grace_minutes: 60,
        mode: "Automatic",
      },
    ],
    resource_group_name: azurermSqlServerPrimary.resourceGroupName,
    server_name: azurermSqlServerPrimary.name,
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermSqlFailoverGroupExample.overrideLogicalId("example");

Argument Reference

The following arguments are supported:

  • name - (Required) The name of the failover group. Changing this forces a new resource to be created.

  • resourceGroupName - (Required) The name of the resource group containing the SQL server Changing this forces a new resource to be created.

  • serverName - (Required) The name of the primary SQL server. Changing this forces a new resource to be created.

  • databases - (Optional) A list of database ids to add to the failover group

-> NOTE: The failover group will create a secondary database for each database listed in databases. If the secondary databases need to be managed through Terraform, they should be defined as resources and a dependency added to the failover group to ensure the secondary databases are created first. Please refer to the detailed example which can be found in the /examples/sqlAzure/failoverGroup directory within the GitHub Repository

  • partnerServers - (Required) A list of secondary servers as documented below

  • readWriteEndpointFailoverPolicy - (Required) A read/write policy as documented below

  • readonlyEndpointFailoverPolicy - (Optional) a read-only policy as documented below

  • tags - (Optional) A mapping of tags to assign to the resource.


The partnerServers block supports the following:

  • id - (Required) the SQL server ID

The readWriteEndpointFailoverPolicy block supports the following:

  • mode - (Required) the failover mode. Possible values are manual, automatic

  • graceMinutes - (Optional) Applies only if mode is automatic. The grace period in minutes before failover with data loss is attempted


The readonlyEndpointFailoverPolicy block supports the following:

  • mode - (Required) Failover policy for the read-only endpoint. Possible values are enabled, and disabled

Attributes Reference

The following attributes are exported:

  • id - The failover group ID.
  • location - the location of the failover group.
  • serverName - (Required) the name of the primary SQL Database Server. Changing this forces a new resource to be created.
  • role - local replication role of the failover group instance.
  • databases - (Optional) list of databases in the failover group.
  • partnerServers - (Required) list of partner server information for the failover group.

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

  • create - (Defaults to 30 minutes) Used when creating the SQL Failover Group.
  • update - (Defaults to 30 minutes) Used when updating the SQL Failover Group.
  • read - (Defaults to 5 minutes) Used when retrieving the SQL Failover Group.
  • delete - (Defaults to 30 minutes) Used when deleting the SQL Failover Group.

Import

SQL Failover Groups can be imported using the resourceId, e.g.

terraform import azurerm_sql_failover_group.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myresourcegroup/providers/Microsoft.Sql/servers/myserver/failoverGroups/group1