Skip to content

Commit 0fa2a6d

Browse files
committed
Add environment vars
1 parent 57c7e9b commit 0fa2a6d

File tree

1 file changed

+50
-7
lines changed

1 file changed

+50
-7
lines changed

articles/iot-operations/connect-to-cloud/tutorial-connect-event-grid.md

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.subservice: mq
77
ms.custom: devx-track-azurecli
88
ms.author: patricka
99
ms.topic: tutorial
10-
ms.date: 11/15/2023
10+
ms.date: 02/28/2024
1111

1212
#CustomerIntent: As an operator, I want to configure IoT MQ to bridge to Azure Event Grid MQTT broker PaaS so that I can process my IoT data at the edge and in the cloud.
1313
---
@@ -22,12 +22,46 @@ In this tutorial, you learn how to configure IoT MQ for bi-directional MQTT brid
2222

2323
* [Deploy Azure IoT Operations](../get-started/quickstart-deploy.md)
2424

25+
## Set environment variables
26+
27+
28+
Sign in with Azure CLI:
29+
30+
```azurecli
31+
az login
32+
```
33+
34+
Set environment variables for the rest of the setup. Replace values in `<>` with valid values or names of your choice. A new Azure Event Grid namespace and topic space are created in your Azure subscription based on the names you provide:
35+
36+
```azurecli
37+
# For this tutorial, the steps assume the IoT Operations cluster and the Event Grid
38+
# are in the same subscription, resource group, and location.
39+
40+
# Name of the resource group of Azure Event Grid and IoT Operations cluster
41+
export RESOURCE_GROUP=<RESOURCE_GROUP_NAME>
42+
43+
# Azure region of Azure Event Grid and IoT Operations cluster
44+
export LOCATION=<LOCATION>
45+
46+
# Name of the Azure Event Grid namespace
47+
export EVENT_GRID_NAMESPACE=<EVENT_GRID_NAMESPACE>
48+
49+
# Name of the Arc-enabled IoT Operations cluster
50+
export CLUSTER_NAME=<CLUSTER_NAME>
51+
52+
# Subscription ID of Azure Event Grid and IoT Operations cluster
53+
export SUBSCRIPTION_ID=<SUBSCRIPTION_ID>
54+
```
55+
2556
## Create Event Grid namespace with MQTT broker enabled
2657

27-
[Create Event Grid namespace](../../event-grid/create-view-manage-namespaces.md) with Azure CLI. Replace `<EG_NAME>`, `<RESOURCE_GROUP>`, and `<LOCATION>` with your own values. The location should be the same as the one you used to deploy Azure IoT Operations.
58+
[Create Event Grid namespace](../../event-grid/create-view-manage-namespaces.md) with Azure CLI. The location should be the same as the one you used to deploy Azure IoT Operations.
2859

2960
```azurecli
30-
az eventgrid namespace create -n <EG_NAME> -g <RESOURCE_GROUP> --location <LOCATION> --topic-spaces-configuration "{state:Enabled,maximumClientSessionsPerAuthenticationName:3}"
61+
az eventgrid namespace create --namespace-name $EVENT_GRID_NAMESPACE \
62+
--resource-group $RESOURCE_GROUP \
63+
--location $LOCATION \
64+
--topic-spaces-configuration "{state:Enabled,maximumClientSessionsPerAuthenticationName:3}"
3165
```
3266

3367
By setting the `topic-spaces-configuration`, this command creates a namespace with:
@@ -39,20 +73,29 @@ The max client sessions option allows IoT MQ to spawn multiple instances and sti
3973

4074
## Create a topic space
4175

42-
In the Event Grid namespace, create a topic space named `tutorial` with a topic template `telemetry/#`. Replace `<EG_NAME>` and `<RESOURCE_GROUP>` with your own values.
76+
In the Event Grid namespace, create a topic space named `tutorial` with a topic template `telemetry/#`.
4377

4478
```azurecli
45-
az eventgrid namespace topic-space create -g <RESOURCE_GROUP> --namespace-name <EG_NAME> --name tutorial --topic-templates "telemetry/#"
79+
az eventgrid namespace topic-space create --resource-group $RESOURCE_GROUP \
80+
--namespace-name $EVENT_GRID_NAMESPACE \
81+
--name tutorial \
82+
--topic-templates "telemetry/#"
4683
```
4784

4885
By using the `#` wildcard in the topic template, you can publish to any topic under the `telemetry` topic space. For example, `telemetry/temperature` or `telemetry/humidity`.
4986

5087
## Give IoT MQ access to the Event Grid topic space
5188

52-
Using `az k8s-extension show`, find the principal ID for the Azure IoT MQ Arc extension.
89+
Using `az k8s-extension show`, find the principal ID for the Azure IoT MQ Arc extension. The command stores the principal ID in a variable for later use.
5390

5491
```azurecli
55-
az k8s-extension show --resource-group <RESOURCE_GROUP> --cluster-name <CLUSTER_NAME> --name mq --cluster-type connectedClusters --query identity.principalId -o tsv
92+
export PRINCIPAL_ID=$(az k8s-extension show --resource-group $RESOURCE_GROUP \
93+
--cluster-name $CLUSTER_NAME \
94+
--name mq \
95+
--cluster-type connectedClusters \
96+
--query identity.principalId -o tsv)
97+
98+
echo $PRINCIPAL_ID
5699
```
57100

58101
Take note of the output value for `identity.principalId`, which is a GUID value with the following format:

0 commit comments

Comments
 (0)