Skip to content

Commit fc48077

Browse files
add Azure SQL service doc (#469)
Co-authored-by: Paolo Salvatori <leprino@hotmail.com>
1 parent 58ca1f4 commit fc48077

File tree

1 file changed

+329
-1
lines changed
  • src/content/docs/azure/services

1 file changed

+329
-1
lines changed
Lines changed: 329 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,339 @@
11
---
22
title: "SQL"
3-
description: API coverage for Microsoft.Sql in LocalStack for Azure.
3+
description: Get started with Azure SQL in LocalStack for Azure.
44
template: doc
55
---
66

77
import AzureFeatureCoverage from "../../../../components/feature-coverage/AzureFeatureCoverage";
88

9+
## Introduction
10+
11+
Azure SQL is a managed relational database service for building cloud-native applications with familiar SQL Server tooling.
12+
It supports creating logical servers, provisioning databases, and configuring operational features such as firewall access and retention policies.
13+
This makes it a common choice for transactional workloads and application backends. For more information, see [What is Azure SQL Database?](https://learn.microsoft.com/azure/azure-sql/database/sql-database-paas-overview).
14+
15+
LocalStack for Azure provides a local environment for building and testing applications that make use of Azure SQL Database.
16+
The supported APIs are listed in the [API Coverage](#api-coverage) section.
17+
18+
## Getting started
19+
20+
This guide is designed for users new to Azure SQL Database and assumes basic knowledge of the Azure CLI and `azlocal`. The following example creates a SQL server and database, configures firewall access, and defines retention and encryption settings.
21+
22+
Launch LocalStack using your preferred method. For more information, see [Introduction to LocalStack for Azure](/azure/getting-started/). Once the container is running, enable Azure CLI interception by running:
23+
24+
```bash
25+
azlocal start-interception
26+
```
27+
28+
This command points the `az` CLI away from the public Azure management REST API and toward the LocalStack for Azure emulator API.
29+
To revert this configuration, run:
30+
31+
```bash
32+
azlocal stop-interception
33+
```
34+
35+
This reconfigures the `az` CLI to send commands to the official Azure management REST API.
36+
37+
### Create a resource group
38+
39+
Create a resource group to contain your SQL resources:
40+
41+
```bash
42+
az group create --name rg-sql-demo --location westeurope
43+
```
44+
45+
```bash title="Output"
46+
{
47+
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-sql-demo",
48+
"location": "westeurope",
49+
"name": "rg-sql-demo",
50+
"properties": {
51+
"provisioningState": "Succeeded"
52+
},
53+
...
54+
}
55+
```
56+
57+
### Create and inspect a SQL server
58+
59+
Create a logical SQL server to host your databases:
60+
61+
```bash
62+
az sql server create \
63+
--name sqlsrvdoc85 \
64+
--resource-group rg-sql-demo \
65+
--location westeurope \
66+
--admin-user lsadmin \
67+
--admin-password "LocalstackSqlPassw0rd"
68+
```
69+
70+
```bash title="Output"
71+
{
72+
"administratorLogin": "lsadmin",
73+
...
74+
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-sql-demo/providers/Microsoft.Sql/servers/sqlsrvdoc85",
75+
...
76+
"location": "westeurope",
77+
...
78+
"name": "sqlsrvdoc85",
79+
...
80+
"type": "Microsoft.Sql/servers",
81+
...
82+
}
83+
```
84+
85+
Get the SQL server details to verify it is ready:
86+
87+
```bash
88+
az sql server show --name sqlsrvdoc85 --resource-group rg-sql-demo
89+
```
90+
91+
```bash title="Output"
92+
{
93+
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-sql-demo/providers/Microsoft.Sql/servers/sqlsrvdoc85",
94+
"name": "sqlsrvdoc85",
95+
"location": "westeurope",
96+
"state": "Ready",
97+
"publicNetworkAccess": "Enabled",
98+
"type": "Microsoft.Sql/servers",
99+
...
100+
}
101+
```
102+
103+
### Create and query a database
104+
105+
Create a database on the SQL server:
106+
107+
```bash
108+
az sql db create \
109+
--name sqldbdoc85 \
110+
--resource-group rg-sql-demo \
111+
--server sqlsrvdoc85 \
112+
--service-objective S0 \
113+
--compute-model Provisioned
114+
```
115+
116+
```bash title="Output"
117+
{
118+
...
119+
"catalogCollation": "SQL_Latin1_General_CP1_CI_AS",
120+
"collation": "SQL_Latin1_General_CP1_CI_AS",
121+
"creationDate": "2026-03-24T09:32:54.177434+00:00",
122+
"currentBackupStorageRedundancy": "Geo",
123+
"currentServiceObjectiveName": "GP_Gen5_2",
124+
"currentSku": {
125+
"capacity": 2,
126+
"family": "Gen5",
127+
"name": "S0",
128+
"size": null,
129+
"tier": "GeneralPurpose"
130+
},
131+
"databaseId": "62951a4b-e3b7-41ce-b7e7-1d4860801828",
132+
...
133+
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-sql-demo/providers/Microsoft.Sql/servers/sqlsrvdoc85/databases/sqldbdoc85",
134+
...
135+
"name": "sqldbdoc85",
136+
...
137+
"sku": {
138+
"capacity": 2,
139+
"family": "Gen5",
140+
"name": "S0",
141+
"size": null,
142+
"tier": "GeneralPurpose"
143+
},
144+
...
145+
"status": "Online",
146+
...
147+
}
148+
```
149+
150+
Verify the database status to confirm successful creation:
151+
152+
```bash
153+
az sql db show \
154+
--name sqldbdoc85 \
155+
--resource-group rg-sql-demo
156+
```
157+
158+
```bash title="Output"
159+
{
160+
...
161+
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-sql-demo/providers/Microsoft.Sql/servers/sqlsrvdoc85/databases/sqldbdoc85",
162+
...
163+
"name": "sqldbdoc85",
164+
...
165+
"status": "Online",
166+
...
167+
}
168+
```
169+
170+
List the databases on the SQL server:
171+
172+
```bash
173+
az sql db list \
174+
--resource-group rg-sql-demo \
175+
--server sqlsrvdoc85
176+
```
177+
178+
```bash title="Output"
179+
[
180+
{
181+
...
182+
"name": "master",
183+
...
184+
},
185+
{
186+
...
187+
"name": "sqldbdoc85",
188+
...
189+
}
190+
]
191+
```
192+
193+
### Add a firewall rule
194+
195+
Create a firewall rule to allow client access:
196+
197+
```bash
198+
az sql server firewall-rule create \
199+
--resource-group rg-sql-demo \
200+
--server sqlsrvdoc85 \
201+
--name AllowLocal \
202+
--start-ip-address 0.0.0.0 \
203+
--end-ip-address 255.255.255.255
204+
```
205+
206+
```bash title="Output"
207+
{
208+
"name": "AllowLocal",
209+
"startIpAddress": "0.0.0.0",
210+
"endIpAddress": "255.255.255.255",
211+
"type": "Microsoft.Sql/servers/firewallRules",
212+
...
213+
}
214+
```
215+
216+
### Configure transparent data encryption
217+
218+
Enable transparent data encryption on the database:
219+
220+
```bash
221+
az sql db tde set \
222+
--database sqldbdoc85 \
223+
--server sqlsrvdoc85 \
224+
--resource-group rg-sql-demo \
225+
--status Enabled
226+
```
227+
228+
```bash title="Output"
229+
{
230+
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-sql-demo/providers/Microsoft.Sql/servers/sqlsrvdoc85/databases/sqldbdoc85/transparentDataEncryption/current",
231+
"name": "current",
232+
"resourceGroup": "rg-sql-demo",
233+
...
234+
"state": "Enabled",
235+
"type": "Microsoft.Sql/servers/databases/transparentDataEncryption"
236+
}
237+
```
238+
239+
### Configure backup retention policies
240+
241+
Configure a short-term backup retention policy:
242+
243+
```bash
244+
az sql db str-policy set \
245+
--name sqldbdoc85 \
246+
--server sqlsrvdoc85 \
247+
--resource-group rg-sql-demo \
248+
--retention-days 7 \
249+
--diffbackup-hours 24
250+
```
251+
252+
```bash title="Output"
253+
{
254+
"diffBackupIntervalInHours": 24,
255+
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-sql-demo/providers/Microsoft.Sql/servers/sqlsrvdoc85/databases/sqldbdoc85/backupShortTermRetentionPolicies/default",
256+
"name": "default",
257+
"resourceGroup": "rg-sql-demo",
258+
"retentionDays": 7,
259+
"type": "Microsoft.Sql/servers/databases/backupShortTermRetentionPolicies"
260+
}
261+
```
262+
263+
Configure a long-term backup retention policy:
264+
265+
```bash
266+
az sql db ltr-policy set \
267+
--name sqldbdoc85 \
268+
--server sqlsrvdoc85 \
269+
--resource-group rg-sql-demo \
270+
--weekly-retention "P4W" \
271+
--monthly-retention "P12M" \
272+
--yearly-retention "P5Y" \
273+
--week-of-year 16
274+
```
275+
276+
```bash title="Output"
277+
{
278+
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-sql-demo/providers/Microsoft.Sql/servers/sqlsrvdoc85/databases/sqldbdoc85/backupLongTermRetentionPolicies/default",
279+
"monthlyRetention": "P12M",
280+
"name": "default",
281+
"resourceGroup": "rg-sql-demo",
282+
"timeBasedImmutability": null,
283+
"timeBasedImmutabilityMode": null,
284+
"type": "Microsoft.Sql/servers/databases/backupLongTermRetentionPolicies",
285+
"weekOfYear": 16,
286+
"weeklyRetention": "P4W",
287+
"yearlyRetention": "P5Y"
288+
}
289+
```
290+
291+
## Features
292+
293+
The Azure SQL emulator supports the following features:
294+
295+
- **Server lifecycle management**: Create, update, delete, get, and list logical SQL servers.
296+
- **Database CRUD**: Create, update, delete, get, list, and rename databases on a logical server.
297+
- **Firewall rules**: Create, update, delete, get, and list server-level firewall rules.
298+
- **Transparent data encryption (TDE)**: Create or update, get, and list TDE configurations per database.
299+
- **Short-term backup retention policies**: Create or update, get, update, and list short-term retention policies per database.
300+
- **Long-term backup retention policies**: Create or update, get, and list long-term retention policies per database.
301+
- **Database security alert policies**: Create or update, get, and list security alert policies per database.
302+
- **Server connection policies**: Create or update, get, and list connection policies per server.
303+
- **SQL vulnerability assessments**: Create or update, get, and list vulnerability assessment settings per server.
304+
- **Database schema introspection**: Get and list schemas, tables, and columns by querying the live SQL Server instance.
305+
- **Server name availability check**: Check whether a server name is available for use.
306+
- **Restorable dropped databases**: Get and list restorable dropped databases (stub: always returns an empty list).
307+
- **Replication links**: List replication links for a database (stub: always returns an empty list).
308+
- **Asynchronous provisioning**: Server and database creation use async operations with polling headers, matching real Azure behavior.
309+
310+
## Limitations
311+
312+
- **No data persistence across restarts**: SQL Server containers are ephemeral. All databases, schemas, and data are lost when the LocalStack emulator is stopped or restarted.
313+
- **Backup retention policies are metadata-only**: Short-term and long-term retention policies are stored but no actual backup or restore operations are performed.
314+
- **Transparent data encryption is metadata-only**: TDE settings are stored but no actual encryption is applied to the database files.
315+
- **Security alert policies are metadata-only**: Alert policies are stored but do not trigger notifications or log monitoring.
316+
- **Vulnerability assessments are metadata-only**: Assessment settings are stored but no scans are executed.
317+
- **Server connection policies are metadata-only**: Connection policies are stored but do not affect network behavior.
318+
- **Replication links always empty**: No geo-replication or active replication is supported.
319+
- **Elastic pools, failover groups, and geo-replication are not supported**: These features are not implemented.
320+
- **MSSQL EULA acceptance required**: The `MSSQL_ACCEPT_EULA` environment variable must be set to `Y` before creating any SQL server.
321+
322+
## Configuration
323+
324+
The behavior of the Azure SQL emulator can be customized using the environment variables listed below.
325+
326+
| **Variable** | **Description** | **Type** | **Default** |
327+
| -------------------------------------- | --------------------------------------------------------------------------------------------------------- | -------- | ----------- |
328+
| `MSSQL_ACCEPT_EULA` | Accept the Microsoft SQL Server End-User License Agreement. Must be set to `Y` to create SQL servers. | String | (unset) |
329+
| `ALLOW_MULTIPLE_SQL_SERVER_DEPLOYMENTS`| Allow provisioning more than one SQL Server Docker container. Set to `1` or `true` to enable. | Boolean | `0` |
330+
331+
## Samples
332+
333+
The following sample demonstrates how to use Azure SQL Database with LocalStack for Azure:
334+
335+
- [Web App and SQL Database](https://github.com/localstack/localstack-azure-samples/blob/main/samples/web-app-sql-database/python/)
336+
9337
## API Coverage
10338

11339
<AzureFeatureCoverage service="Microsoft.Sql" client:load />

0 commit comments

Comments
 (0)