- Latest
- 2026-08-01-預覽
- 2025-08-01-預覽
- 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 已驗證的模組
以下的 Azure 已驗證模組 可用於部署此資源類型。
| 模組 | Description |
|---|---|
| Azure SQL Database | AVM Resource Module for Azure SQL Database |
Azure 快速入門範例
以下的 Azure 快速啟動範本包含部署此資源類型的Bicep範例。
| Bicep檔案 | Description |
|---|---|
| Azure SQL Server 並以 Auditing 寫入 Log Analytics | 此範本允許您部署啟用 Auditing 的 Azure SQL 伺服器,將稽核日誌寫入 Log Analytics(OMS 工作空間) |
| 建立SQL Server與資料庫 | 此範本可讓您建立 SQL Database 和 Server。 |
| 專用 SQL 池,具備透明加密 | 建立 SQL Server 及專用 SQL 池(前稱 SQL DW),並具備 透明資料加密 功能。 |
| 建立一個啟用 ADLS Gen 2 的 Azure 儲存帳號,一個 Azure Data Factory 實例,並連結服務給該儲存帳號(若部署則是 Azure SQL Database),以及一個 Azure Databricks 實例。 部署範本和 ADF 實例受控識別的使用者 AAD 身分識別,將會在記憶體帳戶上授與記憶體 Blob 數據參與者角色。 也有部署 Azure Key Vault 實例、Azure SQL Database 和 Azure Event Hub(用於串流使用案例)的選項。 當 Azure Key Vault 部署時,部署該範本的使用者的資料工廠管理身份與 AAD 身份會被授予 金鑰保存庫 Secrets 使用者角色。 | |
| 私有端點範例 | 此範本展示了如何建立指向 Azure SQL Server 的私有端點 |
| 使用 SQL Database 布建 Web 應用程式 | 此範本會布建 Web 應用程式、SQL Database、自動調整設定、警示規則和 App Insights。 它會在網頁應用程式中為資料庫配置一個 連接字串。 |
| 使用 Azure SQL 在 Linux 上 Sonarqube Docker Web 應用程式 | 此範本會將 Sonarqube 部署於 Azure App 服務 網頁應用 Linux 容器中,使用官方 Sonarqube 映像檔,並由 Azure SQL Server 支援。 |
| Web 應用程式,採用管理身份、SQL Server 與 ΑΙ | 簡單範例,用於部署 Azure 基礎設施以支援應用程式 + data + managed identity + monitoring |
資源格式
創造一個 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 |
|---|---|---|
| 位置 | 資源位置。 | 字串 (必要) |
| name | 資源名稱 | 字串 (必要) |
| 父代 | 在 Bicep 中,你可以指定子資源的父資源。 只有在父資源外部宣告子資源時,才需要新增這個屬性。 如需詳細資訊,請參閱 父資源外部的子資源。 |
類型的資源符號名稱:伺服器 |
| properties | 代表資源的屬性。 | DatabaseProperties |
| tags | 資源標籤 | 標記名稱和值的字典。 請參閱範本中的 標籤 |
DatabaseProperties
|名稱 |描述 |值 | |---- |----------- |------------ | |定序 |資料庫的定序。 如果 createMode 不是 Default,則會忽略此值。 |string | |createMode |指定資料庫建立模式。
默認值:定期建立資料庫。
複製:建立資料庫做為現有資料庫的複本。 sourceDatabaseId 必須指定為源資料庫的資源標識碼。
OnlineSecondary/NonReadableSecondary:建立資料庫做為現有資料庫的次要複本(可讀取或不可讀取的)。 sourceDatabaseId 必須指定為現有主資料庫的資源標識碼。
PointInTimeRestore:藉由還原現有資料庫的時間點備份來建立資料庫。 sourceDatabaseId 必須指定為現有資料庫的資源標識符,而且必須指定 restorePointInTime。
復原:藉由還原異地復寫備份來建立資料庫。 sourceDatabaseId 必須指定為要還原的可復原資料庫資源標識符。
還原:藉由還原已刪除資料庫的備份來建立資料庫。 必須指定sourceDatabaseId。 如果 sourceDatabaseId 是資料庫的原始資源識別碼,則必須指定 sourceDatabaseDeletionDate。 否則,sourceDatabaseId 必須是可還原的卸除資料庫資源標識符,而且會忽略 sourceDatabaseDeletionDate。 restorePointInTime 也可以指定為從先前的時間點還原。
RestoreLongTermRetentionBackup:從長期保留保存庫還原來建立資料庫。 recoveryServicesRecoveryPointResourceId 必須指定為恢復點資源標識符。
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 不是 Default,則會忽略此值。 DataWarehouse 版本不支援。 |'AdventureWorksLT' | |sourceDatabaseDeletionDate |有條件的。 如果 createMode 為 Restore,且 sourceDatabaseId 是已刪除的資料庫原始資源標識符,當它存在時,它就會成為已刪除的資料庫標識碼(與其目前可還原的已卸除資料庫標識符相反),則需要此值。 指定刪除資料庫的時間。 |string | |sourceDatabaseId |有條件的。 如果 createMode 為 Copy、NonReadableSecondary、OnlineSecondary、PointInTimeRestore、Recovery 或 Restore,則需要此值。 指定源資料庫的資源識別碼。 如果 createMode 為 NonReadableSecondary 或 OnlineSecondary,源資料庫的名稱必須與所建立的新資料庫相同。 |string | |zoneRedundant |此資料庫是否為區域備援,這表示此資料庫的複本會分散到多個可用性區域。 |bool |
TrackedResourceTags
| Name | Description | Value |
|---|
ARM 樣本資源定義
伺服器/資料庫資源類型可以使用目標作業來部署:
使用範例
Azure Quickstart templates
以下的 Azure 快速起始範本部署此資源類型。
| Template | Description |
|---|---|
|
Azure SQL Server 並以 Auditing 寫入 Log Analytics |
此範本允許您部署啟用 Auditing 的 Azure SQL 伺服器,將稽核日誌寫入 Log Analytics(OMS 工作空間) |
|
建立SQL Server與資料庫 |
此範本可讓您建立 SQL Database 和 Server。 |
|
專用 SQL 池,具備透明加密 |
建立 SQL Server 及專用 SQL 池(前稱 SQL DW),並具備 透明資料加密 功能。 |
|
部署新的 SQL 彈性池 |
此範本允許您部署新的 SQL 彈性池,並附帶其新關聯的 SQL Server 及可指派的新 SQL 資料庫。 |
| 建立一個啟用 ADLS Gen 2 的 Azure 儲存帳號,一個 Azure Data Factory 實例,並連結服務給該儲存帳號(若部署則是 Azure SQL Database),以及一個 Azure Databricks 實例。 部署範本和 ADF 實例受控識別的使用者 AAD 身分識別,將會在記憶體帳戶上授與記憶體 Blob 數據參與者角色。 也有部署 Azure Key Vault 實例、Azure SQL Database 和 Azure Event Hub(用於串流使用案例)的選項。 當 Azure Key Vault 部署時,部署該範本的使用者的資料工廠管理身份與 AAD 身份會被授予 金鑰保存庫 Secrets 使用者角色。 | |
|
HDInsight 搭配自訂的 Ambari + Hive Metastore 資料庫,VNET |
此範本可讓您使用新的 SQL DB,在現有的虛擬網路中建立 HDInsight 叢集,以作為自訂 Ambari DB 和 Hive 中繼存放區。 您必須擁有現有的 SQL Sever、記憶體帳戶和 VNET。 |
|
私有端點範例 |
此範本展示了如何建立指向 Azure SQL Server 的私有端點 |
|
使用 SQL Database 布建 Web 應用程式 |
此範本會布建 Web 應用程式、SQL Database、自動調整設定、警示規則和 App Insights。 它會在網頁應用程式中為資料庫配置一個 連接字串。 |
|
遠端桌面 具備高可用性的服務 |
此 ARM 範本範例程式碼將部署一個 遠端桌面服務 2019 會話集合實驗室,且具備高可用性。 目標是部署一個完全冗餘且高度可用的 遠端桌面 服務解決方案,使用 Windows Server 2019。 |
| 使用 Azure SQL 在 Linux 上 Sonarqube Docker Web 應用程式 |
此範本會將 Sonarqube 部署於 Azure App 服務 網頁應用 Linux 容器中,使用官方 Sonarqube 映像檔,並由 Azure SQL Server 支援。 |
|
Web 應用程式,採用管理身份、SQL Server 與 ΑΙ |
簡單範例,用於部署 Azure 基礎設施以支援應用程式 + data + managed identity + monitoring |
|
WebApp 正在消耗Azure SQL私有端點 |
此範本展示了如何建立一個使用指向 Azure SQL Server 的私有端點的網頁應用程式 |
資源格式
創造一個 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' |
| 位置 | 資源位置。 | 字串 (必要) |
| name | 資源名稱 | 字串 (必要) |
| properties | 代表資源的屬性。 | DatabaseProperties |
| tags | 資源標籤 | 標記名稱和值的字典。 請參閱範本中的 標籤 |
| 型別 | 資源類型 | 「Microsoft。SQL/伺服器/資料庫」 |
DatabaseProperties
|名稱 |描述 |值 | |---- |----------- |------------ | |定序 |資料庫的定序。 如果 createMode 不是 Default,則會忽略此值。 |string | |createMode |指定資料庫建立模式。
默認值:定期建立資料庫。
複製:建立資料庫做為現有資料庫的複本。 sourceDatabaseId 必須指定為源資料庫的資源標識碼。
OnlineSecondary/NonReadableSecondary:建立資料庫做為現有資料庫的次要複本(可讀取或不可讀取的)。 sourceDatabaseId 必須指定為現有主資料庫的資源標識碼。
PointInTimeRestore:藉由還原現有資料庫的時間點備份來建立資料庫。 sourceDatabaseId 必須指定為現有資料庫的資源標識符,而且必須指定 restorePointInTime。
復原:藉由還原異地復寫備份來建立資料庫。 sourceDatabaseId 必須指定為要還原的可復原資料庫資源標識符。
還原:藉由還原已刪除資料庫的備份來建立資料庫。 必須指定sourceDatabaseId。 如果 sourceDatabaseId 是資料庫的原始資源識別碼,則必須指定 sourceDatabaseDeletionDate。 否則,sourceDatabaseId 必須是可還原的卸除資料庫資源標識符,而且會忽略 sourceDatabaseDeletionDate。 restorePointInTime 也可以指定為從先前的時間點還原。
RestoreLongTermRetentionBackup:從長期保留保存庫還原來建立資料庫。 recoveryServicesRecoveryPointResourceId 必須指定為恢復點資源標識符。
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 不是 Default,則會忽略此值。 DataWarehouse 版本不支援。 |'AdventureWorksLT' | |sourceDatabaseDeletionDate |有條件的。 如果 createMode 為 Restore,且 sourceDatabaseId 是已刪除的資料庫原始資源標識符,當它存在時,它就會成為已刪除的資料庫標識碼(與其目前可還原的已卸除資料庫標識符相反),則需要此值。 指定刪除資料庫的時間。 |string | |sourceDatabaseId |有條件的。 如果 createMode 為 Copy、NonReadableSecondary、OnlineSecondary、PointInTimeRestore、Recovery 或 Restore,則需要此值。 指定源資料庫的資源識別碼。 如果 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 |
|---|---|---|
| 位置 | 資源位置。 | 字串 (必要) |
| name | 資源名稱 | 字串 (必要) |
| parent_id | 此資源為父系之資源的標識碼。 | 類型資源的標識碼:伺服器 |
| properties | 代表資源的屬性。 | DatabaseProperties |
| tags | 資源標籤 | 標記名稱和值的字典。 |
| 型別 | 資源類型 | 「Microsoft。Sql/servers/databases@2014-04-01” |
DatabaseProperties
|名稱 |描述 |值 | |---- |----------- |------------ | |定序 |資料庫的定序。 如果 createMode 不是 Default,則會忽略此值。 |string | |createMode |指定資料庫建立模式。
默認值:定期建立資料庫。
複製:建立資料庫做為現有資料庫的複本。 sourceDatabaseId 必須指定為源資料庫的資源標識碼。
OnlineSecondary/NonReadableSecondary:建立資料庫做為現有資料庫的次要複本(可讀取或不可讀取的)。 sourceDatabaseId 必須指定為現有主資料庫的資源標識碼。
PointInTimeRestore:藉由還原現有資料庫的時間點備份來建立資料庫。 sourceDatabaseId 必須指定為現有資料庫的資源標識符,而且必須指定 restorePointInTime。
復原:藉由還原異地復寫備份來建立資料庫。 sourceDatabaseId 必須指定為要還原的可復原資料庫資源標識符。
還原:藉由還原已刪除資料庫的備份來建立資料庫。 必須指定sourceDatabaseId。 如果 sourceDatabaseId 是資料庫的原始資源識別碼,則必須指定 sourceDatabaseDeletionDate。 否則,sourceDatabaseId 必須是可還原的卸除資料庫資源標識符,而且會忽略 sourceDatabaseDeletionDate。 restorePointInTime 也可以指定為從先前的時間點還原。
RestoreLongTermRetentionBackup:從長期保留保存庫還原來建立資料庫。 recoveryServicesRecoveryPointResourceId 必須指定為恢復點資源標識符。
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 不是 Default,則會忽略此值。 DataWarehouse 版本不支援。 |'AdventureWorksLT' | |sourceDatabaseDeletionDate |有條件的。 如果 createMode 為 Restore,且 sourceDatabaseId 是已刪除的資料庫原始資源標識符,當它存在時,它就會成為已刪除的資料庫標識碼(與其目前可還原的已卸除資料庫標識符相反),則需要此值。 指定刪除資料庫的時間。 |string | |sourceDatabaseId |有條件的。 如果 createMode 為 Copy、NonReadableSecondary、OnlineSecondary、PointInTimeRestore、Recovery 或 Restore,則需要此值。 指定源資料庫的資源識別碼。 如果 createMode 為 NonReadableSecondary 或 OnlineSecondary,源資料庫的名稱必須與所建立的新資料庫相同。 |string | |zoneRedundant |此資料庫是否為區域備援,這表示此資料庫的複本會分散到多個可用性區域。 |bool |
TrackedResourceTags
| Name | Description | Value |
|---|