Skip to content

Commit b009be5

Browse files
committed
First set of bicep modules
0 parents  commit b009be5

12 files changed

+466
-0
lines changed

Devices/dps.bicep

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//
2+
// Deploys a Device Provisioning Service
3+
// https://learn.microsoft.com/en-us/azure/iot-dps/
4+
//
5+
6+
@description('Descriptor for this resource')
7+
param prefix string = 'dps'
8+
9+
@description('Unique suffix for all resources in this deployment')
10+
param suffix string = uniqueString(resourceGroup().id)
11+
12+
@description('Location for all resources.')
13+
param location string = resourceGroup().location
14+
15+
@description('SKU name.')
16+
param sku string = 'S1'
17+
18+
@description('Number of provisioned units. Restricted to 1 unit for the F1 SKU. Can be set up to maximum number allowed for subscription.')
19+
param capacity int = 1
20+
21+
@description('Details for required IoTHub resource (name/id/host)')
22+
param iotHub object
23+
24+
var key = listKeys(iotHub.id, '2021-07-02').value[0]
25+
var HUBCSTR = 'HostName=${iotHub.host};SharedAccessKeyName=${key.keyName};SharedAccessKey=${key.primaryKey}'
26+
27+
resource dps 'Microsoft.Devices/provisioningServices@2022-12-12' = {
28+
name: '${prefix}-${suffix}'
29+
location: location
30+
sku: {
31+
name: sku
32+
capacity: capacity
33+
}
34+
properties: {
35+
iotHubs: [
36+
{
37+
connectionString: HUBCSTR
38+
location: location
39+
}
40+
]
41+
}
42+
}
43+
44+
output result object = {
45+
name: dps.name
46+
id: dps.id
47+
scope: dps.properties.idScope
48+
}

Devices/iothub-dps.bicep

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// Deploys an Azure IoT Hub with an associated Device Provisioning Service
3+
//
4+
5+
@description('Unique suffix for all resources in this deployment')
6+
param suffix string = uniqueString(resourceGroup().id)
7+
8+
@description('Location for all resources.')
9+
param location string = resourceGroup().location
10+
11+
module iotHub 'iothub.bicep' = {
12+
name: 'iotHub'
13+
params: {
14+
suffix: suffix
15+
location: location
16+
}
17+
}
18+
19+
module dps 'dps.bicep' = {
20+
name: 'dps'
21+
params: {
22+
suffix: suffix
23+
location: location
24+
iotHub: iotHub.outputs.result
25+
}
26+
}
27+
28+
output HUBNAME string = iotHub.outputs.result.name
29+
output DPSNAME string = dps.outputs.result.name
30+
output IDSCOPE string = dps.outputs.result.scope

Devices/iothub.bicep

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//
2+
// Deploys an Azure IoT Hub
3+
// https://learn.microsoft.com/en-us/azure/iot-hub/
4+
//
5+
6+
@description('Descriptor for this resource')
7+
param prefix string = 'iothub'
8+
9+
@description('Unique suffix for all resources in this deployment')
10+
param suffix string = uniqueString(resourceGroup().id)
11+
12+
@description('Location for all resources.')
13+
param location string = resourceGroup().location
14+
15+
@description('SKU name.')
16+
param sku string = 'S1'
17+
18+
@description('Number of provisioned units. Restricted to 1 unit for the F1 SKU. Can be set up to maximum number allowed for subscription.')
19+
param capacity int = 1
20+
21+
@description('Optional file upload storage endpoint')
22+
param uploadstorage object = {}
23+
24+
resource iotHub 'Microsoft.Devices/IotHubs@2021-07-02' = {
25+
name: '${prefix}-${suffix}'
26+
location: location
27+
sku: {
28+
name: sku
29+
capacity: capacity
30+
}
31+
properties: {
32+
storageEndpoints: uploadstorage
33+
routing: {
34+
fallbackRoute: {
35+
name: '$fallback'
36+
source: 'DeviceMessages'
37+
condition: 'true'
38+
endpointNames: [
39+
'events'
40+
]
41+
isEnabled: true
42+
}
43+
}
44+
}
45+
}
46+
47+
output result object = {
48+
name: iotHub.name
49+
id: iotHub.id
50+
host: iotHub.properties.hostName
51+
}

Devices/iothubcg.bicep

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// Deploys a Consumer Group into an IoT Hub
3+
//
4+
5+
@description('Name of consumer group')
6+
param name string
7+
8+
@description('Name of parent event hub')
9+
param ehub string
10+
11+
resource cg 'Microsoft.Devices/IotHubs/eventHubEndpoints/ConsumerGroups@2021-07-02' = {
12+
name: '${ehub}/events/${name}'
13+
properties: {
14+
name: name
15+
}
16+
}

EventHub/ehub.bicep

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//
2+
// Deploys an Azure Event Hub namespace
3+
// with associated Event Hub
4+
// with associated sending key
5+
// https://learn.microsoft.com/en-us/azure/event-hubs/
6+
//
7+
8+
@description('Descriptor for the parent namespace resource')
9+
param prefix string = 'ehubns'
10+
11+
@description('Descriptor for the hub resource')
12+
param hubname string = 'ehub'
13+
14+
@description('Name of sending key')
15+
param keyname string = 'SendKey'
16+
17+
@description('Unique suffix for all resources in this deployment')
18+
param suffix string = uniqueString(resourceGroup().id)
19+
20+
@description('Location for all resources.')
21+
param location string = resourceGroup().location
22+
23+
@description('SKU name.')
24+
param sku string = 'Basic'
25+
26+
@description('Number of provisioned units.')
27+
param capacity int = 1
28+
29+
resource namespace 'Microsoft.EventHub/namespaces@2022-10-01-preview' = {
30+
name: '${prefix}-${suffix}'
31+
location: location
32+
sku: {
33+
name: sku
34+
tier: sku
35+
capacity: capacity
36+
}
37+
properties: {
38+
minimumTlsVersion: '1.2'
39+
publicNetworkAccess: 'Enabled'
40+
disableLocalAuth: false
41+
zoneRedundant: true
42+
isAutoInflateEnabled: false
43+
maximumThroughputUnits: 0
44+
kafkaEnabled: false
45+
}
46+
}
47+
48+
resource key 'Microsoft.EventHub/namespaces/authorizationrules@2022-10-01-preview' = {
49+
parent: namespace
50+
name: keyname
51+
properties: {
52+
rights: [
53+
'Send'
54+
]
55+
}
56+
}
57+
58+
resource ehub 'Microsoft.EventHub/namespaces/eventhubs@2022-10-01-preview' = {
59+
parent: namespace
60+
name: hubname
61+
properties: {
62+
retentionDescription: {
63+
cleanupPolicy: 'Delete'
64+
retentionTimeInHours: 1
65+
}
66+
messageRetentionInDays: 1
67+
partitionCount: 2
68+
status: 'Active'
69+
}
70+
}
71+
72+
output namespace object = {
73+
name: namespace.name
74+
id: namespace.id
75+
}
76+
77+
output key object = {
78+
name: key.name
79+
id: key.id
80+
}
81+
82+
output ehub object = {
83+
name: ehub.name
84+
id: ehub.id
85+
}

LICENSE

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) 2022 James Coliz
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Azure Deployment Bicep Templates
2+
3+
This is a repository of Bicep templates for the modules I tend to use frequently.
4+
5+
## Microsoft.Devices
6+
7+
* [IoTHub](./Devices/iothub.bicep)
8+
* [IoTHub Consumer Group](./Devices/iothubcg.bicep)
9+
* [Device Provisioning Service](./Devices/dps.bicep)
10+
* [IoTHub + DPS](./Devices/iothub-dps.bicep)
11+
12+
## Microsoft.Storage
13+
14+
* [Storage Account](./Storage/storage.bicep)
15+
* [Blob Container](./Storage/storcontainer.bicep)
16+
* [Table](./Storage/storagetable.bicep)
17+
18+
## Microsoft.EventHub
19+
20+
* [Event Hub Namespace + Sending Key + Hub](./EventHub/ehub.bicep)
21+
22+
## Microsoft.Web
23+
24+
* [Function App](./Web/fn.bicep)
25+
* [Function App + Storage Account](./Web/fn-storage.bicep)

Storage/storage.bicep

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// Deploys an Azure Storage Account
3+
// https://learn.microsoft.com/en-us/azure/storage/
4+
//
5+
6+
@description('Descriptor for this resource')
7+
param prefix string = 'storage'
8+
9+
@description('Unique suffix for all resources in this deployment')
10+
param suffix string = uniqueString(resourceGroup().id)
11+
12+
@description('Location for all resources.')
13+
param location string = resourceGroup().location
14+
15+
@description('SKU name.')
16+
param sku string = 'Standard_LRS'
17+
18+
resource storage 'Microsoft.Storage/storageAccounts@2022-09-01' = {
19+
name: '${prefix}000${suffix}'
20+
location: location
21+
sku: {
22+
name: sku
23+
}
24+
kind: 'Storage'
25+
}
26+
27+
output result object = {
28+
name: storage.name
29+
id: storage.id
30+
}

Storage/storagetable.bicep

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// Deploys a single Table into a Storage Account
3+
//
4+
5+
@description('Name of table')
6+
param name string
7+
8+
@description('Name of storage account')
9+
param account string
10+
11+
resource storageAccountName_default_storageTable 'Microsoft.Storage/storageAccounts/tableServices/tables@2022-09-01' = {
12+
name: '${account}/default/${name}'
13+
}

Storage/storcontainer.bicep

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// Deploys a Blob Container into a Storage Account
3+
// https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blobs-introduction
4+
//
5+
6+
@description('Name of container')
7+
param name string
8+
9+
@description('Name of storage account')
10+
param account string
11+
12+
resource container 'Microsoft.Storage/storageAccounts/blobServices/containers@2022-09-01' = {
13+
name: '${account}/default/${name}'
14+
properties: {
15+
publicAccess: 'None'
16+
}
17+
}

Web/fn-storage.bicep

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// Deploys Function App with associated storage account
3+
//
4+
5+
@description('Unique suffix for all resources in this deployment')
6+
param suffix string = uniqueString(resourceGroup().id)
7+
8+
@description('Location for all resources.')
9+
param location string = resourceGroup().location
10+
11+
module storage '../Storage/storage.bicep' = {
12+
name: 'storage'
13+
params: {
14+
suffix: suffix
15+
location: location
16+
}
17+
}
18+
19+
module fn 'fn.bicep' = {
20+
name: 'fn'
21+
params: {
22+
storage: storage.outputs.result
23+
suffix: suffix
24+
location: location
25+
}
26+
}
27+
28+
output fn object = {
29+
name: fn.outputs.result.name
30+
id: fn.outputs.result.id
31+
}
32+
33+
output storage object = {
34+
name: storage.outputs.result.name
35+
id: storage.outputs.result.id
36+
}

0 commit comments

Comments
 (0)