From 9312964b501fd04dabc0bef2f422591c0f410729 Mon Sep 17 00:00:00 2001 From: Brian Moore Date: Tue, 4 Oct 2022 10:48:42 -0500 Subject: [PATCH] added exception for old bicep version (#699) Co-authored-by: azure-quickstart-templates pipeline --- .../apiVersions-Should-Be-Recent.test.ps1 | 16 +++++--- .../Fail/not-bicep-module.json | 36 ++++++++++++++++++ .../Pass/bicep-module.json | 38 +++++++++++++++++++ 3 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 unit-tests/apiversions-should-be-recent/Fail/not-bicep-module.json create mode 100644 unit-tests/apiversions-should-be-recent/Pass/bicep-module.json diff --git a/arm-ttk/testcases/deploymentTemplate/apiVersions-Should-Be-Recent.test.ps1 b/arm-ttk/testcases/deploymentTemplate/apiVersions-Should-Be-Recent.test.ps1 index 9cee36ea..ffa6a806 100644 --- a/arm-ttk/testcases/deploymentTemplate/apiVersions-Should-Be-Recent.test.ps1 +++ b/arm-ttk/testcases/deploymentTemplate/apiVersions-Should-Be-Recent.test.ps1 @@ -34,11 +34,13 @@ param( # Test Run Date - date to use when doing comparisons, if not current date (used for unit testing against and old cache) [Parameter(Mandatory = $false, Position = 3)] [datetime] - $TestDate = [DateTime]::Now + $TestDate = [DateTime]::Now, + [Parameter(Mandatory = $true)] + [PSCustomObject] + $TemplateMetadata ) - if (-not $TemplateObject.resources) { # If we don't have any resources # then it's probably a partial template, and there's no apiVersions to check anyway, @@ -48,10 +50,6 @@ if (-not $TemplateObject.resources) { # First, find all of the API versions in the main template resources. $allApiVersions = Find-JsonContent -Key apiVersion -Value * -Like -InputObject $TemplateObject - - - - foreach ($av in $allApiVersions) { <# @@ -141,6 +139,12 @@ foreach ($av in $allApiVersions) { $apiString = $av.ApiVersion $hasDate = $apiString -match "(?\d{4,4})-(?\d{2,2})-(?\d{2,2})" + # bicep - if this is a bicep module skip this test for the given resource + if( $FullResourceType -eq "Microsoft.Resources/deployments" -and + $TemplateMetadata._generator.name -eq 'bicep') { + continue + } + if (-not $hasDate) { # If we couldn't, write an error diff --git a/unit-tests/apiversions-should-be-recent/Fail/not-bicep-module.json b/unit-tests/apiversions-should-be-recent/Fail/not-bicep-module.json new file mode 100644 index 00000000..9664792c --- /dev/null +++ b/unit-tests/apiversions-should-be-recent/Fail/not-bicep-module.json @@ -0,0 +1,36 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "metadata": { + "_generator": { + "name": "not-bicep" + } + }, + "parameters": { }, + "resources": [ + { + "type": "Microsoft.Resources/deployments", + "apiVersion": "2015-01-01", + "name": "nested", + "properties": { + "expressionEvaluationOptions": { + "scope": "inner" + }, + "mode": "Incremental", + "parameters": { }, + "template": { + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "metadata": { + "_generator": { + "name": "bicep", + "version": "0.5.6.12127", + "templateHash": "6034226420560042393" + } + }, + "resources": [ ] + } + } + } + ] + } \ No newline at end of file diff --git a/unit-tests/apiversions-should-be-recent/Pass/bicep-module.json b/unit-tests/apiversions-should-be-recent/Pass/bicep-module.json new file mode 100644 index 00000000..6f641ef3 --- /dev/null +++ b/unit-tests/apiversions-should-be-recent/Pass/bicep-module.json @@ -0,0 +1,38 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "metadata": { + "_generator": { + "name": "bicep", + "version": "0.5.6.12127", + "templateHash": "16815708176905569328" + } + }, + "parameters": { }, + "resources": [ + { + "type": "Microsoft.Resources/deployments", + "apiVersion": "2015-01-01", + "name": "nested", + "properties": { + "expressionEvaluationOptions": { + "scope": "inner" + }, + "mode": "Incremental", + "parameters": { }, + "template": { + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "metadata": { + "_generator": { + "name": "bicep", + "version": "0.5.6.12127", + "templateHash": "6034226420560042393" + } + }, + "resources": [ ] + } + } + } + ] + } \ No newline at end of file