Skip to content

Commit 83d86b4

Browse files
authored
Merge pull request #208199 from mumian/0816-iot-dps
[Azure IoT DPS] - bicep quickstart
2 parents dd26b25 + 5f9f906 commit 83d86b4

File tree

2 files changed

+198
-0
lines changed

2 files changed

+198
-0
lines changed
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
---
2+
title: Quickstart - Create an Azure IoT Hub Device Provisioning Service (DPS) using Bicep
3+
description: Azure quickstart - Learn how to create an Azure IoT Hub Device Provisioning Service (DPS) using Bicep.
4+
ms.author: jgao
5+
ms.date: 08/17/2022
6+
ms.topic: quickstart
7+
ms.service: iot-dps
8+
services: iot-dps
9+
author: mumian
10+
ms.custom: mvc, subject-bicepqs
11+
---
12+
13+
# Quickstart: Set up the IoT Hub Device Provisioning Service (DPS) with Bicep
14+
15+
You can use a [Bicep](../azure-resource-manager/bicep/overview.md) file to programmatically set up the Azure cloud resources necessary for provisioning your devices. These steps show how to create an IoT hub and a new IoT Hub Device Provisioning Service instance with a Bicep file. The IoT Hub is also linked to the DPS resource using the Bicep file. This linking allows the DPS resource to assign devices to the hub based on allocation policies you configure.
16+
17+
[!INCLUDE [About Bicep](../../includes/resource-manager-quickstart-bicep-introduction.md)]
18+
19+
This quickstart uses [Azure PowerShell](../azure-resource-manager/bicep/deploy-powershell.md), and the [Azure CLI](../azure-resource-manager/bicep/deploy-cli.md) to perform the programmatic steps necessary to create a resource group and deploy the Bicep file, but you can easily use .NET, Ruby, or other programming languages to perform these steps and deploy your Bicep file.
20+
21+
## Prerequisites
22+
23+
[!INCLUDE [quickstarts-free-trial-note](../../includes/quickstarts-free-trial-note.md)]
24+
25+
[!INCLUDE [azure-cli-prepare-your-environment-no-header.md](../../includes/azure-cli-prepare-your-environment-no-header.md)]
26+
27+
[!INCLUDE [azure-powershell-requirements-no-header.md](../../includes/azure-powershell-requirements-no-header.md)]
28+
29+
## Review the Bicep file
30+
31+
The Bicep file used in this quickstart is from [Azure Quickstart Templates](https://azure.microsoft.com/resources/templates/iothub-device-provisioning/).
32+
33+
> [!NOTE]
34+
> Currently there is no Bicep file support for creating enrollments with new DPS resources. This is a common and understood request that is being considered for implementation.
35+
36+
:::code language="bicep" source="~/quickstart-templates/quickstarts/microsoft.devices/iothub-device-provisioning/main.bicep":::
37+
38+
Two Azure resources are defined in the Bicep file above:
39+
40+
* [**Microsoft.Devices/iothubs**](/azure/templates/microsoft.devices/iothubs): Creates a new Azure IoT Hub.
41+
* [**Microsoft.Devices/provisioningservices**](/azure/templates/microsoft.devices/provisioningservices): Creates a new Azure IoT Hub Device Provisioning Service with the new IoT Hub already linked to it.
42+
43+
Save a copy of the Bicep file locally as **main.bicep**.
44+
45+
## Deploy the Bicep file
46+
47+
Sign in to your Azure account and select your subscription.
48+
49+
1. To log in Azure at the command prompt:
50+
51+
# [CLI](#tab/CLI)
52+
53+
```azurecli
54+
az login
55+
```
56+
57+
# [PowerShell](#tab/PowerShell)
58+
59+
```azurepowershell
60+
Connect-AzAccount
61+
```
62+
63+
---
64+
65+
Follow the instructions to authenticate using the code and sign in to your Azure account through a web browser.
66+
67+
1. If you have multiple Azure subscriptions, signing in to Azure grants you access to all the Azure accounts associated with your credentials.
68+
69+
# [CLI](#tab/CLI)
70+
71+
```azurecli
72+
az account list -o table
73+
```
74+
75+
# [PowerShell](#tab/PowerShell)
76+
77+
```azurepowershell
78+
Get-AzSubscription
79+
```
80+
81+
---
82+
83+
Use the following command to select the subscription that you want to use to run the commands to create your IoT hub and DPS resources. You can use either the subscription name or ID from the output of the previous command:
84+
85+
# [CLI](#tab/CLI)
86+
87+
```azurecli
88+
az account set --subscription {your subscription name or id}
89+
```
90+
91+
# [PowerShell](#tab/PowerShell)
92+
93+
```azurepowershell
94+
Set-AzContext -Subscription {your subscription name or id}
95+
```
96+
97+
---
98+
99+
1. Deploy the Bicep file with the following commands.
100+
101+
> [!TIP]
102+
> The commands will prompt for a resource group location.
103+
> You can view a list of available locations by first running the command:
104+
>
105+
> # [CLI](#tab/CLI)
106+
>
107+
> `az account list-locations -o table`
108+
>
109+
> # [PowerShell](#tab/PowerShell)
110+
>
111+
> Get-AzLocation
112+
>
113+
> ---
114+
115+
# [CLI](#tab/CLI)
116+
117+
```azurecli
118+
az group create --name exampleRG --location eastus
119+
az deployment group create --resource-group exampleRG --template-file main.bicep --parameters iotHubName={IoT-Hub-name} provisioningServiceName={DPS-name}
120+
```
121+
122+
# [PowerShell](#tab/PowerShell)
123+
124+
```azurepowershell
125+
New-AzResourceGroup -Name exampleRG -Location eastus
126+
New-AzResourceGroupDeployment -ResourceGroupName exampleRG -TemplateFile ./main.bicep -iotHubName "{IoT-Hub-name}" -provisioningServiceName "{DPS-name}"
127+
```
128+
129+
---
130+
131+
Replace **{IoT-Hub-name}** with a globally unique IoT Hub name, replace **{DPS-name}** with a globally unique Device Provisioning Service (DPS) resource name.
132+
133+
It takes a few moments to create the resources.
134+
135+
## Review deployed resources
136+
137+
1. To verify the deployment, run the following command and look for the new provisioning service and IoT hub in the output:
138+
139+
# [CLI](#tab/CLI)
140+
141+
```azurecli
142+
az resource list -g exampleRg
143+
```
144+
145+
# [PowerShell](#tab/PowerShell)
146+
147+
```azurepowershell
148+
Get-AzResource -ResourceGroupName exampleRG
149+
```
150+
151+
2. To verify that the hub is already linked to the DPS resource, run the following command.
152+
153+
# [CLI](#tab/CLI)
154+
155+
```azurecli
156+
az iot dps show --name <Your provisioningServiceName>
157+
```
158+
159+
# [PowerShell](#tab/PowerShell)
160+
161+
```azurepowershell
162+
Get-AzIoTDeviceProvisioningService -ResourceGroupName exampleRG -Name "{DPS-name}"
163+
```
164+
165+
Notice the hubs that are linked on the `iotHubs` member.
166+
167+
## Clean up resources
168+
169+
Other quickstarts in this collection build upon this quickstart. If you plan to continue on to work with subsequent quickstarts or with the tutorials, do not clean up the resources created in this quickstart. If you do not plan to continue, you can use the Azure PowerShell or Azure CLI to delete the resource group and all of its resources.
170+
171+
To delete a resource group and all its resources from the Azure portal, just open the resource group and click **Delete resource group** and the top.
172+
173+
To delete the resource group deployed:
174+
175+
# [CLI](#tab/CLI)
176+
177+
```azurecli
178+
az group delete --name exampleRG
179+
```
180+
181+
# [PowerShell](#tab/PowerShell)
182+
183+
```azurepowershell
184+
Remove-AzResourceGroup -name exampleRG
185+
```
186+
187+
---
188+
You can also delete resource groups and individual resources using the Azure portal, PowerShell, or REST APIs, as well as with supported platform SDKs published for Azure Resource Manager or IoT Hub Device Provisioning Service.
189+
190+
## Next steps
191+
192+
In this quickstart, you've deployed an IoT hub and a Device Provisioning Service instance, and linked the two resources. To learn how to use this setup to provision a device, continue to the quickstart for creating a device.
193+
194+
> [!div class="nextstepaction"]
195+
> [Quickstart: Provision a simulated symmetric key device](./quick-create-simulated-device-symm-key.md)

articles/iot-dps/toc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ items:
1414
href: quick-setup-auto-provision.md
1515
- name: Azure CLI
1616
href: quick-setup-auto-provision-cli.md
17+
- name: Bicep
18+
displayName: Resource Manager,ARM,template
19+
href: quick-setup-auto-provision-bicep.md
1720
- name: ARM template
1821
displayName: Resource Manager
1922
href: quick-setup-auto-provision-rm.md

0 commit comments

Comments
 (0)