Skip to content

Commit 8008466

Browse files
authored
Merge pull request #212695 from kgremban/sep26-terraform
New terraform quickstart for DPS
2 parents 067a45f + f066c15 commit 8008466

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
---
2+
title: Quickstart - Use Terraform to create a DPS instance
3+
description: Learn how to deploy an Azure IoT Device Provisioning Service (DPS) resource with Terraform in this quickstart.
4+
keywords: azure, devops, terraform, device provisioning service, DPS, IoT, IoT Hub DPS
5+
ms.topic: quickstart
6+
ms.date: 10/27/2022
7+
ms.custom: devx-track-terraform
8+
author: kgremban
9+
ms.author: kgremban
10+
ms.service: iot-dps
11+
services: iot-dps
12+
---
13+
14+
# Quickstart: Use Terraform to create an Azure IoT Device Provisioning Service
15+
16+
In this quickstart, you will learn how to deploy an Azure IoT Hub Device Provisioning Service (DPS) resource with a hashed allocation policy using Terraform.
17+
18+
This quickstart was tested with the following Terraform and Terraform provider versions:
19+
20+
- [Terraform v1.2.8](https://releases.hashicorp.com/terraform/)
21+
- [AzureRM Provider v.3.20.0](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs)
22+
23+
[Terraform](https://www.terraform.io/) enables the definition, preview, and deployment of cloud infrastructure. Using Terraform, you create configuration files using HCL syntax. The [HCL syntax](https://www.terraform.io/language/syntax/configuration) allows you to specify the cloud provider - such as Azure - and the elements that make up your cloud infrastructure. After you create your configuration files, you create an execution plan that allows you to preview your infrastructure changes before they're deployed. Once you verify the changes, you apply the execution plan to deploy the infrastructure.
24+
25+
In this article, you learn how to:
26+
27+
- Create a Storage Account & Storage Container
28+
- Create an Event Hubs, Namespace, & Authorization Rule
29+
- Create an IoT Hub
30+
- Link IoT Hub to Storage Account endpoint & Event Hubs endpoint
31+
- Create an IoT Hub Shared Access Policy
32+
- Create a DPS Resource
33+
- Link DPS & IoT Hub
34+
35+
## Prerequisites
36+
37+
[!INCLUDE [open-source-devops-prereqs-azure-subscription.md](~/azure-dev-docs-pr/articles/includes/open-source-devops-prereqs-azure-subscription.md)]
38+
39+
- [Install and configure Terraform](/azure/developer/terraform/quickstart-configure)
40+
41+
## Implement the Terraform code
42+
43+
> [!NOTE]
44+
> The example code in this article is located in the [Azure Terraform GitHub repo](https://github.com/Azure/terraform/tree/master/). See more [articles and sample code showing how to use Terraform to manage Azure resources](/azure/developer/terraform/)
45+
46+
1. Create a directory in which to test and run the sample Terraform code and make it the current directory.
47+
48+
1. Create a file named `providers.tf` and insert the following code:
49+
50+
[!code-terraform[master](~/terraform_samples/quickstart/201-iot-hub-with-device-provisioning-service/providers.tf)]
51+
52+
1. Create a file named `main.tf` and insert the following code:
53+
54+
[!code-terraform[master](~/terraform_samples/quickstart/201-iot-hub-with-device-provisioning-service/main.tf)]
55+
56+
1. Create a file named `variables.tf` and insert the following code:
57+
58+
[!code-terraform[master](~/terraform_samples/quickstart/201-iot-hub-with-device-provisioning-service/variables.tf)]
59+
60+
1. Create a file named `outputs.tf` and insert the following code:
61+
62+
[!code-terraform[master](~/terraform_samples/quickstart/201-iot-hub-with-device-provisioning-service/outputs.tf)]
63+
64+
## Initialize Terraform
65+
66+
[!INCLUDE [terraform-init.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-init.md)]
67+
68+
## Create a Terraform execution plan
69+
70+
[!INCLUDE [terraform-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan.md)]
71+
72+
## Apply a Terraform execution plan
73+
74+
[!INCLUDE [terraform-apply-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-apply-plan.md)]
75+
76+
## Verify the results
77+
78+
**Azure CLI**
79+
Run [az iot dps show](/cli/azure/iot/dps#az-iot-dps-show) to display the Azure DPS resource.
80+
81+
```azurecli
82+
az iot dps show \
83+
--name my_terraform_dps \
84+
--resource-group rg
85+
```
86+
87+
**Azure PowerShell**
88+
Run [Get-AzIoTDeviceProvisioningService](/powershell/module/az.deviceprovisioningservices/get-aziotdeviceprovisioningservice) to display the Azure DPS resource.
89+
90+
```powershell
91+
Get-AzIoTDeviceProvisioningService `
92+
-ResourceGroupName "rg" `
93+
-Name "my_terraform_dps"
94+
```
95+
96+
The names of the resource group and the DPS instance are displayed in the terraform apply output. You can also run the [terraform output](https://www.terraform.io/cli/commands/output) command to view these output values.
97+
98+
## Clean up resources
99+
100+
[!INCLUDE [terraform-plan-destroy.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan-destroy.md)]
101+
102+
## Troubleshoot Terraform on Azure
103+
104+
[Troubleshoot common problems when using Terraform on Azure](/azure/developer/terraform/troubleshoot)
105+
106+
## Next steps
107+
108+
Now that you have an instance of the Device Provisioning Service, continue to the next quickstart to provision a simulated device to IoT hub:
109+
110+
> [!div class="nextstepaction"]
111+
> [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
@@ -17,6 +17,9 @@ items:
1717
- name: Bicep
1818
displayName: Resource Manager,ARM,template
1919
href: quick-setup-auto-provision-bicep.md
20+
- name: TerraForm
21+
displayName: Resource Manager, ARM, template
22+
href: quick-setup-auto-provision-terraform.md
2023
- name: ARM template
2124
displayName: Resource Manager
2225
href: quick-setup-auto-provision-rm.md

0 commit comments

Comments
 (0)