Bicep
Purpose
The idea is to gain more exposure to authoring and deploying Bicep configurations. Configurations will start small and then grow larger and more complex as I progress. It’s also a handy spot to keep links, code examples, etc.
Process
Old habits have me going to PowerShell first, deploying, and then if the project is large enough, repeatable, etc. doing an ARM > Bicep deployment. The three step process is incredibly inefficient for scenarios that call for these types of deployments.
- The Azure portal and scripting is used when creating one-off items or resources that are pretty static.
- Creating a one-off VM and attaching it to a pre-existing vnet, creating a core storage account, etc.
- Bicep is very structured and will sort out most of your dependencies which lends itself to in-depth, repeatable deployments
- The yaml structure and modular files lends itself well to larger or more complex deployments.
- The modules can be re-used for various other projects (e.g. a standard Network module so anything/everything deployed has standard rules)
- Defaults and required resource properties are still hit and miss so this is great exposure for those items
- Add content to the Bicep Notes page to develop a set of standard naming conventions, tags, loops, etc.
Comparing Deployment Processes
Using the fist lab as an example we’re going to create the resource group, then deploy the Bicep file. It’s interesting seeing the difference in the converted ARM > Bicep file vs my authored one. There are a lot of items that Azure will simply handle on the back end for you - but watch out for default settings that are either unsecure or costly.
az group create --name rg-az104bi-westus2 --location westus2
az deployment group create --template-file .\main.bicep
With the main.bicep
file contents being:
Versus the ARM > Bicep conversion which is 5x the length.
The ARM template defines the resources as they exist, live and deployed, which is why the converted template is so much larger than the custom one. There are more items that make up a resource then we typically are aware of and account for. This is an example of where I think the ARM > Bicep process can be useful. There are assumed parameters that are difficult to keep in mind, such as minimum TLS version, that you don’t see, know about, etc. until you look at the output ARM template and realize, “That’s not what I want”.
A lot of the pain points around missing parameters, valid name formats, unknown resource types (vscode did NOT want to give me an option for a disk resource until the API was specified), etc. will all come with more experience.
Azure Storage Security Lab
The AZ-104 learn module around managing storage had a decent environment that needed to be setup. As this is the first refresher on module deployment, I figured I would add it here as well. There are items that, theoretically, should have been added if this were a production setup. This is a learning environment though and I want to track my development as I go through these. Not having something perfect on the first run isn’t a failure - it’s just not perfect yet.
Basically, I’m not making it perfect the first time around - I’m meeting the immediate need and will keep adding things as I progress. This definitely goes against the grain of my personality. I’ve heard, “Don’t let perfect be the enemy of good” as constructive criticism a few times.
- Admin password should probably integrate with/use Azure Key Vault vs prompting the user to enter the password.
- There are no conditional parameters around the environment and deployment types
- e.g. Dev vs Production and manipulating the SKU
- Standards are already shifting
- This is a good example of why modules and parameter files are great - set your standard and move forward. When you need to modify or update, update the standard module (VNETs, VMs, Storage, etc.) or the parameters file to progress everything together.
- The VM and Vnets should be separated out to their own separate modules
- I’m kind of saving this as a progress marker - passing outputs from one module to another is one trick on reducing the amounts of ‘dependsOn’ statements and I want to see how that goes when I have more time.
- The power of automation is also the terrifying part - one-click deployment is also one-click destruction. Adding logic around resource locks with the appropriate lock types will be another item to add to the automation.
There was some amount of Portal -> ARM Template -> Bicep conversion due to the unknown parameters and values for the Microsoft.Storage service endpoint and associating it with the VNET and Storage account. Overall though I’m pretty happy with the progress around creating -> tuning -> deploying at the moment.
The file structure is the standard layout with the following files:
/ main.bicep
|
└───modules
storage104.bicep
vm_nets.bicep
The main.bicep
holds the majority of the parameter values and passes them into the storage and VM/Vnet modules.
I need some more scenarios around the VMs, VNETs, nic properties, etc.. I kind of brute forced the nicProps
parameters and the corresponding resource parameters in the vmresources
resource/module. It does work though and I believe I’ll get a good refresher on those as
The Access Tier, SKU, and VNET integration are areas of improvement on the storage module.
Another great takeaway from this little lab was the reminder on how the code really defines the infrastructure post-deployment. Additional changes around tweaking the NSG rules, VM SKU size, etc. triggered the appropriate modifications of the pre-existing resources. There were no conflicts, teardown -> deploy processes, or anything like that. It’s literally as if someone went in via the Azure portal to make the changes.