Speeding up installation of AIO (Azure IoT Operations) deployment using a script
Tags: aio, tutorial
Published: 2024-06-01 23:57:05

If you're eager to learn more about AIO (Azure IoT Operations), which is currently in private preview, it's crucial to start with a fresh install to experiment quickly and efficiently. In this post, I will guide you through the steps to reinstall your cluster using a script, ensuring a smooth learning experience. Let's get started!

For now, the assumption is that you are using [fresh codespace using those steps](https://learn.microsoft.com/en-us/azure/iot-operations/get-started/quickstart-deploy#connect-a-kubernetes-cluster-to-azure-arc). Updated script for physical machines with Ubuntu server coming soon...

## Setup the cluster again and deploy the AIO extension

> Note: if your are looking at a [new version of AIO](https://github.com/Azure/azure-iot-operations/releases), the script may need adapting - this has been tested with AIO v0.5-preview at the time of writing

### 1. Set up your variables

#### 1.a RESOURCE_GROUP

When you created your Codespace, you had to provide some variable values such as the resource group, so double check that the resource group variable is what you expect with `echo $RESOURCE_GROUP`, and otherwise set it using (update value as needed):

```bash
export RESOURCE_GROUP=aio-codespace-rg
```

#### 1.b IOT OPS USER_EMAIL

To ensure your user can access the AIO UI, specify your IoT Ops user email with the following command, replacing <your-email> with your actual email address:

```bash
export USER_EMAIL=<your-email>
```

> Note: Remember that user needs to be a member of the tenant such as iotops@YOUTENANT.onmicrosoft.com
> If you do not have one, use `export USER_EMAIL=$(az ad user create --display-name 'IoT Ops User' --password <PASSOWRD> --user-principal-name iotop@<TENANTNAME>.onmicrosoft.com --force-change-password-next-sign-in false -o tsv --query userPrincipalName)`

### 1.c Other Variables (optional)

Consider double checking other environment variables such as the $CLUSTER_NAME to suit your preferences.

### 2. Login

Ensure you are signed into your Azure Account by running the following command in your terminal, then follow the instructions in your browser:

```bash
az login --use-device-code
```

### 3. Run your setup script

Create a file named setup.sh in your Codespace and copy the content from [this gist](https://gist.github.com/danuw/37c931341d5cde145564a5bfe05cc4c7/2fb3c5452d273a884da1dd8a28a7100bdfd1a656) into it.

Once you have updated your variables and logged into Azure, you are ready to run the script with the following command:

```bash
. ./setup.sh
```
![Running the command in Codespace](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tdwh6tbofk7orfubey7g.png)


> Note: Currently tested on Codespace, but will soon update with script for Ubuntu server including Az CLI install and other pre-requisites for re-install

### 4. Manual Validation

Based on experience, if your Codespace setup remains unchanged (same number of cores, etc.), you can expect this whole process to take approximately 25 minutes.

After the process completes, navigate to [IoT Operations Portal](https://iotoperations.azure.com) and sign in with your member user account. You should see your cluster listed as connected.

![IoT Operations Portal with your connected cluster](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ywljgzxxrg8odk6eup2d.png)


## Next?

Thank you for reading this far. I hope this script helps you experiment faster with AIO. In the future, I plan to:

- Expand the script with new steps: As AIO evolves and more APIs become available, additional processes can be automated. You may also consider improving the script as you explore or revisit the latest features, in which case don't forget to let me know in the gist's comments.
- Cover more scenarios, such as creating assets using CLI.


References:
- https://github.com/Azure/azure-iot-ops-cli-extension
- https://learn.microsoft.com/en-us/cli/azure/iot/ops?view=azure-cli-latest
- https://learn.microsoft.com/en-us/azure/azure-arc/kubernetes/custom-locations
- https://learn.microsoft.com/en-us/azure/iot-operations/get-started/quickstart-deploy
- https://learn.microsoft.com/en-us/azure/iot-operations/manage-devices-assets/howto-manage-assets-remotely?tabs=cli