Created
July 1, 2021 13:29
-
-
Save ehrnst/86144e9882600418a24f6d7b88c3345b to your computer and use it in GitHub Desktop.
Bicep modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
targetScope = 'subscription' | |
var location = deployment().location // set same location as the deployment | |
// deploy resource group | |
resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = { | |
name: 'myapp-rg' | |
location: location | |
} | |
// deploy storage account to resource group | |
module str 'simplemodule.bicep' = { | |
name: 'storage' | |
scope: rg | |
params: { | |
name: 'str39465131' | |
} | |
} | |
output resourceGroup object = rg | |
output storageAccountName string = str.outputs.storageAccountName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param storageName string | |
resource storage 'Microsoft.Storage/storageAccounts@2021-04-01' = { | |
name: storageName | |
location: resourceGroup().location | |
sku: { | |
name: 'Standard_GRS' | |
} | |
kind: 'StorageV2' | |
} | |
output storageAccountName string = storage.name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// main bicep file | |
// accepting inputs for what type of environment you are creating | |
targetScope = 'subscription' | |
@allowed([ | |
'prod' | |
'test' | |
]) | |
param environment string | |
param baseTime string = utcNow('yyyy-MM-dd') | |
var tags = { | |
'owner': 'martin-ehrnst' | |
'environment': environment | |
'last-provisioned': baseTime | |
} | |
var location = deployment().location // set same location as the deployment | |
// deploy resource group | |
resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = { | |
name: 'myapp-${environment}-rg' | |
location: location | |
tags: tags | |
} | |
// deploy storage account to resource group | |
module str 'resources/storage-account.bicep' = { | |
name: 'storage' | |
scope: rg | |
params: { | |
environment: environment | |
tags: tags | |
} | |
} | |
output resourceGroup object = rg | |
output storageAccountName string = str.outputs.storageAccountName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// storage account module | |
param environment string | |
param tags object | |
var location = resourceGroup().location | |
var environmentSettings = { | |
prod: { | |
storageAccountName: toLower('strprod${uniqueString(resourceGroup().id)}') // concat prefix with a unique id. Make sure its in lower case. | |
sku: 'Standard_GRS' | |
publicAccess: false | |
} | |
test: { | |
storageAccountName: toLower('strtest${uniqueString(resourceGroup().id)}') // concat prefix with a unique id. Make sure its in lower case. | |
sku: 'Standard_LRS' | |
publicAccess: true | |
} | |
} | |
resource storage 'Microsoft.Storage/storageAccounts@2021-04-01' = { | |
name: '${environmentSettings[environment].storageAccountName}' // use the name from our environment settings based on the inputed environment name | |
location: location | |
sku: { | |
name: '${environmentSettings[environment].sku}' | |
} | |
kind: 'StorageV2' | |
tags: tags | |
properties: { | |
supportsHttpsTrafficOnly: true | |
allowBlobPublicAccess: '${environmentSettings[environment].publicAccess}' | |
} | |
} | |
output storageAccountName string = storage.name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment