Skip to content

Commit

Permalink
added exception for old bicep version (#699)
Browse files Browse the repository at this point in the history
Co-authored-by: azure-quickstart-templates pipeline <[email protected]>
  • Loading branch information
bmoore-msft and azure-quickstart-templates pipeline authored Oct 4, 2022
1 parent 232b00a commit 9312964
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {

<#
Expand Down Expand Up @@ -141,6 +139,12 @@ foreach ($av in $allApiVersions) {
$apiString = $av.ApiVersion
$hasDate = $apiString -match "(?<Year>\d{4,4})-(?<Month>\d{2,2})-(?<Day>\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

Expand Down
36 changes: 36 additions & 0 deletions unit-tests/apiversions-should-be-recent/Fail/not-bicep-module.json
Original file line number Diff line number Diff line change
@@ -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": [ ]
}
}
}
]
}
38 changes: 38 additions & 0 deletions unit-tests/apiversions-should-be-recent/Pass/bicep-module.json
Original file line number Diff line number Diff line change
@@ -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": [ ]
}
}
}
]
}

0 comments on commit 9312964

Please sign in to comment.