{"id":11326,"date":"2026-05-24T07:18:44","date_gmt":"2026-05-24T12:18:44","guid":{"rendered":"https:\/\/stevepedwards.today\/DebianAdmin\/?p=11326"},"modified":"2026-05-24T13:19:06","modified_gmt":"2026-05-24T18:19:06","slug":"saving-and-uploading-bicep-templates","status":"publish","type":"post","link":"https:\/\/stevepedwards.today\/DebianAdmin\/saving-and-uploading-bicep-templates\/","title":{"rendered":"Saving and Uploading Bicep Templates &#8211; 2 Peered VMs Code, add Private DNS"},"content":{"rendered":"<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_11326\" class=\"pvc_stats all  \" data-element-id=\"11326\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p>Saving and Uploading Bicep Templates:<\/p>\n<p><strong>Step 1: Export the Template from your Resource Group<\/strong><\/p>\n<p>Instead of exporting individual VMs, you want to capture the entire Resource Group so it links the VNets, the Peering, the Bastion host, and the VMs together in one blueprint.<\/p>\n<ol>\n<li>In the main Azure search bar, type <strong>Resource groups<\/strong> and select the specific resource group holding your lab.<\/li>\n<li>In the left-hand menu, scroll all the way down to the <strong>Automation<\/strong> section.<\/li>\n<li>Click on <strong>Export template or Copy the code and Paste into VS Studio etc<\/strong>.<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1366\" height=\"720\" class=\"wp-image-11341\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-1-2.png\" srcset=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-1-2.png 1366w, https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-1-2-300x158.png 300w, https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-1-2-1024x540.png 1024w, https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-1-2-768x405.png 768w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1366\" height=\"720\" class=\"wp-image-11342\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-2-2.png\" srcset=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-2-2.png 1366w, https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-2-2-300x158.png 300w, https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-2-2-1024x540.png 1024w, https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-2-2-768x405.png 768w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<p>You can check for relevant recent code additions with Ctrl F, eg. Search DNS above etc<\/p>\n<p><strong>Step 2: Switch the Output to Bicep<\/strong><\/p>\n<p>Microsoft integrated native Bicep conversion directly into this blade!<\/p>\n<ol>\n<li>At the top of the code window, look at the language tabs. Click the tab that says <strong>Bicep<\/strong>.<\/li>\n<li>The code will instantly transform from ugly, complicated JSON into clean, readable Bicep syntax.<\/li>\n<li>Click the <strong>Download<\/strong> button at the top menu bar. This will download a zip file containing your complete infrastructure code (usually named template.bicep and parameters.json) straight to your local computer.<\/li>\n<\/ol>\n<p><strong>?? Crucial AZ-700 \"Gotchas\" to Fix Before Re-uploading<\/strong><\/p>\n<p>While the Export tool is incredible, Azure's automation leaves a few traps in the code that will cause errors if you just try to upload it blindly later. Open your downloaded template.bicep file in Notepad or VS Code and check for these three things:<\/p>\n<p><strong>1. The VNet Peering Missing Link<\/strong><\/p>\n<p>When you export a template, Azure exports the <em>state<\/em> of the objects. VNet Peering requires a bidirectional handshake. The exported code will absolutely include the definitions for hub-to-spoke and spoke-to-hub, but sometimes the portal's exporter strips out the underlying nested link references. Look at the code block containing Microsoft.Network\/virtualNetworks\/virtualNetworkPeerings to make sure both directions are explicitly defined in the resource loops.<\/p>\n<p><strong>2. Clear Out the Internal VM Passwords<\/strong><\/p>\n<p>For security, Azure <strong>will never export the admin passwords<\/strong> you typed in for your Windows 11 VMs. In your Bicep file, you will see a parameter or property under the VM resource called adminPassword. It will either be completely blank or say something like null.<\/p>\n<ul>\n<li><em>Before you re-deploy it in the future, you must manually type a password string into that parameter, or the deployment will fail immediately.<\/em><\/li>\n<\/ul>\n<p><strong>3. Wipe Out Stale Hard-coded Virtual Machine IDs<\/strong><\/p>\n<p>The template will hard-code the unique internal resource IDs and specific system-generated names of the virtual hard disks (VHDs) currently attached to your running VMs. If you try to run the script in a brand new, empty resource group, Azure will fail because those specific old storage blobs don't exist there yet. You may need to change the disk creation properties from Attach to FromImage or CreateNew so it creates fresh drives on deployment.<\/p>\n<p>Check the file in VS Code and the Visualiser (top right net tree icon):<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1366\" height=\"720\" class=\"wp-image-11343\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-3-2.png\" srcset=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-3-2.png 1366w, https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-3-2-300x158.png 300w, https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-3-2-1024x540.png 1024w, https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-3-2-768x405.png 768w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<p><strong>Run the Test Deployment via the Terminal<\/strong><\/p>\n<p>Instead of deleting your resource group blindly, you can run a <strong>What-If<\/strong> command. This tells Azure to read your Bicep file and report back exactly what it <em>would<\/em> create, modify, or destroy without actually making changes yet.<\/p>\n<p>Open the integrated terminal in VS Code (Ctrl + ~) and run these three steps:<\/p>\n<p><strong>Step A: Connect to Azure<\/strong><\/p>\n<p>Type the following command and press Enter. A browser window will pop up asking you to sign in to your Azure account:<\/p>\n<p>PowerShell<\/p>\n<p>Connect-AzAccount<\/p>\n<p><strong>Step B: Run the \"What-If\" Validation Test<\/strong><\/p>\n<p>Run this command to simulate the deployment against your target resource group. Because the template includes secure password parameters, PowerShell will safely pause and prompt you to type a password for your VMs:<\/p>\n<p>PowerShell<\/p>\n<p>New-AzResourceGroupDeployment -ResourceGroupName \"rg1\" -TemplateFile \".\\peering.bicep\" -WhatIf<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1366\" height=\"720\" class=\"wp-image-11344\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-4-1.png\" srcset=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-4-1.png 1366w, https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-4-1-300x158.png 300w, https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-4-1-1024x540.png 1024w, https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-4-1-768x405.png 768w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<p>Azure will analyze the template and print out a color-coded text map showing you exactly what it intends to build. If there are any syntax errors or capacity limitations, they will show up here in bright red text.<\/p>\n<p><strong>Step C: Execute the Real Rebuild<\/strong><\/p>\n<p>Once you are happy with the simulation, go ahead and delete your old resource group in the portal. Then, simply run the deployment command for real from your VS Code terminal to build the entire lab:<\/p>\n<p>PowerShell \u2013 Create the resource group first:<\/p>\n<p>New-AzResourceGroup -Name \"rg1\" -Location \"belgiumcentral\"<\/p>\n<p>Now run the bicep template:<\/p>\n<p>New-AzResourceGroupDeployment -ResourceGroupName \"rg1\" -TemplateFile \".\\peering.bicep\"<\/p>\n<p>Type in your passwords when prompted, sit back, and watch the terminal spin up your networks, peering links, and virtual machines automatically!<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1366\" height=\"720\" class=\"wp-image-11345\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-5-1.png\" srcset=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-5-1.png 1366w, https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-5-1-300x158.png 300w, https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-5-1-1024x540.png 1024w, https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-5-1-768x405.png 768w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<p><strong>How You Upload and Run It Next Time<\/strong><\/p>\n<p>When you want to spin this exact lab back up, you don't even need to open the portal wizard. You open <strong>PowerShell<\/strong> on your local computer, log into your account, and run a single command pointing to your saved file:<\/p>\n<p>PowerShell<\/p>\n<p>CD to the folder of you template:<\/p>\n<p>Cd C:\\Users\\steve\\Desktop\\RecentDocs\\AzureCode\\PeeringVMs<\/p>\n<p>New-AzResourceGroupDeployment -ResourceGroupName \"rg1\" -TemplateFile \".\\template.bicep\"<\/p>\n<p>You have officially graduated from clicking buttons to deploying Infrastructure as Code. Save those files in a safe folder on your machine\u2014you just captured your hard work into a reusable cloud blueprint!<\/p>\n<p>You can check on the Deployment status in:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1366\" height=\"720\" class=\"wp-image-11346\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-6.png\" srcset=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-6.png 1366w, https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-6-300x158.png 300w, https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-6-1024x540.png 1024w, https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2026\/05\/word-image-11326-6-768x405.png 768w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_11326\" class=\"pvc_stats all  \" data-element-id=\"11326\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p>Saving and Uploading Bicep Templates: Step 1: Export the Template from your Resource Group Instead of exporting individual VMs, you want to capture the entire Resource Group so it links the VNets, the Peering, the Bastion host, and the VMs together in one blueprint. In the main Azure search bar, type Resource groups and select <a href=\"https:\/\/stevepedwards.today\/DebianAdmin\/saving-and-uploading-bicep-templates\/\" class=\"more-link\">...<span class=\"screen-reader-text\">\u00a0 Saving and Uploading Bicep Templates &#8211; 2 Peered VMs Code, add Private DNS<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-11326","post","type-post","status-publish","format-standard","hentry","category-post"],"a3_pvc":{"activated":true,"total_views":8,"today_views":0},"_links":{"self":[{"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/posts\/11326","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/comments?post=11326"}],"version-history":[{"count":6,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/posts\/11326\/revisions"}],"predecessor-version":[{"id":11347,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/posts\/11326\/revisions\/11347"}],"wp:attachment":[{"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/media?parent=11326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/categories?post=11326"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/tags?post=11326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}