azurermSqlDatabase
Allows you to manage an Azure SQL Database
-> Note: The azurermSqlDatabase resource is deprecated in version 3.0 of the AzureRM provider and will be removed in version 4.0. Please use the azurermMssqlDatabase 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 azurermSqlServerExample = new azurerm.sqlServer.SqlServer(
this,
"example_1",
{
administrator_login: "4dm1n157r470r",
administrator_login_password: "4-v3ry-53cr37-p455w0rd",
location: azurermResourceGroupExample.location,
name: "myexamplesqlserver",
resource_group_name: azurermResourceGroupExample.name,
tags: {
environment: "production",
},
version: "12.0",
}
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermSqlServerExample.overrideLogicalId("example");
const azurermStorageAccountExample = new azurerm.storageAccount.StorageAccount(
this,
"example_2",
{
account_replication_type: "LRS",
account_tier: "Standard",
location: azurermResourceGroupExample.location,
name: "examplesa",
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.*/
azurermStorageAccountExample.overrideLogicalId("example");
const azurermSqlDatabaseExample = new azurerm.sqlDatabase.SqlDatabase(
this,
"example_3",
{
location: azurermResourceGroupExample.location,
name: "myexamplesqldatabase",
resource_group_name: azurermResourceGroupExample.name,
server_name: azurermSqlServerExample.name,
tags: {
environment: "production",
},
}
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermSqlDatabaseExample.overrideLogicalId("example");
Argument Reference
The following arguments are supported:
-
name- (Required) The name of the database. Changing this forces a new resource to be created. -
resourceGroupName- (Required) The name of the resource group in which to create the database. This must be the same as Database Server resource group currently. Changing this forces a new resource to be created. -
location- (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. -
serverName- (Required) The name of the SQL Server on which to create the database. Changing this forces a new resource to be created. -
createMode- (Optional) Specifies how to create the database. Valid values are:default,copy,onlineSecondary,nonReadableSecondary,pointInTimeRestore,recovery,restoreorrestoreLongTermRetentionBackup. Must bedefaultto create a new database. Defaults todefault. Please see Azure SQL Database REST API -
import- (Optional) A Database Import block as documented below.createModemust be set todefault. -
sourceDatabaseId- (Optional) The URI of the source database ifcreateModevalue is notdefault. -
restorePointInTime- (Optional) The point in time for the restore. Only applies ifcreateModeispointInTimeRestore, it should be provided in RFC3339 format, e.g.20131108T22:00:40Z. -
edition- (Optional) The edition of the database to be created. Applies only ifcreateModeisdefault. Valid values are:basic,standard,premium,dataWarehouse,business,businessCritical,free,generalPurpose,hyperscale,premium,premiumRs,standard,stretch,system,system2, orweb. Please see Azure SQL database models. -
collation- (Optional) The name of the collation. Applies only ifcreateModeisdefault. Azure default issqlLatin1GeneralCp1CiAs. Changing this forces a new resource to be created. -
maxSizeBytes- (Optional) The maximum size that the database can grow to. Applies only ifcreateModeisdefault. Please see Azure SQL database models. -
requestedServiceObjectiveId- (Optional) A GUID/UUID corresponding to a configured Service Level Objective for the Azure SQL database which can be used to configure a performance level. . -
requestedServiceObjectiveName- (Optional) The service objective name for the database. Valid values depend on edition and location and may includes0,s1,s2,s3,p1,p2,p4,p6,p11andelasticPool. You can list the available names with the CLI:shellAzSqlDbListEditionsLWestusOTable. For further information please see Azure CLI - az sql db. -
sourceDatabaseDeletionDate- (Optional) The deletion date time of the source database. Only applies to deleted databases wherecreateModeispointInTimeRestore. -
elasticPoolName- (Optional) The name of the elastic database pool. -
threatDetectionPolicy- (Optional) Threat detection policy configuration. ThethreatDetectionPolicyblock supports fields documented below. -
readScale- (Optional) Read-only connections will be redirected to a high-available replica. Please see Use read-only replicas to load-balance read-only query workloads. -
zoneRedundant- (Optional) Whether or not this database is zone redundant, which means the replicas of this database will be spread across multiple availability zones. -
tags- (Optional) A mapping of tags to assign to the resource.
The import block supports the following:
storageUri- (Required) Specifies the blob URI of the .bacpac file.storageKey- (Required) Specifies the access key for the storage account.storageKeyType- (Required) Specifies the type of access key for the storage account. Valid values arestorageAccessKeyorsharedAccessKey.administratorLogin- (Required) Specifies the name of the SQL administrator.administratorLoginPassword- (Required) Specifies the password of the SQL administrator.authenticationType- (Required) Specifies the type of authentication used to access the server. Valid values aresqloradPassword.operationMode- (Optional) Specifies the type of import operation being performed. The only allowable value isimport.
The threatDetectionPolicy block supports the following:
state- (Optional) The State of the Policy. Possible values areenabled,disabledornew.disabledAlerts- (Optional) Specifies a list of alerts which should be disabled. Possible values includeaccessAnomaly,sqlInjectionandsqlInjectionVulnerability.emailAccountAdmins- (Optional) Should the account administrators be emailed when this alert is triggered? Possible values aredisabledandenabled.emailAddresses- (Optional) A list of email addresses which alerts should be sent to.retentionDays- (Optional) Specifies the number of days to keep in the Threat Detection audit logs.storageAccountAccessKey- (Optional) Specifies the identifier key of the Threat Detection audit storage account. Required ifstateisenabled.storageEndpoint- (Optional) Specifies the blob storage endpoint (e.g. https://example.blob.core.windows.net). This blob storage will hold all Threat Detection audit logs. Required ifstateisenabled.
Attributes Reference
The following attributes are exported:
id- The SQL Database ID.creationDate- The creation date of the SQL Database.defaultSecondaryLocation- The default secondary location of the SQL Database.
Timeouts
The timeouts block allows you to specify timeouts for certain actions:
create- (Defaults to 60 minutes) Used when creating the SQL Database.update- (Defaults to 60 minutes) Used when updating the SQL Database.read- (Defaults to 5 minutes) Used when retrieving the SQL Database.delete- (Defaults to 60 minutes) Used when deleting the SQL Database.
Import
SQL Databases can be imported using the resourceId, e.g.