Posted: Wednesday, December 4, 2024
Word Count: 1403
Reading Time: 7 minutes
Smoking a turkey breast is a delightful and rewarding way to create tender, flavorful meat. But here, we’re adding a twist. Instead of listing the recipe in traditional format, we’re using Bicep – a declarative language often used for deploying resources on Azure – to express this recipe as code. Ready for a challenge? Let’s dive in.
You might wonder, “Why use Bicep for a recipe?” Think of it as a fun exercise to break out of the ordinary! This format not only lets you practice Bicep syntax but also makes for a unique and interactive experience. Plus, as cloud enthusiasts, combining technology with culinary creativity is right up our alley!
Let’s go through the Bicep code for setting up a brine solution and managing the smoking process. Each step and ingredient is defined in code, and by running it, you’ll receive a detailed breakdown of what’s needed for a perfectly smoked turkey. And in the process, we’ll learn about variables and parameters too.
The first section of our code sets up the parameters for the recipe, like the weight of the turkey breast and brining essentials. In Bicep, we use parameters and variables to represent these values.
For example:
param turkeyWeight int = 5
var waterAmount = (turkeyWeight * 2) / 5 // 2 gallons per 5 pounds of turkey
BICEPThe code also includes key brine ingredients such as salt, sugar, honey, black pepper, and bay leaves, each calculated based on the amount of water needed.
var saltPerGallonOfWater = waterAmount * 1/2 // 0.5 cups per gallon
var sugarPerGallonOfWater = waterAmount * 4 // tablespoons per gallon
var honeyPerGallonOfWater = waterAmount * 4 // tablespoons per gallon
BICEPThis portion of the code dynamically calculates the amount of each ingredient, ensuring the brine ratios remain accurate for different turkey sizes.
One of the unique challenges we encountered when designing this recipe in Bicep is that Bicep doesn’t support floating-point numbers (decimals). This limitation means that calculations like 0.5 cups of salt per gallon
aren’t natively supported. If we tried using 0.5
directly in Bicep, it would round down to zero, making our recipe a bit bland!
To work around this, we multiplied ingredient amounts by larger numbers to approximate ratios. For example, instead of trying to calculate .25 cups of sugar per gallon, we used the integer-friendly approximation of 4 tablespoons (since 1 cup = 16 tablespoons) per gallon of water. This way, our brine maintains the intended balance without needing decimals.
Once our brine is set, the code calculates the total smoke time based on the turkey’s weight and a specified smoke time per pound.
For extra flavor, we add a “spritz” to the turkey every so often. This spritz might contain ingredients like apple juice, vinegar, and water, and can be set to happen at specific intervals.
Here’s the best part – when you run this Bicep file, it outputs the entire recipe in readable format. You’ll see details like the total amount of each ingredient and a step-by-step list of the smoking process with spritz instructions.
For instance:
output preparationSteps string = '1. Brine the turkey in the solution for ${brineTime} hours. 2. Prepare the smoker with ${woodType} at ${smokerTemp}°F.'
output recipeSummary string = 'Your turkey breast is ready after smoking for ${totalSmokeTime} hours at ${smokerTemp}°F with periodic spritzing!'
Bits and That Technology BlogThese outputs provide all the information you need, laid out in a concise and easy-to-follow format.
In a traditional recipe, we’d simply list out steps like “smoke the turkey for 5 hours, spritzing every hour.” However, in Bicep, we can use loops to handle these repetitive actions automatically, making the code adaptable for any duration.
In this recipe, we use a loop to represent each hour of the smoking process, along with conditional logic to determine when to apply a spritz. This loop dynamically generates a list of instructions for each hour, based on the total smoking time and frequency of spritzing. Here’s how it works:
bicepCopy codevar smokingProcess = [
for i in range(0, totalSmokeTime): {
hour: i
spritz: (i % spritzFrequency == 0) ? spritzMix : 'No spritz'
}
]
Bits and That Technology Blogrange(0, totalSmokeTime)
: This defines the loop range, creating an entry for each hour from 0 to totalSmokeTime
. If totalSmokeTime
is 5, the loop will create 5 entries (hours 0 to 4).i % spritzFrequency == 0
: We use the modulo operator %
to determine when to apply a spritz. If spritzFrequency
is set to 1 (meaning spritz every hour), i % 1 == 0
will be true each hour. If spritzFrequency
is set to 2, spritzing will happen every two hours, and so on.The result of the loop is an array of entries detailing each hour’s spritz instructions. This approach makes the code versatile and easy to adjust – no need to manually list out each spritzing hour.
By the end of the script, the loop outputs the entire smoking process step-by-step, which you’ll see displayed in the terminal as a readable set of instructions.
he entire script is detailed below. Play around with the variables – it’s a great way to learn about variables, parameters, and loop statements.
targetScope = 'subscription'
// Smoking Boneless Turkey Breast Recipe in Bicep
@description('Weight of the boneless turkey breast in pounds')
param turkeyWeight int = 5
// Calculate brine solution based on turkey weight
var waterAmount = (turkeyWeight * 2) / 5 // Gallons of water, assuming 2 gallons per 5 pounds
@description('Brine ingredients - add saltiness to taste')
var saltPerGallonOfWater = waterAmount * 1/2 // 0.5 cups per gallon
var sugarPerGallonOfWater = waterAmount * 4 // tablespoons per gallon
var honeyPerGallonOfWater = waterAmount * 4 // tablespoons per gallon
var blackPepperPerGallonOfWater = waterAmount * 2 // tablespoons per gallon
var bayLeavesPerGallonOfWater = waterAmount * 2 // leaves per gallon
@description('Brine time in hours')
param brineTime int = 12
@description('Smoke time per pound in hours')
param smokeTimePerPound int = 1
@description('Temperature for smoking in Fahrenheit')
param smokerTemp int = 225
@description('Type of wood for smoking')
param woodType string = 'applewood'
// Calculated total smoke time based on weight and smoke time per pound
var totalSmokeTime = turkeyWeight * smokeTimePerPound
// Spritz mix - customized with a "mysterious" blend
@description('Spritz ingredients')
param spritzMix array = [
'apple juice'
'vinegar'
'water'
]
@description('Spritz frequency in hours')
param spritzFrequency int = 1
// Display Brine Ingredients
output totalWaterNeeded string = 'Total water needed: ${waterAmount} gallons'
output totalSaltNeeded string = 'Total salt needed: ${saltPerGallonOfWater} cups'
output totalSugarNeeded string = 'Total sugar needed: ${sugarPerGallonOfWater} tablespoons'
output totalHoneyNeeded string = 'Total honey needed: ${honeyPerGallonOfWater} tablespoons'
output totalBlackPepper string = 'Total black pepper needed: ${blackPepperPerGallonOfWater} tablespoons'
output totalBayLeaves string = 'Total bay leaves needed: ${bayLeavesPerGallonOfWater} leaves'
// Display preparation steps for readers
output preparationSteps string = '1. Brine the turkey in the solution for ${brineTime} hours. 2. Prepare the smoker with ${woodType} at ${smokerTemp}°F.'
// Array to represent each hour of smoking with spritz instructions
var smokingProcess = [
for i in range(0, totalSmokeTime): {
hour: i
spritz: (i % spritzFrequency == 0) ? spritzMix : 'No spritz'
}
]
// Final output to reveal to readers the step-by-step smoking process
output smokingInstructions array = [
for item in smokingProcess: {
hour: item.hour
spritz: item.spritz
}
]
// Final output to summarize the smoking process
output recipeSummary string = 'Your turkey breast is ready after smoking for ${totalSmokeTime} hours at ${smokerTemp}°F with periodic spritzing!'
Bits and That Technology BlogAnd here’s the output
{
"preparationSteps": {
"type": "String",
"value": "1. Brine the turkey in the solution for 12 hours. 2. Prepare the smoker with applewood at 225°F."
},
"recipeSummary": {
"type": "String",
"value": "Your turkey breast is ready after smoking for 5 hours at 225°F with periodic spritzing!"
},
"smokingInstructions": {
"type": "Array",
"value": [
{
"hour": 0,
"spritz": [
"apple juice",
"vinegar",
"water"
]
},
{
"hour": 1,
"spritz": [
"apple juice",
"vinegar",
"water"
]
},
{
"hour": 2,
"spritz": [
"apple juice",
"vinegar",
"water"
]
},
{
"hour": 3,
"spritz": [
"apple juice",
"vinegar",
"water"
]
},
{
"hour": 4,
"spritz": [
"apple juice",
"vinegar",
"water"
]
}
]
},
"totalBayLeaves": {
"type": "String",
"value": "Total bay leaves needed: 4 leaves"
},
"totalBlackPepper": {
"type": "String",
"value": "Total black pepper needed: 4 tablespoons"
},
"totalHoneyNeeded": {
"type": "String",
"value": "Total honey needed: 8 tablespoons"
},
"totalSaltNeeded": {
"type": "String",
"value": "Total salt needed: 1 cups"
},
"totalSugarNeeded": {
"type": "String",
"value": "Total sugar needed: 8 tablespoons"
},
"totalWaterNeeded": {
"type": "String",
"value": "Total water needed: 2 gallons"
}
}
Will this recipe win you an award? Probably not. But it’s a solid brine and smoking process for a boneless turkey breast. More importantly, it offers a unique, hands-on way to explore Bicep’s variables, parameters, and loops in action. Whether you’re a cloud professional looking for a creative coding exercise or just curious to mix tech with cooking, this project gives you a fresh perspective on Bicep. Hopefully, it’s as cool to try as it was to create. Happy coding—and smoking!
Leave a Reply