Create a failover group of databases on a collection of Azure SQL servers.
resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "West Europe"
}
resource "azurerm_sql_server" "primary" {
name = "sql-primary"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
version = "12.0"
administrator_login = "sqladmin"
administrator_login_password = "pa$$w0rd"
}
resource "azurerm_sql_server" "secondary" {
name = "sql-secondary"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
version = "12.0"
administrator_login = "sqladmin"
administrator_login_password = "pa$$w0rd"
}
resource "azurerm_sql_database" "db1" {
name = "db1"
resource_group_name = azurerm_sql_server.primary.resource_group_name
location = azurerm_sql_server.primary.location
server_name = azurerm_sql_server.primary.name
}
resource "azurerm_sql_failover_group" "example" {
name = "example-failover-group"
resource_group_name = azurerm_sql_server.primary.resource_group_name
server_name = azurerm_sql_server.primary.name
databases = [azurerm_sql_database.db1.id]
partner_servers {
id = azurerm_sql_server.secondary.id
}
read_write_endpoint_failover_policy {
mode = "Automatic"
grace_minutes = 60
}
}
The following arguments are supported:
name
- (Required) The name of the failover group. Changing this forces a new resource to be created.
resource_group_name
- (Required) The name of the resource group containing the SQL server Changing this forces a new resource to be created.
server_name
- (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
partner_servers
- (Required) A list of partner_servers
blocks as documented below.
read_write_endpoint_failover_policy
- (Required) A read_write_endpoint_failover_policy
block as documented below.
readonly_endpoint_failover_policy
- (Optional) A readonly_endpoint_failover_policy
block as documented below.
tags
- (Optional) A mapping of tags to assign to the resource.
The partner_servers
block supports the following:
id
- (Required) the SQL server IDThe read_write_endpoint_failover_policy
block supports the following:
mode
- (Required) the failover mode. Possible values are Manual
, Automatic
grace_minutes
- (Optional) Applies only if mode
is Automatic
. The grace period in minutes before failover with data loss is attempted
The readonly_endpoint_failover_policy
block supports the following:
mode
- (Required) Failover policy for the read-only endpoint. Possible values are Enabled
, and Disabled
In addition to the Arguments listed above - the following Attributes are exported:
id
- The failover group ID.location
- the location of the failover group.server_name
- (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.partner_servers
- (Required) list of partner server information for the failover group.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.SQL Failover Groups can be imported using the resource id
, e.g.
terraform import azurerm_sql_failover_group.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myresourcegroup/providers/Microsoft.Sql/servers/myserver/failoverGroups/group1