Skip to content

Commit b39bdc5

Browse files
authored
Merge pull request #96950 from mumian/1121-secure-artifacts
1121 secure artifacts
2 parents 472ddc8 + 489a8bc commit b39bdc5

File tree

3 files changed

+126
-48
lines changed

3 files changed

+126
-48
lines changed
Loading

articles/azure-resource-manager/resource-manager-tutorial-deploy-sql-extensions-bacpac.md

Lines changed: 126 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
---
1+
---
22
title: Import SQL BACPAC files with templates
33
description: Learn how to use SQL Database extension to import SQL BACPAC files with Azure Resource Manager templates.
44
author: mumian
5-
ms.date: 04/08/2019
5+
ms.date: 11/21/2019
66
ms.topic: tutorial
77
ms.author: jgao
88
---
99

1010
# Tutorial: Import SQL BACPAC files with Azure Resource Manager templates
1111

12-
Learn how to use Azure SQL Database extensions to import a BACPAC file with Azure Resource Manager templates. Deployment artifacts are any files, in addition to the main template file that are needed to complete a deployment. The BACPAC file is an artifact. In this tutorial, you create a template to deploy an Azure SQL Server, a SQL Database, and import a BACPAC file. For information about deploying Azure virtual machine extensions using Azure Resource Manager templates, see [# Tutorial: Deploy virtual machine extensions with Azure Resource Manager templates](./resource-manager-tutorial-deploy-vm-extensions.md).
12+
Learn how to use Azure SQL Database extensions to import a BACPAC file with Azure Resource Manager templates. Deployment artifacts are any files, in addition to the main template files that are needed to complete a deployment. The BACPAC file is an artifact. In this tutorial, you create a template to deploy an Azure SQL Server, a SQL Database, and import a BACPAC file. For information about deploying Azure virtual machine extensions using Azure Resource Manager templates, see [# Tutorial: Deploy virtual machine extensions with Azure Resource Manager templates](./resource-manager-tutorial-deploy-vm-extensions.md).
1313

1414
This tutorial covers the following tasks:
1515

@@ -32,22 +32,68 @@ To complete this article, you need:
3232
```azurecli-interactive
3333
openssl rand -base64 32
3434
```
35+
3536
Azure Key Vault is designed to safeguard cryptographic keys and other secrets. For more information, see [Tutorial: Integrate Azure Key Vault in Resource Manager Template deployment](./resource-manager-tutorial-use-key-vault.md). We also recommend you to update your password every three months.
3637
3738
## Prepare a BACPAC file
3839
39-
A BACPAC file is shared in [Github](https://github.com/Azure/azure-docs-json-samples/raw/master/tutorial-sql-extension/SQLDatabaseExtension.bacpac). To create your own, see [Export an Azure SQL database to a BACPAC file](../sql-database/sql-database-export.md). If you choose to publish the file to your own location, you must update the template later in the tutorial.
40+
A BACPAC file is shared in [GitHub](https://github.com/Azure/azure-docs-json-samples/raw/master/tutorial-sql-extension/SQLDatabaseExtension.bacpac). To create your own, see [Export an Azure SQL database to a BACPAC file](../sql-database/sql-database-export.md). If you choose to publish the file to your own location, you must update the template later in the tutorial.
41+
42+
The BACPAC file must be stored in an Azure Storage account before it can be imported using Resource Manager template.
43+
44+
1. Open the [Cloud shell](https://shell.azure.com).
45+
1. Select **Upload/Download files**, and then select **Upload**.
46+
1. Specify the following URL and then select **Open**.
47+
48+
```url
49+
https://github.com/Azure/azure-docs-json-samples/raw/master/tutorial-sql-extension/SQLDatabaseExtension.bacpac
50+
```
51+
52+
1. Copy and paste the following PowerShell script into the shell window.
53+
54+
```azurepowershell-interactive
55+
$projectName = Read-Host -Prompt "Enter a project name that is used to generate Azure resource names"
56+
$location = Read-Host -Prompt "Enter the location (i.e. centralus)"
57+
58+
$resourceGroupName = "${projectName}rg"
59+
$storageAccountName = "${projectName}store"
60+
$containerName = "bacpacfiles"
61+
$bacpacFile = "$HOME/SQLDatabaseExtension.bacpac"
62+
$blobName = "SQLDatabaseExtension.bacpac"
63+
64+
New-AzResourceGroup -Name $resourceGroupName -Location $location
65+
$storageAccount = New-AzStorageAccount -ResourceGroupName $resourceGroupName `
66+
-Name $storageAccountName `
67+
-SkuName Standard_LRS `
68+
-Location $location
69+
$storageAccountKey = (Get-AzStorageAccountKey -ResourceGroupName $resourceGroupName `
70+
-Name $storageAccountName).Value[0]
71+
72+
New-AzStorageContainer -Name $containerName -Context $storageAccount.Context
73+
74+
Set-AzStorageBlobContent -File $bacpacFile `
75+
-Container $containerName `
76+
-Blob $blobName `
77+
-Context $storageAccount.Context
78+
79+
Write-Host "The storage account key is $storageAccountKey"
80+
Write-Host "The BACPAC file URL is https://$storageAccountName.blob.core.windows.net/$containerName/$blobName"
81+
Write-Host "Press [ENTER] to continue ..."
82+
```
83+
84+
1. Write down storage account key and the BACPAC file URL. You need these values when you deploy the template.
4085
4186
## Open a Quickstart template
4287
43-
The template used in this tutorial is stored in [Github](https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/tutorial-sql-extension/azuredeploy.json).
88+
The template used in this tutorial is stored in [GitHub](https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/tutorial-sql-extension/azuredeploy.json).
4489
4590
1. From Visual Studio Code, select **File**>**Open File**.
4691
2. In **File name**, paste the following URL:
4792
4893
```url
4994
https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/tutorial-sql-extension/azuredeploy.json
5095
```
96+
5197
3. Select **Open** to open the file.
5298
5399
There are three resources defined in the template:
@@ -61,89 +107,121 @@ The template used in this tutorial is stored in [Github](https://raw.githubuserc
61107
62108
## Edit the template
63109
64-
Add two additional resources to the template.
65-
66-
* To allow the SQL database extension to import BACPAC files, you need to allow access to Azure services. Add the following JSON to the SQL server definition:
110+
1. Add two more parameters at the end of the **parameters** section to set the storage account key and the BACPAC URL:
67111
68112
```json
69-
{
70-
"type": "firewallrules",
71-
"name": "AllowAllAzureIps",
72-
"location": "[parameters('location')]",
73-
"apiVersion": "2015-05-01-preview",
74-
"dependsOn": [
113+
"storageAccountKey": {
114+
"type":"string",
115+
"metadata":{
116+
"description": "Specifies the key of the storage account where the BACPAC file is stored."
117+
}
118+
},
119+
"bacpacUrl": {
120+
"type":"string",
121+
"metadata":{
122+
"description": "Specifies the URL of the BACPAC file."
123+
}
124+
}
125+
```
126+
127+
Add a comma after **adminPassword**. To format the JSON file from VS Code, press **[SHIFT]+[ALT]+F**.
128+
129+
See [Prepare a BACPAC file](#prepare-a-bacpac-file) about getting these two values.
130+
131+
1. Add two additional resources to the template.
132+
133+
* To allow the SQL database extension to import BACPAC files, you need to allow traffic from Azure services. Add the following firewall rule definition under the SQL server definition:
134+
135+
```json
136+
{
137+
"type": "firewallrules",
138+
"apiVersion": "2015-05-01-preview",
139+
"name": "AllowAllAzureIps",
140+
"location": "[parameters('location')]",
141+
"dependsOn": [
75142
"[variables('databaseServerName')]"
76-
],
77-
"properties": {
143+
],
144+
"properties": {
78145
"startIpAddress": "0.0.0.0",
79146
"endIpAddress": "0.0.0.0"
147+
}
80148
}
81-
}
82-
```
149+
```
83150
84-
The template shall look like:
151+
The template shall look like:
85152
86-
![Azure Resource Manager deploy sql extensions BACPAC](./media/resource-manager-tutorial-deploy-sql-extensions-bacpac/resource-manager-tutorial-deploy-sql-extensions-bacpac-firewall.png)
153+
![Azure Resource Manager deploy sql extensions BACPAC](./media/resource-manager-tutorial-deploy-sql-extensions-bacpac/resource-manager-tutorial-deploy-sql-extensions-bacpac-firewall.png)
87154
88-
* Add a SQL Database extension resource to the database definition with the following JSON:
155+
* Add a SQL Database extension resource to the database definition with the following JSON:
89156
90-
```json
91-
"resources": [
92-
{
93-
"name": "Import",
94-
"type": "extensions",
95-
"apiVersion": "2014-04-01",
96-
"dependsOn": [
157+
```json
158+
"resources": [
159+
{
160+
"type": "extensions",
161+
"apiVersion": "2014-04-01",
162+
"name": "Import",
163+
"dependsOn": [
97164
"[resourceId('Microsoft.Sql/servers/databases', variables('databaseServerName'), variables('databaseName'))]"
98-
],
99-
"properties": {
100-
"storageKeyType": "SharedAccessKey",
101-
"storageKey": "?",
102-
"storageUri": "https://github.com/Azure/azure-docs-json-samples/raw/master/tutorial-sql-extension/SQLDatabaseExtension.bacpac",
165+
],
166+
"properties": {
167+
"storageKeyType": "StorageAccessKey",
168+
"storageKey": "[parameters('storageAccountKey')]",
169+
"storageUri": "[parameters('bacpacUrl')]",
103170
"administratorLogin": "[variables('databaseServerAdminLogin')]",
104171
"administratorLoginPassword": "[variables('databaseServerAdminLoginPassword')]",
105-
"operationMode": "Import",
172+
"operationMode": "Import"
173+
}
106174
}
107-
}
108-
]
109-
```
175+
]
176+
```
110177
111-
The template shall look like:
178+
The template shall look like:
112179
113-
![Azure Resource Manager deploy sql extensions BACPAC](./media/resource-manager-tutorial-deploy-sql-extensions-bacpac/resource-manager-tutorial-deploy-sql-extensions-bacpac.png)
180+
![Azure Resource Manager deploy sql extensions BACPAC](./media/resource-manager-tutorial-deploy-sql-extensions-bacpac/resource-manager-tutorial-deploy-sql-extensions-bacpac.png)
114181
115-
To understand the resource definition, see the [SQL Database extension reference](https://docs.microsoft.com/azure/templates/microsoft.sql/servers/databases/extensions). The following are some important elements:
182+
To understand the resource definition, see the [SQL Database extension reference](https://docs.microsoft.com/azure/templates/microsoft.sql/servers/databases/extensions). The following are some important elements:
116183
117-
* **dependsOn**: The extension resource must be created after the SQL database has been created.
118-
* **storageKeyType**: The type of the storage key to use. The value can be either `StorageAccessKey` or `SharedAccessKey`. Because the provided BACPAC file is shared on an Azure Storage account with public access, `SharedAccessKey' is used here.
119-
* **storageKey**: The storage key to use. If storage key type is SharedAccessKey, it must be preceded with a "?."
120-
* **storageUri**: The storage uri to use. If you choose not to use the BACPAC file provided, you need to update the values.
121-
* **administratorLoginPassword**: The password of the SQL administrator. Use a generated password. See [Prerequisites](#prerequisites).
184+
* **dependsOn**: The extension resource must be created after the SQL database has been created.
185+
* **storageKeyType**: Specify the type of the storage key to use. The value can be either `StorageAccessKey` or `SharedAccessKey`. Use `StorageAccessKey` in this tutorial.
186+
* **storageKey**: Specify the key for the storage account where the BACPAC file is stored. If storage key type is SharedAccessKey, it must be preceded with a "?"
187+
* **storageUri**: Specify the URL of the BACPAC file stored in a storage account.
188+
* **administratorLoginPassword**: The password of the SQL administrator. Use a generated password. See [Prerequisites](#prerequisites).
122189
123190
## Deploy the template
124191
125192
[!INCLUDE [updated-for-az](../../includes/updated-for-az.md)]
126193
127194
Refer to the [Deploy the template](./resource-manager-tutorial-create-templates-with-dependent-resources.md#deploy-the-template) section for the deployment procedure. Use the following PowerShell deployment script instead:
128195
129-
```azurepowershell
130-
$resourceGroupName = Read-Host -Prompt "Enter the Resource Group name"
196+
```azurepowershell-interactive
197+
$projectName = Read-Host -Prompt "Enter a project name that is used to generate Azure resource names"
131198
$location = Read-Host -Prompt "Enter the location (i.e. centralus)"
132199
$adminUsername = Read-Host -Prompt "Enter the SQL admin username"
133200
$adminPassword = Read-Host -Prompt "Enter the admin password" -AsSecureString
201+
$storageAccountKey = Read-Host -Prompt "Enter the storage account key"
202+
$bacpacUrl = Read-Host -Prompt "Enter the URL of the BACPAC file"
203+
$resourceGroupName = "${projectName}rg"
134204
135205
New-AzResourceGroup -Name $resourceGroupName -Location $location
136206
New-AzResourceGroupDeployment `
137207
-ResourceGroupName $resourceGroupName `
138208
-adminUser $adminUsername `
139209
-adminPassword $adminPassword `
140-
-TemplateFile "$HOME/azuredeploy.json"
210+
-TemplateFile "$HOME/azuredeploy.json" `
211+
-storageAccountKey $storageAccountKey `
212+
-bacpacUrl $bacpacUrl
213+
214+
Write-Host "Press [ENTER] to continue ..."
141215
```
142216

217+
Consider using the same project name as you used when you prepared the bacpac file, so that all the resources are stored within the same resource group. It is easier for managing resource, such as cleaning up the resources. If you use the same project name, you can either remove the **New-AzResourceGroup** command from the script, or answer y or n when you are asked whether you want to update the existing resource group.
218+
143219
Use a generated password. See [Prerequisites](#prerequisites).
144220

145221
## Verify the deployment
146222

223+
To access the SQL server from your client computer, you need to add an additional firewall rule. For more information, see [Create and manage IP firewall rules](../sql-database/sql-database-firewall-configure.md#create-and-manage-ip-firewall-rules).
224+
147225
In the portal, select the SQL database from the newly deployed resource group. Select **Query editor (preview)**, and then enter the administrator credentials. You shall see two tables imported into the database:
148226

149227
![Azure Resource Manager deploy sql extensions BACPAC](./media/resource-manager-tutorial-deploy-sql-extensions-bacpac/resource-manager-tutorial-deploy-sql-extensions-bacpac-query-editor.png)

0 commit comments

Comments
 (0)