Skip to content

azurermMssqlFailoverGroup

Manages a Microsoft Azure SQL Failover Group.

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.*/
new azurerm.provider.AzurermProvider(this, "azurerm", {
  features: [{}],
});
const azurermResourceGroupExample = new azurerm.resourceGroup.ResourceGroup(
  this,
  "example",
  {
    location: "West Europe",
    name: "database-rg",
  }
);
const azurermMssqlServerPrimary = new azurerm.mssqlServer.MssqlServer(
  this,
  "primary",
  {
    administrator_login: "missadministrator",
    administrator_login_password: "thisIsKat11",
    location: azurermResourceGroupExample.location,
    name: "mssqlserver-primary",
    resource_group_name: azurermResourceGroupExample.name,
    version: "12.0",
  }
);
const azurermMssqlServerSecondary = new azurerm.mssqlServer.MssqlServer(
  this,
  "secondary",
  {
    administrator_login: "missadministrator",
    administrator_login_password: "thisIsKat12",
    location: azurermResourceGroupExample.location,
    name: "mssqlserver-secondary",
    resource_group_name: azurermResourceGroupExample.name,
    version: "12.0",
  }
);
const azurermMssqlDatabaseExample = new azurerm.mssqlDatabase.MssqlDatabase(
  this,
  "example_4",
  {
    collation: "SQL_Latin1_General_CP1_CI_AS",
    max_size_gb: "200",
    name: "exampledb",
    server_id: azurermMssqlServerPrimary.id,
    sku_name: "S1",
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermMssqlDatabaseExample.overrideLogicalId("example");
const azurermMssqlFailoverGroupExample =
  new azurerm.mssqlFailoverGroup.MssqlFailoverGroup(this, "example_5", {
    databases: [azurermMssqlDatabaseExample.id],
    name: "example",
    partner_server: [
      {
        id: azurermMssqlServerSecondary.id,
      },
    ],
    read_write_endpoint_failover_policy: [
      {
        grace_minutes: 80,
        mode: "Automatic",
      },
    ],
    server_id: azurermMssqlServerPrimary.id,
    tags: {
      database: "example",
      environment: "prod",
    },
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermMssqlFailoverGroupExample.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.

  • serverId - (Required) The ID of the primary SQL Server on which to create the failover group. Changing this forces a new resource to be created.

  • partnerServer - (Required) A partnerServer block as defined below.

  • databases - (Optional) A set of database names to include in the failover group.

  • readonlyEndpointFailoverPolicyEnabled - (Optional) Whether failover is enabled for the readonly endpoint. Defaults to false.

  • readWriteEndpointFailoverPolicy - (Required) A readWriteEndpointFailoverPolicy block as defined below.

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


A partnerServer block supports the following:

  • id - (Required) The ID of a partner SQL server to include in the failover group.

The readWriteEndpointFailoverPolicy block supports the following:

  • mode - (Required) The failover policy of the read-write endpoint for the failover group. Possible values are automatic or manual.

  • graceMinutes - (Optional) The grace period in minutes, before failover with data loss is attempted for the read-write endpoint. Required when mode is automatic.

Attributes Reference

The following attributes are exported:

  • id - The ID of the Failover Group.

  • partnerServer - A partnerServer block as defined below.


A partnerServer block exports the following:

  • location - The location of the partner server.

  • role - The replication role of the partner server. Possible values include primary or secondary.

Timeouts

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

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

Import

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

terraform import azurerm_mssql_failover_group.example /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Sql/servers/server1/failoverGroups/failoverGroup1