Skip to content

Commit

Permalink
add IoT Hub resource
Browse files Browse the repository at this point in the history
  • Loading branch information
ks6088ts committed Jun 12, 2024
1 parent fadb785 commit 4fb4831
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,16 @@
- [Create a database in Azure Cosmos DB for NoSQL using Python](https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/how-to-python-create-database)
- [Create a container in Azure Cosmos DB for NoSQL using Python](https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/how-to-python-create-container)
- [Sample - demonstrates the basic CRUD operations on a Item resource for Azure Cosmos](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/cosmos/azure-cosmos/samples/document_management.py)

### Azure IoT Hub

- [Create and monitor a device](https://learn.microsoft.com/en-us/azure/iot-hub/quickstart-send-telemetry-cli#create-and-monitor-a-device)
- [Connect Raspberry Pi to Azure IoT Hub](https://learn.microsoft.com/en-us/azure/iot-hub/raspberry-pi-get-started)

```shell
IOT_HUB_NAME=""
DEVICE_NAME="simDevice"
az iot hub device-identity create \
--device-id $DEVICE_NAME \
--hub-name $IOT_HUB_NAME
```
13 changes: 13 additions & 0 deletions infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ param eventGridName string = '${prefix}eg'
@description('Specifies the name of the Azure Cosmos DB resource.')
param cosmosDbName string = '${prefix}cosmosdb'

@description('Specifies the name of the Azure IoT Hub resource.')
param iotHubName string = '${prefix}iothub'

module openAi './modules/openAi.bicep' = {
name: 'openAi'
params: {
Expand Down Expand Up @@ -92,6 +95,15 @@ module cosmosDb './modules/cosmosDb.bicep' = {
}
}

module iotHub './modules/iotHub.bicep' = {
name: 'iotHub'
params: {
name: iotHubName
location: location
tags: tags
}
}

// Output
output cognitiveServicesName string = cognitiveServices.outputs.name
output cognitiveServicesEndpoint string = cognitiveServices.outputs.endpoint
Expand All @@ -100,3 +112,4 @@ output eventGridTopicEndpoint string = eventGrid.outputs.eventGridTopicEndpoint
output openAiName string = openAi.outputs.name
output openAiEndpoint string = openAi.outputs.endpoint
output storageAccountName string = storageAccount.outputs.name
output iotHubName string = iotHub.outputs.iotHubName
32 changes: 32 additions & 0 deletions infra/modules/iotHub.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Parameters
@description('Specifies the name prefix.')
param prefix string = uniqueString(resourceGroup().id)

@description('Specifies the primary location of Azure resources.')
param location string = resourceGroup().location

@description('Specifies the resource tags.')
param tags object = {}

@description('Specifies the name of the Azure resource.')
param name string = '${prefix}-iothub'

@description('The SKU to use for the IoT Hub.')
param skuName string = 'B1'

@description('The number of IoT Hub units.')
param skuUnits int = 1

resource iotHub 'Microsoft.Devices/IotHubs@2023-06-30' = {
name: name
location: location
tags: tags
sku: {
name: skuName
capacity: skuUnits
}
}

// Outputs
output iotHubId string = iotHub.id
output iotHubName string = iotHub.name

0 comments on commit 4fb4831

Please sign in to comment.