0
0
Azurecloud~30 mins

Bicep syntax and modules in Azure - Mini Project: Build & Apply

Choose your learning style9 modes available
Bicep Syntax and Modules
📖 Scenario: You are working on an Azure cloud project. You want to organize your infrastructure code using Bicep modules. This helps keep your code clean and reusable.
🎯 Goal: Build a simple Bicep project that defines a storage account in a module and then uses that module in the main Bicep file.
📋 What You'll Learn
Create a Bicep module file named storage.bicep that defines an Azure Storage Account resource.
Create a main Bicep file named main.bicep that calls the storage.bicep module.
Pass the storage account name as a parameter from main.bicep to the module.
Use correct Bicep syntax for module declaration and parameter passing.
💡 Why This Matters
🌍 Real World
Using Bicep modules helps cloud engineers organize and reuse infrastructure code efficiently in Azure deployments.
💼 Career
Understanding Bicep syntax and modules is essential for Azure infrastructure as code roles and DevOps engineers working with Azure Resource Manager.
Progress0 / 4 steps
1
Create the storage.bicep module
Create a Bicep file named storage.bicep. Inside it, declare a parameter called storageAccountName of type string. Then define a resource named storageAccount of type Microsoft.Storage/storageAccounts@2022-09-01 with the name set to storageAccountName, location set to resourceGroup().location, and sku name set to Standard_LRS. Use kind as StorageV2.
Azure
Need a hint?

Remember to declare the parameter first, then define the resource using the parameter for the name.

2
Create the main.bicep file with a parameter
Create a Bicep file named main.bicep. Declare a parameter called storageName of type string. This will hold the storage account name to pass to the module.
Azure
Need a hint?

Just declare a parameter named storageName of type string at the top of main.bicep.

3
Add the module call in main.bicep
In main.bicep, add a module declaration named storageModule that references the storage.bicep file. Pass the storageName parameter to the module's storageAccountName parameter.
Azure
Need a hint?

Use module storageModule 'storage.bicep' = { ... } and inside params, map storageAccountName to storageName.

4
Clean up main.bicep by removing unused code
Remove the direct resource storageAccount declaration and the param storageAccountName from main.bicep. Keep only the param storageName and the module declaration.
Azure
Need a hint?

Keep only the parameter and module call in main.bicep. Remove the resource and extra parameter.