You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/iot-dps/tutorial-automation-github-actions.md
+50-11Lines changed: 50 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,15 +51,29 @@ Only repository owners and admins can manage repository secrets.
51
51
52
52
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).
53
53
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.
55
55
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.
57
57
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:
61
63
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
+
```
63
77
64
78
### Save service principal credentials as secrets
65
79
@@ -72,21 +86,21 @@ The output for this command includes a generated password for the service princi
72
86
1. Create a secret for your service principal ID.
73
87
74
88
***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.
76
90
77
91
1. Select **Add secret**, then select **New repository secret** to add a second secret.
78
92
79
93
1. Create a secret for your service principal password.
80
94
81
95
***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.
83
97
84
98
1. Select **Add secret**, then select **New repository secret** to add the final secret.
85
99
86
100
1. Create a secret for your Azure tenant.
87
101
88
102
***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.
90
104
91
105
1. Select **Add secret**.
92
106
@@ -98,7 +112,7 @@ For this tutorial, we'll create one workflow that contains jobs for each of the
98
112
99
113
* Provision an IoT Hub instance and a DPS instance.
100
114
* 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.
102
116
* Simulate the device for five minutes and monitor the IoT hub events.
103
117
104
118
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
145
159
jobs:
146
160
```
147
161
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:
149
163
150
164
```yml
151
165
provision:
@@ -159,6 +173,11 @@ Workflows are YAML files that are located in the `.github/workflows/` directory
159
173
az iot dps create -n "$DPS_NAME" -g "$RESOURCE_GROUP"
160
174
```
161
175
176
+
For more information about the commands run in this job, see:
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.
163
182
164
183
```yml
@@ -172,6 +191,10 @@ Workflows are YAML files that are located in the `.github/workflows/` directory
172
191
az iot dps linked-hub create --dps-name "$DPS_NAME" --hub-name "$HUB_NAME"
173
192
```
174
193
194
+
For more information about the commands run in this job, see:
> 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:
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.
207
242
208
243
```yml
@@ -217,6 +252,10 @@ Workflows are YAML files that are located in the `.github/workflows/` directory
217
252
az iot hub monitor-events -n "$HUB_NAME" -y
218
253
```
219
254
255
+
For more information about the commands run in this job, see:
0 commit comments