你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
- Latest
- 2026-08-01-preview
- 2025-08-01-preview
- 2025-02-01-preview
- 2025-01-01
- 2024-11-01-preview
- 2024-05-01-preview
- 2023-08-01
- 2023-08-01-preview
- 2023-05-01-preview
- 2023-02-01-preview
- 2022-11-01-preview
- 2022-08-01-preview
- 2022-05-01-preview
- 2022-02-01-preview
- 2021-11-01
- 2021-11-01-preview
- 2021-08-01-preview
- 2021-05-01-preview
- 2021-02-01-preview
- 2020-11-01-preview
- 2020-08-01-preview
- 2020-02-02-preview
- 2019-06-01-preview
- 2017-10-01-preview
- 2017-03-01-preview
- 2014-04-01
Bicep资源定义
可以使用目标操作部署服务器/数据库资源类型:
- 资源组 - 请参阅 资源组部署命令
有关每个 API 版本中已更改属性的列表,请参阅 更改日志。
用法示例
Bicep 样本
部署 MS SQL 数据库的基本示例。
@secure()
@description('The administrator login password for the SQL server')
param administratorLoginPassword string
param resourceName string = 'acctest0001'
param location string = 'westeurope'
resource server 'Microsoft.Sql/servers@2021-02-01-preview' = {
name: resourceName
location: location
properties: {
administratorLogin: 'mradministrator'
administratorLoginPassword: administratorLoginPassword
minimalTlsVersion: '1.2'
publicNetworkAccess: 'Enabled'
restrictOutboundNetworkAccess: 'Disabled'
version: '12.0'
}
}
resource database 'Microsoft.Sql/servers/databases@2021-02-01-preview' = {
name: resourceName
location: location
parent: server
properties: {
autoPauseDelay: 0
createMode: 'Default'
elasticPoolId: ''
highAvailabilityReplicaCount: 0
isLedgerOn: false
licenseType: 'LicenseIncluded'
maintenanceConfigurationId: resourceId('Microsoft.Maintenance/publicMaintenanceConfigurations', 'SQL_Default')
minCapacity: 0
readScale: 'Disabled'
requestedBackupStorageRedundancy: 'Geo'
zoneRedundant: false
}
}
Azure verified modules
以下 Azure 验证模块可用于部署该资源类型。
| 模块 | Description |
|---|---|
| Azure SQL 数据库 | AVM Resource Module for Azure SQL 数据库 |
Azure 快速入门示例
以下Azure快速启动模板包含部署该资源类型的Bicep示例。
| Bicep 文件 | Description |
|---|---|
| 该模板允许您部署启用审计功能的 Azure SQL 服务器,将审计日志写入 Log Analytics(OMS 工作空间) | |
| 创建SQL Server和数据库 | 使用此模板可以创建 SQL 数据库和服务器。 |
| 专用SQL池,采用透明加密 | 创建一个SQL Server和一个专用SQL池(前称SQL DW),并采用透明数据加密。 |
| 创建一个启用 ADLS Gen 2 的 Azure 存储账户,创建一个带有关联服务的 Azure 数据工厂 实例(如果部署了则是 Azure SQL 数据库),以及一个 Azure Databricks 实例。 将为部署模板的用户的 AAD 标识以及 ADF 实例的托管标识授予存储帐户上的存储 Blob 数据参与者角色。 还有部署 Azure 密钥保管库 实例、Azure SQL 数据库 和 Azure Event Hub(用于流式使用场景)的选项。 当 Azure 密钥保管库 部署时,部署该模板的用户的数据工厂管理身份和 AAD 身份将被授予 密钥保管库 Secrets 用户角色。 | |
| 私有端点示例 | 这个模板展示了如何创建指向 Azure SQL Server 的私有端点 |
| 使用 SQL 数据库 预配 Web 应用 | 此模板预配 Web 应用、SQL 数据库、自动缩放设置、警报规则和 App Insights。 它在网页应用中为数据库配置一个连接字符串。 |
| 此模板使用官方 Sonarqube 映像并由 Azure SQL Server 支持,部署于 Azure 应用服务 web app Linux 容器中。 | |
| Web 应用,支持托管身份、SQL Server 和 ΑΙ | 部署 Azure 基础设施用于应用 + 数据 + 管理身份 + 监控的简单示例 |
资源格式
去创造一个Microsoft。Sql/servers/databases 资源,给你的模板添加以下 Bicep。
resource symbolicname 'Microsoft.Sql/servers/databases@2014-04-01' = {
parent: resourceSymbolicName
location: 'string'
name: 'string'
properties: {
collation: 'string'
createMode: 'string'
edition: 'string'
elasticPoolName: 'string'
maxSizeBytes: 'string'
readScale: 'string'
recoveryServicesRecoveryPointResourceId: 'string'
requestedServiceObjectiveId: 'string'
requestedServiceObjectiveName: 'string'
restorePointInTime: 'string'
sampleName: 'string'
sourceDatabaseDeletionDate: 'string'
sourceDatabaseId: 'string'
zoneRedundant: bool
}
tags: {
{customized property}: 'string'
}
}
属性值
Microsoft。SQL/服务器/数据库
| Name | Description | Value |
|---|---|---|
| 位置 | 资源位置。 | string (必需) |
| name | 资源名称 | string (必需) |
| 父级 | 在 Bicep 中,你可以指定子资源的父资源。 仅当子资源在父资源外部声明时,才需要添加此属性。 有关详细信息,请参阅 父资源外部的子资源。 |
类型资源的符号名称:服务器 |
| properties | 表示资源的属性。 | DatabaseProperties |
| tags | 资源标记 | 标记名称和值的字典。 请参阅模板 中的 |
DatabaseProperties
|名称 |说明 |值 | |---- |----------- |------------ | |排序规则 |数据库的排序规则。 如果 createMode 不是默认值,则忽略此值。 |string | |createMode |指定数据库创建模式。
默认值:常规数据库创建。
复制:将数据库创建为现有数据库的副本。 sourceDatabaseId 必须指定为源数据库的资源 ID。
OnlineSecondary/NonReadableSecondary:将数据库创建为现有数据库的辅助副本(可读或不可读)。 sourceDatabaseId 必须指定为现有主数据库的资源 ID。
PointInTimeRestore:通过还原现有数据库的时间点备份来创建数据库。 sourceDatabaseId 必须指定为现有数据库的资源 ID,并且必须指定 restorePointInTime。
恢复:通过还原异地复制的备份来创建数据库。 sourceDatabaseId 必须指定为可恢复的数据库资源 ID 才能还原。
还原:通过还原已删除数据库的备份来创建数据库。 必须指定 sourceDatabaseId。 如果 sourceDatabaseId 是数据库的原始资源 ID,则必须指定 sourceDatabaseDeletionDate。 否则,sourceDatabaseId 必须是可还原删除的数据库资源 ID,并且将忽略 sourceDatabaseDeletionDate。 还可以指定 restorePointInTime,以便从以前的时间点还原。
RestoreLongTermRetentionBackup:通过从长期保留保管库还原来创建数据库。 recoveryServicesRecoveryPointResourceId 必须指定为恢复点资源 ID。
DataWarehouse 版本不支持 Copy、NonReadableSecondary、OnlineSecondary 和 RestoreLongTermRetentionBackup。 |“复制”
'Default'
'NonReadableSecondary'
'OnlineSecondary'
'PointInTimeRestore'
'Recovery'
'Restore'
'RestoreLongTermRetentionBackup' | |版本 |数据库的版本。 DatabaseEditions 枚举包含所有有效版本。 如果 createMode 为 NonReadableSecondary 或 OnlineSecondary,则忽略此值。
SKU 列表可能因区域和支持产品/服务而异。 要确定Azure区域内订阅可用的SKU(包括SKU名称、层级/版本、家族和容量),可以使用Capabilities_ListByLocation REST API或以下命令之一:
azurecli<br />az sql db list-editions -l <location> -o table<br />````<br /><br />Powershell
Get-AzSqlServerServiceObjective -Location <位置> | 'Basic'<br />'Business'<br />'BusinessCritical'<br />'DataWarehouse'<br />'Free'<br />'GeneralPurpose'<br />'Hyperscale'<br />'Premium'<br />'PremiumRS'<br />'Standard'<br />'Stretch'<br />'System'<br />'System2'<br />'Web' | | elasticPoolName | The name of the elastic pool the database is in. If elasticPoolName and requestedServiceObjectiveName are both updated, the value of requestedServiceObjectiveName is ignored. Not supported for DataWarehouse edition. | string | | maxSizeBytes | The max size of the database expressed in bytes. If createMode is not Default, this value is ignored. To see possible values, query the capabilities API (/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationID}/capabilities) referred to by operationId: "Capabilities_ListByLocation." | string | | readScale | Conditional. If the database is a geo-secondary, readScale indicates whether read-only connections are allowed to this database or not. Not supported for DataWarehouse edition. | 'Disabled'<br />'Enabled' | | recoveryServicesRecoveryPointResourceId | Conditional. If createMode is RestoreLongTermRetentionBackup, then this value is required. Specifies the resource ID of the recovery point to restore from. | string | | requestedServiceObjectiveId | The configured service level objective ID of the database. This is the service level objective that is in the process of being applied to the database. Once successfully updated, it will match the value of currentServiceObjectiveId property. If requestedServiceObjectiveId and requestedServiceObjectiveName are both updated, the value of requestedServiceObjectiveId overrides the value of requestedServiceObjectiveName.<br /><br />The list of SKUs may vary by region and support offer. To determine the service objective ids that are available to your subscription in an Azure region, use the `Capabilities_ListByLocation` REST API. | string <br /><br />Constraints:<br />Min length = 36<br />Max length = 36<br />Pattern = `^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$` | | requestedServiceObjectiveName | The name of the configured service level objective of the database. This is the service level objective that is in the process of being applied to the database. Once successfully updated, it will match the value of serviceLevelObjective property. <br /><br />The list of SKUs may vary by region and support offer. To determine the SKUs (including the SKU name, tier/edition, family, and capacity) that are available to your subscription in an Azure region, use the `Capabilities_ListByLocation` REST API or one of the following commands:<br /><br />```azurecli<br />az sql db list-editions -l <location> -o table<br />
```powershell
Get-AzSqlServerServiceObjective -Location <位置>
```` |“Basic”
'DS100'
'DS1000'
'DS1200'
'DS1500'
'DS200'
'DS2000'
'DS300'
'DS400'
'DS500'
'DS600'
'DW100'
'DW1000'
'DW10000c'
'DW1000c'
'DW1200'
'DW1500'
'DW15000c'
'DW1500c'
'DW200'
'DW2000'
'DW2000c'
'DW2500c'
'DW300'
'DW3000'
'DW30000c'
'DW3000c'
'DW400'
'DW500'
'DW5000c'
'DW600'
'DW6000'
'DW6000c'
'DW7500c'
'ElasticPool'
'Free'
'P1'
'P11'
'P15'
'P2'
'P3'
'P4'
'P6'
'PRS1'
'PRS2'
'PRS4'
'PRS6'
'S0'
'S1'
'S12'
'S2'
'S3'
'S4'
'S6'
'S7'
'S9'
'System'
'System0'
'System1'
'System2'
'System2L'
'System3'
'System3L'
'System4'
“System4L” | |restorePointInTime |有條件的。 如果 createMode 为 PointInTimeRestore,则此值是必需的。 如果 createMode 为 Restore,则此值是可选的。 指定将还原以创建新数据库的源数据库的时间点(ISO8601格式)。 必须大于或等于源数据库的最早RestoreDate 值。 |string | |sampleName |指示创建此数据库时要应用的示例架构的名称。 如果 createMode 不是默认值,则忽略此值。 DataWarehouse 版本不支持。 |“AdventureWorksLT”| |sourceDatabaseDeletionDate |有條件的。 如果 createMode 为 Restore,并且 sourceDatabaseId 是已删除的数据库的原始资源 ID(而不是其当前可还原的已删除数据库 ID),则此值是必需的。 指定删除数据库的时间。 |string | |sourceDatabaseId |有條件的。 如果 createMode 为 Copy、NonReadableSecondary、OnlineSecondary、PointInTimeRestore、Recovery 或 Restore,则此值是必需的。 指定源数据库的资源 ID。 如果 createMode 为 NonReadableSecondary 或 OnlineSecondary,则源数据库的名称必须与要创建新数据库的名称相同。 |string | |zoneRedundant |此数据库是否为区域冗余,这意味着此数据库的副本将分布在多个可用性区域。 |bool |
TrackedResourceTags
| Name | Description | Value |
|---|
ARM 模板资源定义
可以使用目标操作部署服务器/数据库资源类型:
用法示例
Azure 快速入门模板
以下Azure快速启动模板部署了这种资源类型。
| Template | Description |
|---|---|
| 该模板允许您部署启用审计功能的 Azure SQL 服务器,将审计日志写入 Log Analytics(OMS 工作空间) | |
|
创建SQL Server和数据库 |
使用此模板可以创建 SQL 数据库和服务器。 |
|
专用SQL池,采用透明加密 |
创建一个SQL Server和一个专用SQL池(前称SQL DW),并采用透明数据加密。 |
|
部署新的SQL弹性池, |
该模板允许您部署一个新的SQL弹性池,并配备新的关联SQL Server和新的SQL数据库以分配到它。 |
| 创建一个启用 ADLS Gen 2 的 Azure 存储账户,创建一个带有关联服务的 Azure 数据工厂 实例(如果部署了则是 Azure SQL 数据库),以及一个 Azure Databricks 实例。 将为部署模板的用户的 AAD 标识以及 ADF 实例的托管标识授予存储帐户上的存储 Blob 数据参与者角色。 还有部署 Azure 密钥保管库 实例、Azure SQL 数据库 和 Azure Event Hub(用于流式使用场景)的选项。 当 Azure 密钥保管库 部署时,部署该模板的用户的数据工厂管理身份和 AAD 身份将被授予 密钥保管库 Secrets 用户角色。 | |
| 此模板允许在现有虚拟网络中创建 HDInsight 群集,该群集具有新的 SQL DB,该数据库既充当自定义 Ambari DB,又充当 Hive 元存储。 必须具有现有的 SQL Sever、存储帐户和 VNET。 | |
|
私有端点示例 |
这个模板展示了如何创建指向 Azure SQL Server 的私有端点 |
|
使用 SQL 数据库 预配 Web 应用 |
此模板预配 Web 应用、SQL 数据库、自动缩放设置、警报规则和 App Insights。 它在网页应用中为数据库配置一个连接字符串。 |
|
远程桌面 高可用性服务 |
该 ARM 模板示例代码将部署一个高可用性的 远程桌面服务 2019 会话集合实验室。 目标是部署一个完全冗余、高可用性的 远程桌面 服务解决方案,使用 Windows Server 2019。 |
| 此模板使用官方 Sonarqube 映像并由 Azure SQL Server 支持,部署于 Azure 应用服务 web app Linux 容器中。 | |
|
Web 应用,支持托管身份、SQL Server 和 ΑΙ |
部署 Azure 基础设施用于应用 + 数据 + 管理身份 + 监控的简单示例 |
|
WebApp正在消耗Azure SQL私有端点 |
该模板展示了如何创建一个使用指向 Azure SQL Server 私有端点的 Web 应用 |
资源格式
去创造一个Microsoft。Sql/servers/databases 资源,在模板中添加以下 JSON 代码。
{
"type": "Microsoft.Sql/servers/databases",
"apiVersion": "2014-04-01",
"name": "string",
"location": "string",
"properties": {
"collation": "string",
"createMode": "string",
"edition": "string",
"elasticPoolName": "string",
"maxSizeBytes": "string",
"readScale": "string",
"recoveryServicesRecoveryPointResourceId": "string",
"requestedServiceObjectiveId": "string",
"requestedServiceObjectiveName": "string",
"restorePointInTime": "string",
"sampleName": "string",
"sourceDatabaseDeletionDate": "string",
"sourceDatabaseId": "string",
"zoneRedundant": "bool"
},
"tags": {
"{customized property}": "string"
}
}
属性值
Microsoft。SQL/服务器/数据库
| Name | Description | Value |
|---|---|---|
| apiVersion | API 版本 | '2014-04-01' |
| 位置 | 资源位置。 | string (必需) |
| name | 资源名称 | string (必需) |
| properties | 表示资源的属性。 | DatabaseProperties |
| tags | 资源标记 | 标记名称和值的字典。 请参阅模板 中的 |
| 类型 | 资源类型 | “Microsoft。Sql/服务器/数据库 |
DatabaseProperties
|名称 |说明 |值 | |---- |----------- |------------ | |排序规则 |数据库的排序规则。 如果 createMode 不是默认值,则忽略此值。 |string | |createMode |指定数据库创建模式。
默认值:常规数据库创建。
复制:将数据库创建为现有数据库的副本。 sourceDatabaseId 必须指定为源数据库的资源 ID。
OnlineSecondary/NonReadableSecondary:将数据库创建为现有数据库的辅助副本(可读或不可读)。 sourceDatabaseId 必须指定为现有主数据库的资源 ID。
PointInTimeRestore:通过还原现有数据库的时间点备份来创建数据库。 sourceDatabaseId 必须指定为现有数据库的资源 ID,并且必须指定 restorePointInTime。
恢复:通过还原异地复制的备份来创建数据库。 sourceDatabaseId 必须指定为可恢复的数据库资源 ID 才能还原。
还原:通过还原已删除数据库的备份来创建数据库。 必须指定 sourceDatabaseId。 如果 sourceDatabaseId 是数据库的原始资源 ID,则必须指定 sourceDatabaseDeletionDate。 否则,sourceDatabaseId 必须是可还原删除的数据库资源 ID,并且将忽略 sourceDatabaseDeletionDate。 还可以指定 restorePointInTime,以便从以前的时间点还原。
RestoreLongTermRetentionBackup:通过从长期保留保管库还原来创建数据库。 recoveryServicesRecoveryPointResourceId 必须指定为恢复点资源 ID。
DataWarehouse 版本不支持 Copy、NonReadableSecondary、OnlineSecondary 和 RestoreLongTermRetentionBackup。 |“复制”
'Default'
'NonReadableSecondary'
'OnlineSecondary'
'PointInTimeRestore'
'Recovery'
'Restore'
'RestoreLongTermRetentionBackup' | |版本 |数据库的版本。 DatabaseEditions 枚举包含所有有效版本。 如果 createMode 为 NonReadableSecondary 或 OnlineSecondary,则忽略此值。
SKU 列表可能因区域和支持产品/服务而异。 要确定Azure区域内订阅可用的SKU(包括SKU名称、层级/版本、家族和容量),可以使用Capabilities_ListByLocation REST API或以下命令之一:
azurecli<br />az sql db list-editions -l <location> -o table<br />````<br /><br />Powershell
Get-AzSqlServerServiceObjective -Location <位置> | 'Basic'<br />'Business'<br />'BusinessCritical'<br />'DataWarehouse'<br />'Free'<br />'GeneralPurpose'<br />'Hyperscale'<br />'Premium'<br />'PremiumRS'<br />'Standard'<br />'Stretch'<br />'System'<br />'System2'<br />'Web' | | elasticPoolName | The name of the elastic pool the database is in. If elasticPoolName and requestedServiceObjectiveName are both updated, the value of requestedServiceObjectiveName is ignored. Not supported for DataWarehouse edition. | string | | maxSizeBytes | The max size of the database expressed in bytes. If createMode is not Default, this value is ignored. To see possible values, query the capabilities API (/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationID}/capabilities) referred to by operationId: "Capabilities_ListByLocation." | string | | readScale | Conditional. If the database is a geo-secondary, readScale indicates whether read-only connections are allowed to this database or not. Not supported for DataWarehouse edition. | 'Disabled'<br />'Enabled' | | recoveryServicesRecoveryPointResourceId | Conditional. If createMode is RestoreLongTermRetentionBackup, then this value is required. Specifies the resource ID of the recovery point to restore from. | string | | requestedServiceObjectiveId | The configured service level objective ID of the database. This is the service level objective that is in the process of being applied to the database. Once successfully updated, it will match the value of currentServiceObjectiveId property. If requestedServiceObjectiveId and requestedServiceObjectiveName are both updated, the value of requestedServiceObjectiveId overrides the value of requestedServiceObjectiveName.<br /><br />The list of SKUs may vary by region and support offer. To determine the service objective ids that are available to your subscription in an Azure region, use the `Capabilities_ListByLocation` REST API. | string <br /><br />Constraints:<br />Min length = 36<br />Max length = 36<br />Pattern = `^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$` | | requestedServiceObjectiveName | The name of the configured service level objective of the database. This is the service level objective that is in the process of being applied to the database. Once successfully updated, it will match the value of serviceLevelObjective property. <br /><br />The list of SKUs may vary by region and support offer. To determine the SKUs (including the SKU name, tier/edition, family, and capacity) that are available to your subscription in an Azure region, use the `Capabilities_ListByLocation` REST API or one of the following commands:<br /><br />```azurecli<br />az sql db list-editions -l <location> -o table<br />
```powershell
Get-AzSqlServerServiceObjective -Location <位置>
```` |“Basic”
'DS100'
'DS1000'
'DS1200'
'DS1500'
'DS200'
'DS2000'
'DS300'
'DS400'
'DS500'
'DS600'
'DW100'
'DW1000'
'DW10000c'
'DW1000c'
'DW1200'
'DW1500'
'DW15000c'
'DW1500c'
'DW200'
'DW2000'
'DW2000c'
'DW2500c'
'DW300'
'DW3000'
'DW30000c'
'DW3000c'
'DW400'
'DW500'
'DW5000c'
'DW600'
'DW6000'
'DW6000c'
'DW7500c'
'ElasticPool'
'Free'
'P1'
'P11'
'P15'
'P2'
'P3'
'P4'
'P6'
'PRS1'
'PRS2'
'PRS4'
'PRS6'
'S0'
'S1'
'S12'
'S2'
'S3'
'S4'
'S6'
'S7'
'S9'
'System'
'System0'
'System1'
'System2'
'System2L'
'System3'
'System3L'
'System4'
“System4L” | |restorePointInTime |有條件的。 如果 createMode 为 PointInTimeRestore,则此值是必需的。 如果 createMode 为 Restore,则此值是可选的。 指定将还原以创建新数据库的源数据库的时间点(ISO8601格式)。 必须大于或等于源数据库的最早RestoreDate 值。 |string | |sampleName |指示创建此数据库时要应用的示例架构的名称。 如果 createMode 不是默认值,则忽略此值。 DataWarehouse 版本不支持。 |“AdventureWorksLT”| |sourceDatabaseDeletionDate |有條件的。 如果 createMode 为 Restore,并且 sourceDatabaseId 是已删除的数据库的原始资源 ID(而不是其当前可还原的已删除数据库 ID),则此值是必需的。 指定删除数据库的时间。 |string | |sourceDatabaseId |有條件的。 如果 createMode 为 Copy、NonReadableSecondary、OnlineSecondary、PointInTimeRestore、Recovery 或 Restore,则此值是必需的。 指定源数据库的资源 ID。 如果 createMode 为 NonReadableSecondary 或 OnlineSecondary,则源数据库的名称必须与要创建新数据库的名称相同。 |string | |zoneRedundant |此数据库是否为区域冗余,这意味着此数据库的副本将分布在多个可用性区域。 |bool |
TrackedResourceTags
| Name | Description | Value |
|---|
Terraform (AzAPI 提供程序)资源定义
可以使用目标操作部署服务器/数据库资源类型:
- 资源组 关于每个API版本中变更属性的列表,请参见 更改日志。
用法示例
Terraform 示例
部署 MS SQL 数据库的基本示例。
terraform {
required_providers {
azapi = {
source = "Azure/azapi"
}
azurerm = {
source = "hashicorp/azurerm"
}
}
}
provider "azurerm" {
features {
}
}
provider "azapi" {
skip_provider_registration = false
}
variable "resource_name" {
type = string
default = "acctest0001"
}
variable "location" {
type = string
default = "westeurope"
}
variable "administrator_login_password" {
type = string
description = "The administrator login password for the SQL server"
sensitive = true
}
data "azurerm_client_config" "current" {
}
resource "azapi_resource" "resourceGroup" {
type = "Microsoft.Resources/resourceGroups@2020-06-01"
name = var.resource_name
location = var.location
}
resource "azapi_resource" "server" {
type = "Microsoft.Sql/servers@2021-02-01-preview"
parent_id = azapi_resource.resourceGroup.id
name = var.resource_name
location = var.location
body = {
properties = {
administratorLogin = "mradministrator"
administratorLoginPassword = var.administrator_login_password
minimalTlsVersion = "1.2"
publicNetworkAccess = "Enabled"
restrictOutboundNetworkAccess = "Disabled"
version = "12.0"
}
}
schema_validation_enabled = false
response_export_values = ["*"]
}
data "azapi_resource_id" "publicMaintenanceConfiguration" {
type = "Microsoft.Maintenance/publicMaintenanceConfigurations@2023-04-01"
parent_id = "/subscriptions/${data.azurerm_client_config.current.subscription_id}"
name = "SQL_Default"
}
resource "azapi_resource" "database" {
type = "Microsoft.Sql/servers/databases@2021-02-01-preview"
parent_id = azapi_resource.server.id
name = var.resource_name
location = var.location
body = {
properties = {
autoPauseDelay = 0
createMode = "Default"
elasticPoolId = ""
highAvailabilityReplicaCount = 0
isLedgerOn = false
licenseType = "LicenseIncluded"
maintenanceConfigurationId = data.azapi_resource_id.publicMaintenanceConfiguration.id
minCapacity = 0
readScale = "Disabled"
requestedBackupStorageRedundancy = "Geo"
zoneRedundant = false
}
}
schema_validation_enabled = false
response_export_values = ["*"]
}
部署 MS SQL 数据库的基本示例。
terraform {
required_providers {
azapi = {
source = "Azure/azapi"
}
azurerm = {
source = "hashicorp/azurerm"
}
}
}
provider "azurerm" {
features {
}
}
provider "azapi" {
skip_provider_registration = false
}
variable "resource_name" {
type = string
default = "acctest0001"
}
variable "location" {
type = string
default = "westeurope"
}
variable "administrator_login_password" {
type = string
description = "The administrator login password for the SQL server"
sensitive = true
}
data "azurerm_client_config" "current" {
}
resource "azapi_resource" "resourceGroup" {
type = "Microsoft.Resources/resourceGroups@2020-06-01"
name = var.resource_name
location = var.location
}
resource "azapi_resource" "server" {
type = "Microsoft.Sql/servers@2021-02-01-preview"
parent_id = azapi_resource.resourceGroup.id
name = var.resource_name
location = var.location
body = {
properties = {
administratorLogin = "mradministrator"
administratorLoginPassword = var.administrator_login_password
minimalTlsVersion = "1.2"
publicNetworkAccess = "Enabled"
restrictOutboundNetworkAccess = "Disabled"
version = "12.0"
}
}
schema_validation_enabled = false
response_export_values = ["*"]
}
data "azapi_resource_id" "publicMaintenanceConfiguration" {
type = "Microsoft.Maintenance/publicMaintenanceConfigurations@2023-04-01"
parent_id = "/subscriptions/${data.azurerm_client_config.current.subscription_id}"
name = "SQL_Default"
}
resource "azapi_resource" "database" {
type = "Microsoft.Sql/servers/databases@2021-02-01-preview"
parent_id = azapi_resource.server.id
name = var.resource_name
location = var.location
body = {
properties = {
autoPauseDelay = 0
createMode = "Default"
elasticPoolId = ""
highAvailabilityReplicaCount = 0
isLedgerOn = false
licenseType = "LicenseIncluded"
maintenanceConfigurationId = data.azapi_resource_id.publicMaintenanceConfiguration.id
minCapacity = 0
readScale = "Disabled"
requestedBackupStorageRedundancy = "Geo"
zoneRedundant = false
}
}
schema_validation_enabled = false
response_export_values = ["*"]
}
资源格式
去创造一个Microsoft。Sql/servers/databases 资源,将以下 Terraform 添加到你的模板中。
resource "azapi_resource" "symbolicname" {
type = "Microsoft.Sql/servers/databases@2014-04-01"
name = "string"
parent_id = "string"
location = "string"
tags = {
{customized property} = "string"
}
body = {
properties = {
collation = "string"
createMode = "string"
edition = "string"
elasticPoolName = "string"
maxSizeBytes = "string"
readScale = "string"
recoveryServicesRecoveryPointResourceId = "string"
requestedServiceObjectiveId = "string"
requestedServiceObjectiveName = "string"
restorePointInTime = "string"
sampleName = "string"
sourceDatabaseDeletionDate = "string"
sourceDatabaseId = "string"
zoneRedundant = bool
}
}
}
属性值
Microsoft。SQL/服务器/数据库
| Name | Description | Value |
|---|---|---|
| 位置 | 资源位置。 | string (必需) |
| name | 资源名称 | string (必需) |
| parent_id | 此资源的父资源的 ID。 | 类型资源的 ID:服务器 |
| properties | 表示资源的属性。 | DatabaseProperties |
| tags | 资源标记 | 标记名称和值的字典。 |
| 类型 | 资源类型 | “Microsoft。Sql/servers/databases@2014-04-01” |
DatabaseProperties
|名称 |说明 |值 | |---- |----------- |------------ | |排序规则 |数据库的排序规则。 如果 createMode 不是默认值,则忽略此值。 |string | |createMode |指定数据库创建模式。
默认值:常规数据库创建。
复制:将数据库创建为现有数据库的副本。 sourceDatabaseId 必须指定为源数据库的资源 ID。
OnlineSecondary/NonReadableSecondary:将数据库创建为现有数据库的辅助副本(可读或不可读)。 sourceDatabaseId 必须指定为现有主数据库的资源 ID。
PointInTimeRestore:通过还原现有数据库的时间点备份来创建数据库。 sourceDatabaseId 必须指定为现有数据库的资源 ID,并且必须指定 restorePointInTime。
恢复:通过还原异地复制的备份来创建数据库。 sourceDatabaseId 必须指定为可恢复的数据库资源 ID 才能还原。
还原:通过还原已删除数据库的备份来创建数据库。 必须指定 sourceDatabaseId。 如果 sourceDatabaseId 是数据库的原始资源 ID,则必须指定 sourceDatabaseDeletionDate。 否则,sourceDatabaseId 必须是可还原删除的数据库资源 ID,并且将忽略 sourceDatabaseDeletionDate。 还可以指定 restorePointInTime,以便从以前的时间点还原。
RestoreLongTermRetentionBackup:通过从长期保留保管库还原来创建数据库。 recoveryServicesRecoveryPointResourceId 必须指定为恢复点资源 ID。
DataWarehouse 版本不支持 Copy、NonReadableSecondary、OnlineSecondary 和 RestoreLongTermRetentionBackup。 |“复制”
'Default'
'NonReadableSecondary'
'OnlineSecondary'
'PointInTimeRestore'
'Recovery'
'Restore'
'RestoreLongTermRetentionBackup' | |版本 |数据库的版本。 DatabaseEditions 枚举包含所有有效版本。 如果 createMode 为 NonReadableSecondary 或 OnlineSecondary,则忽略此值。
SKU 列表可能因区域和支持产品/服务而异。 要确定Azure区域内订阅可用的SKU(包括SKU名称、层级/版本、家族和容量),可以使用Capabilities_ListByLocation REST API或以下命令之一:
azurecli<br />az sql db list-editions -l <location> -o table<br />````<br /><br />Powershell
Get-AzSqlServerServiceObjective -Location <位置> | 'Basic'<br />'Business'<br />'BusinessCritical'<br />'DataWarehouse'<br />'Free'<br />'GeneralPurpose'<br />'Hyperscale'<br />'Premium'<br />'PremiumRS'<br />'Standard'<br />'Stretch'<br />'System'<br />'System2'<br />'Web' | | elasticPoolName | The name of the elastic pool the database is in. If elasticPoolName and requestedServiceObjectiveName are both updated, the value of requestedServiceObjectiveName is ignored. Not supported for DataWarehouse edition. | string | | maxSizeBytes | The max size of the database expressed in bytes. If createMode is not Default, this value is ignored. To see possible values, query the capabilities API (/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationID}/capabilities) referred to by operationId: "Capabilities_ListByLocation." | string | | readScale | Conditional. If the database is a geo-secondary, readScale indicates whether read-only connections are allowed to this database or not. Not supported for DataWarehouse edition. | 'Disabled'<br />'Enabled' | | recoveryServicesRecoveryPointResourceId | Conditional. If createMode is RestoreLongTermRetentionBackup, then this value is required. Specifies the resource ID of the recovery point to restore from. | string | | requestedServiceObjectiveId | The configured service level objective ID of the database. This is the service level objective that is in the process of being applied to the database. Once successfully updated, it will match the value of currentServiceObjectiveId property. If requestedServiceObjectiveId and requestedServiceObjectiveName are both updated, the value of requestedServiceObjectiveId overrides the value of requestedServiceObjectiveName.<br /><br />The list of SKUs may vary by region and support offer. To determine the service objective ids that are available to your subscription in an Azure region, use the `Capabilities_ListByLocation` REST API. | string <br /><br />Constraints:<br />Min length = 36<br />Max length = 36<br />Pattern = `^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$` | | requestedServiceObjectiveName | The name of the configured service level objective of the database. This is the service level objective that is in the process of being applied to the database. Once successfully updated, it will match the value of serviceLevelObjective property. <br /><br />The list of SKUs may vary by region and support offer. To determine the SKUs (including the SKU name, tier/edition, family, and capacity) that are available to your subscription in an Azure region, use the `Capabilities_ListByLocation` REST API or one of the following commands:<br /><br />```azurecli<br />az sql db list-editions -l <location> -o table<br />
```powershell
Get-AzSqlServerServiceObjective -Location <位置>
```` |“Basic”
'DS100'
'DS1000'
'DS1200'
'DS1500'
'DS200'
'DS2000'
'DS300'
'DS400'
'DS500'
'DS600'
'DW100'
'DW1000'
'DW10000c'
'DW1000c'
'DW1200'
'DW1500'
'DW15000c'
'DW1500c'
'DW200'
'DW2000'
'DW2000c'
'DW2500c'
'DW300'
'DW3000'
'DW30000c'
'DW3000c'
'DW400'
'DW500'
'DW5000c'
'DW600'
'DW6000'
'DW6000c'
'DW7500c'
'ElasticPool'
'Free'
'P1'
'P11'
'P15'
'P2'
'P3'
'P4'
'P6'
'PRS1'
'PRS2'
'PRS4'
'PRS6'
'S0'
'S1'
'S12'
'S2'
'S3'
'S4'
'S6'
'S7'
'S9'
'System'
'System0'
'System1'
'System2'
'System2L'
'System3'
'System3L'
'System4'
“System4L” | |restorePointInTime |有條件的。 如果 createMode 为 PointInTimeRestore,则此值是必需的。 如果 createMode 为 Restore,则此值是可选的。 指定将还原以创建新数据库的源数据库的时间点(ISO8601格式)。 必须大于或等于源数据库的最早RestoreDate 值。 |string | |sampleName |指示创建此数据库时要应用的示例架构的名称。 如果 createMode 不是默认值,则忽略此值。 DataWarehouse 版本不支持。 |“AdventureWorksLT”| |sourceDatabaseDeletionDate |有條件的。 如果 createMode 为 Restore,并且 sourceDatabaseId 是已删除的数据库的原始资源 ID(而不是其当前可还原的已删除数据库 ID),则此值是必需的。 指定删除数据库的时间。 |string | |sourceDatabaseId |有條件的。 如果 createMode 为 Copy、NonReadableSecondary、OnlineSecondary、PointInTimeRestore、Recovery 或 Restore,则此值是必需的。 指定源数据库的资源 ID。 如果 createMode 为 NonReadableSecondary 或 OnlineSecondary,则源数据库的名称必须与要创建新数据库的名称相同。 |string | |zoneRedundant |此数据库是否为区域冗余,这意味着此数据库的副本将分布在多个可用性区域。 |bool |
TrackedResourceTags
| Name | Description | Value |
|---|