Skip to content

Commit aeb8798

Browse files
Merge pull request #303 from sumantshiv/tempValFixes
Multiple Template validator fixes.
2 parents f06324f + 63e3606 commit aeb8798

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

CloudCapabilities/AzureRM.CloudCapabilities.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function Get-AzureRMCloudCapability() {
3434
foreach ($providerNamespace in $providerNamespaces) {
3535
Write-Verbose "Working on $providerNamespace provider namespace"
3636
try {
37-
$resourceTypes = (Get-AzureRmResourceProvider -ProviderNamespace $providerNamespace -Location $location -ErrorAction Stop).ResourceTypes
37+
$resourceTypes = (Get-AzureRmResourceProvider -ProviderNamespace $providerNamespace -ErrorAction Stop | Where-Object {$_.Locations -contains $location -or $_.Locations -contains "global"}).ResourceTypes
3838
foreach ($resourceType in $resourceTypes) {
3939
$result = "" | Select-Object ProviderNamespace, ResourceTypeName, Locations, ApiVersions
4040
$result.ProviderNamespace = $providerNamespace

TemplateValidator/AzureRM.TemplateValidator.psm1

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,76 @@ $Global:VerbosePreference = 'SilentlyContinue'
88
function Test-AzureRMTemplate() {
99
[CmdletBinding()]
1010
param(
11-
[Parameter(Mandatory = $true, HelpMessage = "Template directory or TemplateFullPath to Validate")]
11+
[Parameter(Mandatory = $true, HelpMessage = "Template directory or TemplateFullPath to Validate", ParameterSetName = "local")]
1212
[ValidateScript( { Test-Path -Path $_ })]
1313
[String] $TemplatePath,
14+
15+
[Parameter(Mandatory = $true, HelpMessage = "Template url to Validate", ParameterSetName = "url")]
16+
[String] $TemplateUrl,
17+
18+
[Parameter(ParameterSetName = "local")]
19+
[Parameter(ParameterSetName = "url")]
1420
[Parameter(HelpMessage = "Template Pattern to match.Default is *azuredeploy.json")]
1521
[String] $TemplatePattern = "*azuredeploy.json",
22+
1623
[Parameter(Mandatory = $true, HelpMessage = "Cloud Capabilities JSON File Name in the current folder or with full path")]
24+
[Parameter(ParameterSetName = "local")]
25+
[Parameter(ParameterSetName = "url")]
1726
[ValidateScript( { Test-Path -Path $_ })]
1827
[String] $CapabilitiesPath,
28+
1929
[Parameter(HelpMessage = "Set to process VMImages , VMExtensions & VMSizes")]
30+
[Parameter(ParameterSetName = "local")]
31+
[Parameter(ParameterSetName = "url")]
2032
[Switch] $IncludeComputeCapabilities,
33+
2134
[Parameter(HelpMessage = "Set to process Storage Skus")]
35+
[Parameter(ParameterSetName = "local")]
36+
[Parameter(ParameterSetName = "url")]
2237
[Switch] $IncludeStorageCapabilities,
38+
2339
[Parameter(HelpMessage = "Output Report FileName")]
40+
[Parameter(ParameterSetName = "local")]
41+
[Parameter(ParameterSetName = "url")]
2442
[String] $Report = "TemplateValidationReport.html"
2543
)
44+
2645
$capabilities = ConvertFrom-Json (Get-Content -Path $CapabilitiesPath -Raw) -ErrorAction Stop
27-
$TemplateDirectory = Get-ChildItem -Path $TemplatePath -Recurse -Include $TemplatePattern
46+
47+
if ($PSCmdlet.ParameterSetName -eq "url")
48+
{
49+
$pathTokens = $TemplateUrl.Split("/")
50+
$filename = $pathTokens[-1]
51+
$fileDir = $pathTokens[-2]
52+
$rootPath = $env:TEMP
53+
54+
$localDirPath = Join-Path -Path $rootPath -ChildPath $fileDir
55+
56+
if(Test-Path($localDirPath))
57+
{
58+
Remove-Item -Path $localDirPath -Recurse -Force -ErrorAction Stop
59+
}
60+
61+
New-Item -Path $localDirPath -ItemType Directory -Force | Out-Null
62+
63+
$sourcePath = Join-Path -Path $localDirPath -ChildPath $filename
64+
Invoke-WebRequest -Uri $TemplateUrl -OutFile $sourcePath -Verbose -ErrorAction Stop
65+
66+
if([IO.Path]::GetExtension($filename) -eq ".zip")
67+
{
68+
$expandedPath = Join-Path -Path $localDirPath -ChildPath ([IO.Path]::GetFileNameWithoutExtension($filename))
69+
Expand-archive $sourcePath -DestinationPath $expandedPath -ErrorAction Stop
70+
$sourcePath = $expandedPath
71+
}
72+
73+
}
74+
else
75+
{
76+
$sourcePath = $TemplatePath
77+
}
78+
79+
80+
$TemplateDirectory = Get-ChildItem -Path $sourcePath -Recurse -Include $TemplatePattern
2881
$reportOutPut = @()
2982
$totalCount = 0
3083
$warningCount = 0
Binary file not shown.

0 commit comments

Comments
 (0)