Skip to content

Commit 42cc7f0

Browse files
Merge pull request #224343 from kgremban/jan18-gitops
Small changes to gitops tutorial
2 parents 8c795d1 + 977228a commit 42cc7f0

File tree

1 file changed

+50
-11
lines changed

1 file changed

+50
-11
lines changed

articles/iot-dps/tutorial-automation-github-actions.md

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,29 @@ Only repository owners and admins can manage repository secrets.
5151

5252
Rather than providing your personal access credentials, we'll create a service principal and then add those credentials as repository secrets. Use the Azure CLI to create a new service principal. For more information, see [Create an Azure service principal](/cli/azure/create-an-azure-service-principal-azure-cli).
5353

54-
The following command creates a service principal with *contributor* access to a specific resource group. Replace **<SUBSCRIPTION_ID>** and **<RESOURCE_GROUP_NAME>** with your own information.
54+
1. Use the [az ad sp create-for-rbac](/cli/azure/ad/sp#az-ad-sp-create-for-rbac) command to create a service principal with *contributor* access to a specific resource group. Replace `<SUBSCRIPTION_ID>` and `<RESOURCE_GROUP_NAME>` with your own information.
5555

56-
This command requires owner or user access administrator roles in the subscription.
56+
This command requires owner or user access administrator roles in the subscription.
5757

58-
```azurecli
59-
az ad sp create-for-rbac --name github-actions-sp --role contributor --scopes /subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP_NAME>
60-
```
58+
```azurecli
59+
az ad sp create-for-rbac --name github-actions-sp --role contributor --scopes /subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP_NAME>
60+
```
61+
62+
1. Copy the following items from the output of the service principal creation command to use in the next section:
6163

62-
The output for this command includes a generated password for the service principal. Copy this password to use in the next section. You won't be able to access the password again.
64+
* The *clientId*.
65+
* The *clientSecret*. This is a generated password for the service principal that you won't be able to access again.
66+
* The *tenantId*.
67+
68+
1. Use the [az role assignment create](/cli/azure/role/assignment#az-role-assignment-create) command to assign two more access roles to the service principal: *Device Provisioning Service Data Contributor* and *IoT Hub Data Contributor*. Replace `<SP_CLIENT_ID>` with the *clientId* value that you copied from the previous command's output.
69+
70+
```azurecli
71+
az role assignment create --assignee "<SP_CLIENT_ID>" --role "Device Provisioning Service Data Contributor" --resource-group "<RESOURCE_GROUP_NAME>"
72+
```
73+
74+
```azurecli
75+
az role assignment create --assignee "<SP_CLIENT_ID>" --role "IoT Hub Data Contributor" --resource-group "<RESOURCE_GROUP_NAME>"
76+
```
6377

6478
### Save service principal credentials as secrets
6579

@@ -72,21 +86,21 @@ The output for this command includes a generated password for the service princi
7286
1. Create a secret for your service principal ID.
7387

7488
* **Name**: `APP_ID`
75-
* **Secret**: `github-actions-sp`, or the value you used for the service principal name if you used a different value.
89+
* **Secret**: Paste the *clientId* that you copied from the output of the service principal creation command.
7690

7791
1. Select **Add secret**, then select **New repository secret** to add a second secret.
7892

7993
1. Create a secret for your service principal password.
8094

8195
* **Name**: `SECRET`
82-
* **Secret**: Paste the password that you copied from the output of the service principal creation command.
96+
* **Secret**: Paste the *clientSecret* that you copied from the output of the service principal creation command.
8397

8498
1. Select **Add secret**, then select **New repository secret** to add the final secret.
8599

86100
1. Create a secret for your Azure tenant.
87101

88102
* **Name**: `TENANT`
89-
* **Secret**: Provide your Azure tenant. The value of this argument can either be an .onmicrosoft.com domain or the Azure object ID for the tenant.
103+
* **Secret**: Paste the *tenantId* that you copied from the output of the service principal creation command.
90104

91105
1. Select **Add secret**.
92106

@@ -98,7 +112,7 @@ For this tutorial, we'll create one workflow that contains jobs for each of the
98112

99113
* Provision an IoT Hub instance and a DPS instance.
100114
* Link the IoT Hub and DPS instances to each other.
101-
* Create an individual enrollment on the DPS instance, and register a device to the IoT hub via the DPS enrollment.
115+
* Create an individual enrollment on the DPS instance, and register a device to the IoT hub using symmetric key authentication via the DPS enrollment.
102116
* Simulate the device for five minutes and monitor the IoT hub events.
103117

104118
Workflows are YAML files that are located in the `.github/workflows/` directory of a repository.
@@ -145,7 +159,7 @@ Workflows are YAML files that are located in the `.github/workflows/` directory
145159
jobs:
146160
```
147161

148-
1. Define the first job for our workflow, which we'll call the `provision` job. This job provisions the IoT Hub and DPS instances.
162+
1. Define the first job for our workflow, which we'll call the `provision` job. This job provisions the IoT Hub and DPS instances:
149163

150164
```yml
151165
provision:
@@ -159,6 +173,11 @@ Workflows are YAML files that are located in the `.github/workflows/` directory
159173
az iot dps create -n "$DPS_NAME" -g "$RESOURCE_GROUP"
160174
```
161175

176+
For more information about the commands run in this job, see:
177+
178+
* [az iot hub create](/cli/azure/iot/hub#az-iot-hub-create)
179+
* [az iot dps create](/cli/azure/iot/dps#az-iot-dps-create)
180+
162181
1. Define a job to `configure` the DPS and IoT Hub instances. Notice that this job uses the [needs](https://docs.github.com/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idneeds) parameter, which means that the `configure` job won't run until listed job completes its own run successfully.
163182

164183
```yml
@@ -172,6 +191,10 @@ Workflows are YAML files that are located in the `.github/workflows/` directory
172191
az iot dps linked-hub create --dps-name "$DPS_NAME" --hub-name "$HUB_NAME"
173192
```
174193

194+
For more information about the commands run in this job, see:
195+
196+
* [az iot dps linked-hub create](/cli/azure/iot/dps/linked-hub#az-iot-dps-linked-hub-create)
197+
175198
1. Define a job called `register` that will create an individual enrollment and then use that enrollment to register a device to IoT Hub.
176199

177200
```yml
@@ -189,6 +212,14 @@ Workflows are YAML files that are located in the `.github/workflows/` directory
189212
az iot device registration create -n "$DPS_NAME" --rid "$DEVICE_NAME" --auth-type login
190213
```
191214

215+
> [!NOTE]
216+
> This job and others use the parameter `--auth-type login` in some commands to indicate that the operation should use the service principal from the current Azure AD session. The alternative, `--auth-type key` doesn't require the service principal configuration, but is less secure.
217+
218+
For more information about the commands run in this job, see:
219+
220+
* [az iot dps enrollment create](/cli/azure/iot/dps/enrollment#az-iot-dps-enrollment-create)
221+
* [az iot device registration create](/cli/azure/iot/device/registration#az-iot-device-registration-create)
222+
192223
1. Define a job to `simulate` an IoT device that will connect to the IoT hub and send sample telemetry messages.
193224

194225
```yml
@@ -203,6 +234,10 @@ Workflows are YAML files that are located in the `.github/workflows/` directory
203234
az iot device simulate -n "$HUB_NAME" -d "$DEVICE_NAME"
204235
```
205236

237+
For more information about the commands run in this job, see:
238+
239+
* [az iot device simulate](/cli/azure/iot/device#az-iot-device-simulate)
240+
206241
1. Define a job to `monitor` the IoT hub endpoint for events, and watch messages coming in from the simulated device. Notice that the **simulate** and **monitor** jobs both define the **register** job in their `needs` parameter. This configuration means that once the **register** job completes successfully, both these jobs will run in parallel.
207242

208243
```yml
@@ -217,6 +252,10 @@ Workflows are YAML files that are located in the `.github/workflows/` directory
217252
az iot hub monitor-events -n "$HUB_NAME" -y
218253
```
219254

255+
For more information about the commands run in this job, see:
256+
257+
* [az iot hub monitor-events](/cli/azure/iot/hub#az-iot-hub-monitor-events)
258+
220259
1. The complete workflow file should look like this example, with your information replacing the placeholder values in the environment variables:
221260

222261
```yml

0 commit comments

Comments
 (0)