{"id":136,"date":"2024-10-19T11:12:44","date_gmt":"2024-10-19T09:12:44","guid":{"rendered":"https:\/\/j4ni.com\/blog\/?p=136"},"modified":"2025-06-21T01:24:04","modified_gmt":"2025-06-20T23:24:04","slug":"check-bicep-api-version","status":"publish","type":"post","link":"https:\/\/j4ni.com\/blog\/2024\/10\/19\/check-bicep-api-version\/","title":{"rendered":"Bicep Tip: Check for Outdated API Versions in Your Bicep Files"},"content":{"rendered":"<p>Bicep makes infrastructure-as-code simpler, but Azure\u2019s evolving API versions can still trip you up. Microsoft frequently introduces new versions of resource providers, and while the latest version isn&#8217;t always the best fit, it&#8217;s useful to be aware of what you\u2019re currently using.<\/p>\n<p>In this post, you\u2019ll learn how to scan your Bicep files for resource definitions that aren&#8217;t using the latest available API version\u2014so you can review and decide if it\u2019s time to update.<\/p>\n<h2>Why This Matters<\/h2>\n<ul>\n<li>Keep your deployments aligned with the latest Azure features<\/li>\n<li>Detect inconsistent or outdated definitions across environments<\/li>\n<li>Build confidence in code modernization and audit compliance<\/li>\n<\/ul>\n<h2>What the Script Does<\/h2>\n<p>Accepts a single resource type as input, like Microsoft.Storage\/storageAccounts<br \/>\nUses Azure CLI to fetch the latest API version for that resource type<br \/>\nRecursively searches all .bicep files under the current directory<br \/>\nReports which files (and lines) use older or hard-coded API versions<\/p>\n<h2>Usage Example<\/h2>\n<pre><code>.\\Test-BicepApiVersion.ps1 -resourceType \"Microsoft.Storage\/storageAccounts\"<\/code><\/pre>\n<p>This will show all *.bicep files that reference the Microsoft.Storage\/storageAccounts resource type, along with the API version in use.<\/p>\n<pre><code>\r\nparam (\r\n    [string]$resourceType  # Example: 'Microsoft.Storage\/storageAccounts'\r\n)\r\n\r\nif (-not $resourceType) {\r\n    Write-Error \"Please provide a valid resource type (e.g., Microsoft.Storage\/storageAccounts).\"\r\n    exit\r\n}\r\n\r\n# Split resourceType into namespace and resource type\r\n$namespace = $resourceType.Split('\/')[0]\r\n$resource = $resourceType.Split('\/')[1]\r\n\r\n# Get all API versions for the specified resource type\r\n$apiVersions = az provider show --namespace $namespace --query \"resourceTypes[?resourceType=='$resource'].apiVersions\" | ConvertFrom-Json\r\n\r\nif (-not $apiVersions) {\r\n    Write-Error \"Could not retrieve API versions for $resourceType.\"\r\n    exit\r\n}\r\n\r\n# Sort API versions in descending order and select the latest one\r\n$apiVersionList = $apiVersions | Sort-Object -Descending\r\n$latestApiVersion = $apiVersionList[0]\r\n\r\nif (-not $latestApiVersion) {\r\n    Write-Error \"Could not determine the latest API version for $resourceType.\"\r\n    exit\r\n}\r\n\r\nWrite-Host \"Latest API version for $resourceType : $latestApiVersion\"\r\n\r\n# Get all *.bicep files in the current directory and subdirectories\r\n$files = Get-ChildItem -Path . -Recurse -Filter \"*.bicep\"\r\n\r\n# Initialize an array to store the results for Out-GridView\r\n$results = @()\r\n\r\n# Loop through each Bicep file\r\nforeach ($file in $files) {\r\n    $fileContent = Get-Content $file.FullName\r\n\r\n    # Track line number for better reference in the output\r\n    $lineNumber = 0\r\n\r\n    # Look for the resource definition that matches the provided resourceType\r\n    foreach ($line in $fileContent) {\r\n        $lineNumber++\r\n\r\n        if ($line -match $resourceType) {\r\n            # Extract the API version from the resource definition\r\n            if ($line -match \"@(\\d{4}-\\d{2}-\\d{2})(\\S*)\") {\r\n                $foundApiVersion = $matches[1]\r\n\r\n                # Store the file, line, and found API version in an object\r\n                $result = [pscustomobject]@{\r\n                    FileName       = $file.FullName\r\n                    LineNumber     = $lineNumber\r\n                    ApiVersionUsed = $foundApiVersion\r\n                    LineContent    = $line\r\n                }\r\n\r\n                # Add result to the array\r\n                $results += $result\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n# Output to GridView if any outdated API versions are found\r\nif ($results.Count -eq 0) {\r\n    Write-Host \"No API versions found in the Bicep files matching $resourceType.\" -ForegroundColor Yellow\r\n} else {\r\n    if ($IsWindows) {\r\n        $results | Out-GridView -Title \"API Versions Used for $resourceType (Latest: $latestApiVersion)\"\r\n    } else {\r\n        $results | Format-Table -AutoSize\r\n    }\r\n}\r\n<\/code><\/pre>\n<h2>Maintained Version<\/h2>\n<p>This script is part of the <strong>pws-helpers<\/strong> library, publicly maintained on GitHub.<\/p>\n<ul>\n<li><strong>Library:<\/strong> <a href=\"https:\/\/github.com\/Jiihaa\/pws-helpers\/\" target=\"_blank\">https:\/\/github.com\/Jiihaa\/pws-helpers\/<\/a><\/li>\n<li><strong>Script Path:<\/strong> <a href=\"https:\/\/github.com\/Jiihaa\/pws-helpers\/blob\/main\/scripts\/Test-BicepApiVersion.ps1\" target=\"_blank\">scripts\/Test-BicepApiVersion.ps1<\/a><\/li>\n<\/ul>\n<h2>What to Do With the Output<\/h2>\n<p>Once you identify older API versions:<\/p>\n<ul>\n<li>Check the <a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/templates\/\" target=\"_blank\">Azure Bicep Resource Reference<\/a> for breaking changes<\/li>\n<li>Update with caution\u2014newest APIs may introduce changes in required fields<\/li>\n<li>Test changes in non-production environments before rollout<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>Automating your API version checks helps you maintain better control over infrastructure code. While newer versions don\u2019t always mean better, this tool ensures you know where and why you&#8217;re using a specific version.<\/p>\n<p>Pair this with CI\/CD validations or PR checks for improved DevOps practices.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Bicep makes infrastructure-as-code simpler, but Azure\u2019s evolving API versions can still trip you up. Microsoft frequently introduces new versions of resource providers, and while the latest version isn&#8217;t always the best fit, it&#8217;s useful to be aware of what you\u2019re &hellip; <a href=\"https:\/\/j4ni.com\/blog\/2024\/10\/19\/check-bicep-api-version\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,31],"tags":[32,3,5,42],"class_list":["post-136","post","type-post","status-publish","format-standard","hentry","category-azure","category-bicep","tag-api","tag-azure","tag-bicep","tag-test-bicepapiversion-ps"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Check If Your Bicep Files Use the Latest API Version<\/title>\n<meta name=\"description\" content=\"Use this PowerShell script to find outdated API versions in Bicep templates. Scan files, compare against the latest versions, and modernize with confidence.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/j4ni.com\/blog\/2024\/10\/19\/check-bicep-api-version\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Check If Your Bicep Files Use the Latest API Version\" \/>\n<meta property=\"og:description\" content=\"Use this PowerShell script to find outdated API versions in Bicep templates. Scan files, compare against the latest versions, and modernize with confidence.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/j4ni.com\/blog\/2024\/10\/19\/check-bicep-api-version\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Junkyard\" \/>\n<meta property=\"article:published_time\" content=\"2024-10-19T09:12:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-20T23:24:04+00:00\" \/>\n<meta name=\"author\" content=\"Jani Nevalainen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jani Nevalainen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/j4ni.com\\\/blog\\\/2024\\\/10\\\/19\\\/check-bicep-api-version\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/j4ni.com\\\/blog\\\/2024\\\/10\\\/19\\\/check-bicep-api-version\\\/\"},\"author\":{\"name\":\"Jani Nevalainen\",\"@id\":\"https:\\\/\\\/j4ni.com\\\/blog\\\/#\\\/schema\\\/person\\\/6965affa2e3ad32cc3349451a7e51d9a\"},\"headline\":\"Bicep Tip: Check for Outdated API Versions in Your Bicep Files\",\"datePublished\":\"2024-10-19T09:12:44+00:00\",\"dateModified\":\"2025-06-20T23:24:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/j4ni.com\\\/blog\\\/2024\\\/10\\\/19\\\/check-bicep-api-version\\\/\"},\"wordCount\":300,\"publisher\":{\"@id\":\"https:\\\/\\\/j4ni.com\\\/blog\\\/#\\\/schema\\\/person\\\/6965affa2e3ad32cc3349451a7e51d9a\"},\"keywords\":[\"API\",\"azure\",\"bicep\",\"Test-BicepApiVersion.ps\"],\"articleSection\":[\"Azure\",\"Bicep\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/j4ni.com\\\/blog\\\/2024\\\/10\\\/19\\\/check-bicep-api-version\\\/\",\"url\":\"https:\\\/\\\/j4ni.com\\\/blog\\\/2024\\\/10\\\/19\\\/check-bicep-api-version\\\/\",\"name\":\"Check If Your Bicep Files Use the Latest API Version\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/j4ni.com\\\/blog\\\/#website\"},\"datePublished\":\"2024-10-19T09:12:44+00:00\",\"dateModified\":\"2025-06-20T23:24:04+00:00\",\"description\":\"Use this PowerShell script to find outdated API versions in Bicep templates. Scan files, compare against the latest versions, and modernize with confidence.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/j4ni.com\\\/blog\\\/2024\\\/10\\\/19\\\/check-bicep-api-version\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/j4ni.com\\\/blog\\\/2024\\\/10\\\/19\\\/check-bicep-api-version\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/j4ni.com\\\/blog\\\/2024\\\/10\\\/19\\\/check-bicep-api-version\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/j4ni.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Bicep Tip: Check for Outdated API Versions in Your Bicep Files\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/j4ni.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/j4ni.com\\\/blog\\\/\",\"name\":\"Code Junkyard\",\"description\":\"Azure &amp; Bicep , IoT, some Windows dev\u2026 Things I do and hope might help others\",\"publisher\":{\"@id\":\"https:\\\/\\\/j4ni.com\\\/blog\\\/#\\\/schema\\\/person\\\/6965affa2e3ad32cc3349451a7e51d9a\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/j4ni.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/j4ni.com\\\/blog\\\/#\\\/schema\\\/person\\\/6965affa2e3ad32cc3349451a7e51d9a\",\"name\":\"Jani Nevalainen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/j4ni.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/10\\\/cropped-cropped-logo.jpg\",\"url\":\"https:\\\/\\\/j4ni.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/10\\\/cropped-cropped-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/j4ni.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/10\\\/cropped-cropped-logo.jpg\",\"width\":940,\"height\":198,\"caption\":\"Jani Nevalainen\"},\"logo\":{\"@id\":\"https:\\\/\\\/j4ni.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/10\\\/cropped-cropped-logo.jpg\"},\"sameAs\":[\"https:\\\/\\\/j4ni.com\\\/blog\"],\"url\":\"https:\\\/\\\/j4ni.com\\\/blog\\\/author\\\/jiihaa\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Check If Your Bicep Files Use the Latest API Version","description":"Use this PowerShell script to find outdated API versions in Bicep templates. Scan files, compare against the latest versions, and modernize with confidence.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/j4ni.com\/blog\/2024\/10\/19\/check-bicep-api-version\/","og_locale":"en_US","og_type":"article","og_title":"Check If Your Bicep Files Use the Latest API Version","og_description":"Use this PowerShell script to find outdated API versions in Bicep templates. Scan files, compare against the latest versions, and modernize with confidence.","og_url":"https:\/\/j4ni.com\/blog\/2024\/10\/19\/check-bicep-api-version\/","og_site_name":"Code Junkyard","article_published_time":"2024-10-19T09:12:44+00:00","article_modified_time":"2025-06-20T23:24:04+00:00","author":"Jani Nevalainen","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Jani Nevalainen","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/j4ni.com\/blog\/2024\/10\/19\/check-bicep-api-version\/#article","isPartOf":{"@id":"https:\/\/j4ni.com\/blog\/2024\/10\/19\/check-bicep-api-version\/"},"author":{"name":"Jani Nevalainen","@id":"https:\/\/j4ni.com\/blog\/#\/schema\/person\/6965affa2e3ad32cc3349451a7e51d9a"},"headline":"Bicep Tip: Check for Outdated API Versions in Your Bicep Files","datePublished":"2024-10-19T09:12:44+00:00","dateModified":"2025-06-20T23:24:04+00:00","mainEntityOfPage":{"@id":"https:\/\/j4ni.com\/blog\/2024\/10\/19\/check-bicep-api-version\/"},"wordCount":300,"publisher":{"@id":"https:\/\/j4ni.com\/blog\/#\/schema\/person\/6965affa2e3ad32cc3349451a7e51d9a"},"keywords":["API","azure","bicep","Test-BicepApiVersion.ps"],"articleSection":["Azure","Bicep"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/j4ni.com\/blog\/2024\/10\/19\/check-bicep-api-version\/","url":"https:\/\/j4ni.com\/blog\/2024\/10\/19\/check-bicep-api-version\/","name":"Check If Your Bicep Files Use the Latest API Version","isPartOf":{"@id":"https:\/\/j4ni.com\/blog\/#website"},"datePublished":"2024-10-19T09:12:44+00:00","dateModified":"2025-06-20T23:24:04+00:00","description":"Use this PowerShell script to find outdated API versions in Bicep templates. Scan files, compare against the latest versions, and modernize with confidence.","breadcrumb":{"@id":"https:\/\/j4ni.com\/blog\/2024\/10\/19\/check-bicep-api-version\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/j4ni.com\/blog\/2024\/10\/19\/check-bicep-api-version\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/j4ni.com\/blog\/2024\/10\/19\/check-bicep-api-version\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/j4ni.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Bicep Tip: Check for Outdated API Versions in Your Bicep Files"}]},{"@type":"WebSite","@id":"https:\/\/j4ni.com\/blog\/#website","url":"https:\/\/j4ni.com\/blog\/","name":"Code Junkyard","description":"Azure &amp; Bicep , IoT, some Windows dev\u2026 Things I do and hope might help others","publisher":{"@id":"https:\/\/j4ni.com\/blog\/#\/schema\/person\/6965affa2e3ad32cc3349451a7e51d9a"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/j4ni.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/j4ni.com\/blog\/#\/schema\/person\/6965affa2e3ad32cc3349451a7e51d9a","name":"Jani Nevalainen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/j4ni.com\/blog\/wp-content\/uploads\/2021\/10\/cropped-cropped-logo.jpg","url":"https:\/\/j4ni.com\/blog\/wp-content\/uploads\/2021\/10\/cropped-cropped-logo.jpg","contentUrl":"https:\/\/j4ni.com\/blog\/wp-content\/uploads\/2021\/10\/cropped-cropped-logo.jpg","width":940,"height":198,"caption":"Jani Nevalainen"},"logo":{"@id":"https:\/\/j4ni.com\/blog\/wp-content\/uploads\/2021\/10\/cropped-cropped-logo.jpg"},"sameAs":["https:\/\/j4ni.com\/blog"],"url":"https:\/\/j4ni.com\/blog\/author\/jiihaa\/"}]}},"_links":{"self":[{"href":"https:\/\/j4ni.com\/blog\/wp-json\/wp\/v2\/posts\/136","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/j4ni.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/j4ni.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/j4ni.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/j4ni.com\/blog\/wp-json\/wp\/v2\/comments?post=136"}],"version-history":[{"count":4,"href":"https:\/\/j4ni.com\/blog\/wp-json\/wp\/v2\/posts\/136\/revisions"}],"predecessor-version":[{"id":209,"href":"https:\/\/j4ni.com\/blog\/wp-json\/wp\/v2\/posts\/136\/revisions\/209"}],"wp:attachment":[{"href":"https:\/\/j4ni.com\/blog\/wp-json\/wp\/v2\/media?parent=136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/j4ni.com\/blog\/wp-json\/wp\/v2\/categories?post=136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/j4ni.com\/blog\/wp-json\/wp\/v2\/tags?post=136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}