Image from Pixabay
ARM Templates / IaC with Azure Bicep
By Morgan Lucas
By Morgan Lucas
This is a post intended for this site, as a way to get a feel of using it consistently. Older posts are here.
So Bicep is like Terraform but a different language that's native to Azure! That's fun. Here's a video about it (I love how enthusiastic the person is)
My Attempt
First we have our resource group; This is where things like virtual machines (virtual computers), storage account, and some configurations are stored for organizational ease.
az group create --name runtcp -l eastus
Don't forget to check the naming contention of the regions you put resources in. I kept putting in us-east ala AWS.
Then I make the storage account to go in! this can store resources that can be open to the greater internet for people to download - Or it can have the proper security measures in place for certain people to have access to.
az group deployment create --resource-group runtcp --template-file main.bicep --mode Complete
A very cool thing the video Azure Bicep Crash Course, by Meet Kamal Today does is use an array to push the same resource in multiple regions (3:30)
'This Declaration is Not Recognized'
I use the VS code extension for bicep, where you can start typing (usually `res`) and it gives suggestions on what you might want.
res-resource storageaccount 'Microsoft.Storage/storageAccounts@2021-02-01' = {
name: storageName
location: 'eastus'
kind: 'StorageV2'
sku: {
name: 'Premium_LRS'
}
}
That says 'Let's make a storage account and name it storageName, in the East US, as a V2'
Sometimes the res- gets stuck at the beginning and the entire thing is marked as a non declared ... declaration.
'Inner Errors'
- "PreFlightValidationCheckFailed" and "AccountNameInvalid" basically boiled down to 'You don't put capital letters in your storage account name.
resource storageaccount 'Microsoft.Storage/storageAccounts@2021-02-01' = {
name: 'Starro' # ⬅ Wrong
location: 'eastus'
kind: 'StorageV2'
sku: {
name: 'Premium_LRS'
}
}
Bicep has both parameters [(param)s] and variables, which was helpfully pointed out by The Lazy Administrator; It doesn't seem as if there's much difference between the two.
param = storageAccountName string = 'starro'
var location = 'eastus'
resource storageaccount 'Microsoft.Storage/storageAccounts@2021-02-01' = {
name: storageAccountName
location: location
kind: 'StorageV2'
sku: {
name: 'Premium_LRS'
}
}
At this point, the machine I was using to work on this, the monitor and logic board broke. But I got this far, fixed my own errors, so here's a proof of knowledge post.