Skip to content

azurermMssqlManagedInstanceFailoverGroup

Manages an Azure SQL Managed Instance Failover Group.

Example Usage

-> Note: For a more complete example, see the /examples/sqlAzure/managedInstanceFailoverGroup directory within the GitHub Repository.

/*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 azurermRouteTableExample = new azurerm.routeTable.RouteTable(
  this,
  "example_1",
  {
    location: azurermResourceGroupExample.location,
    name: "example",
    resource_group_name: azurermResourceGroupExample.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.*/
azurermRouteTableExample.overrideLogicalId("example");
const azurermVirtualNetworkExample = new azurerm.virtualNetwork.VirtualNetwork(
  this,
  "example_2",
  {
    address_space: ["10.0.0.0/16"],
    location: azurermResourceGroupExample.location,
    name: "example",
    resource_group_name: azurermResourceGroupExample.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.*/
azurermVirtualNetworkExample.overrideLogicalId("example");
const azurermNetworkSecurityGroupExample =
  new azurerm.networkSecurityGroup.NetworkSecurityGroup(this, "example_3", {
    location: azurermResourceGroupExample.location,
    name: "example",
    resource_group_name: azurermResourceGroupExample.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.*/
azurermNetworkSecurityGroupExample.overrideLogicalId("example");
const azurermSubnetExample = new azurerm.subnet.Subnet(this, "example_4", {
  address_prefixes: ["10.0.2.0/24"],
  name: "example",
  resource_group_name: azurermResourceGroupExample.name,
  virtual_network_name: azurermVirtualNetworkExample.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.*/
azurermSubnetExample.overrideLogicalId("example");
const azurermSubnetNetworkSecurityGroupAssociationExample =
  new azurerm.subnetNetworkSecurityGroupAssociation.SubnetNetworkSecurityGroupAssociation(
    this,
    "example_5",
    {
      network_security_group_id: azurermNetworkSecurityGroupExample.id,
      subnet_id: azurermSubnetExample.id,
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermSubnetNetworkSecurityGroupAssociationExample.overrideLogicalId(
  "example"
);
const azurermSubnetRouteTableAssociationExample =
  new azurerm.subnetRouteTableAssociation.SubnetRouteTableAssociation(
    this,
    "example_6",
    {
      route_table_id: azurermRouteTableExample.id,
      subnet_id: azurermSubnetExample.id,
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermSubnetRouteTableAssociationExample.overrideLogicalId("example");
const azurermMssqlManagedInstancePrimary =
  new azurerm.mssqlManagedInstance.MssqlManagedInstance(this, "primary", {
    administrator_login: "mradministrator",
    administrator_login_password: "thisIsDog11",
    depends_on: [
      `\${${azurermSubnetNetworkSecurityGroupAssociationExample.fqn}}`,
      `\${${azurermSubnetRouteTableAssociationExample.fqn}}`,
    ],
    license_type: "BasePrice",
    location: azurermResourceGroupExample.location,
    name: "example-primary",
    resource_group_name: azurermResourceGroupExample.name,
    sku_name: "GP_Gen5",
    storage_size_in_gb: 32,
    subnet_id: azurermSubnetExample.id,
    tags: {
      environment: "prod",
    },
    vcores: 4,
  });
const azurermMssqlManagedInstanceSecondary =
  new azurerm.mssqlManagedInstance.MssqlManagedInstance(this, "secondary", {
    administrator_login: "mradministrator",
    administrator_login_password: "thisIsDog11",
    depends_on: [
      `\${${azurermSubnetNetworkSecurityGroupAssociationExample.fqn}}`,
      `\${${azurermSubnetRouteTableAssociationExample.fqn}}`,
    ],
    license_type: "BasePrice",
    location: azurermResourceGroupExample.location,
    name: "example-secondary",
    resource_group_name: azurermResourceGroupExample.name,
    sku_name: "GP_Gen5",
    storage_size_in_gb: 32,
    subnet_id: azurermSubnetExample.id,
    tags: {
      environment: "prod",
    },
    vcores: 4,
  });
const azurermMssqlManagedInstanceFailoverGroupExample =
  new azurerm.mssqlManagedInstanceFailoverGroup.MssqlManagedInstanceFailoverGroup(
    this,
    "example_9",
    {
      location: azurermMssqlManagedInstancePrimary.location,
      managed_instance_id: azurermMssqlManagedInstancePrimary.id,
      name: "example-failover-group",
      partner_managed_instance_id: azurermMssqlManagedInstanceSecondary.id,
      read_write_endpoint_failover_policy: [
        {
          grace_minutes: 60,
          mode: "Automatic",
        },
      ],
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermMssqlManagedInstanceFailoverGroupExample.overrideLogicalId("example");

Arguments Reference

The following arguments are supported:

  • name - (Required) The name which should be used for this Managed Instance Failover Group. Changing this forces a new resource to be created.

  • location - (Required) The Azure Region where the Managed Instance Failover Group should exist. Changing this forces a new resource to be created.

  • managedInstanceId - (Required) The ID of the Azure SQL Managed Instance which will be replicated using a Managed Instance Failover Group. Changing this forces a new resource to be created.

  • partnerManagedInstanceId - (Required) The ID of the Azure SQL Managed Instance which will be replicated to. Changing this forces a new resource to be created.

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

  • readonlyEndpointFailoverPolicyEnabled - (Optional) Failover policy for the read-only endpoint. Defaults to true.


A readWriteEndpointFailoverPolicy block supports the following:

  • mode - (Required) The failover mode. Possible values are automatic or manual.

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

Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:

  • id - The ID of the Managed Instance Failover Group.

  • partnerRegion - A partnerRegion block as defined below.

  • role - The local replication role of the Managed Instance Failover Group.


A partnerRegion block exports the following:

  • location - The Azure Region where the Managed Instance Failover Group partner exists.

  • role - The partner replication role of the Managed Instance Failover Group.

Timeouts

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

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

Import

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

terraform import azurerm_mssql_managed_instance_failover_group.example /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Sql/locations/Location/instanceFailoverGroups/failoverGroup1