Skip to content
This repository has been archived by the owner on Jan 30, 2025. It is now read-only.

Commit

Permalink
Support schema validation (Azure#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
SenthuranSivananthan authored May 9, 2022
1 parent 1d8dbd7 commit ce6c27f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 3 deletions.
8 changes: 5 additions & 3 deletions scripts/deployments/Functions/EnvironmentContext.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,18 @@ function New-EnvironmentContext {
WorkingDirectory = $WorkingDirectory

RolesDirectory = "$WorkingDirectory/roles"

PolicyCustomDefinitionDirectory = "$PolicyDirectory/custom/definitions/policy"
PolicySetCustomDefinitionDirectory = "$PolicyDirectory/custom/definitions/policyset"
PolicySetCustomAssignmentsDirectory = "$PolicyDirectory/custom/assignments"
PolicySetBuiltInAssignmentsDirectory = "$PolicyDirectory/builtin/assignments"


SchemaDirectory = "$WorkingDirectory/schemas/latest"

LoggingDirectory = "$WorkingDirectory/config/logging/$Environment"
NetworkingDirectory = "$WorkingDirectory/config/networking/$Environment"
SubscriptionsDirectory = "$WorkingDirectory/config/subscriptions/$Environment"

Variables = $Variables
ManagementGroupHierarchy = $ManagementGroupHierarchy

Expand Down
13 changes: 13 additions & 0 deletions scripts/deployments/Functions/HubNetworkWithAzureFirewall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ function Get-AzureFirewallPolicy {

function Set-AzureFirewallPolicy {
param (
[Parameter(Mandatory = $true)]
$Context,

[Parameter(Mandatory = $true)]
[String]$Region,

Expand All @@ -45,6 +48,11 @@ function Set-AzureFirewallPolicy {

Set-AzContext -Subscription $SubscriptionId

$SchemaFilePath = "$($Context.SchemaDirectory)/landingzones/lz-platform-connectivity-hub-azfw-policy.json"

Write-Output "Validation JSON parameter configuration using $SchemaFilePath"
Get-Content -Raw $ConfigurationFilePath | Test-Json -SchemaFile $SchemaFilePath

Write-Output "Deploying to $SubscriptionId in $Region using $ConfigurationFilePath"

New-AzSubscriptionDeployment `
Expand Down Expand Up @@ -80,6 +88,11 @@ function Set-HubNetwork-With-AzureFirewall {

Set-AzContext -Subscription $SubscriptionId

$SchemaFilePath = "$($Context.SchemaDirectory)/landingzones/lz-platform-connectivity-hub-azfw.json"

Write-Output "Validation JSON parameter configuration using $SchemaFilePath"
Get-Content -Raw $ConfigurationFilePath | Test-Json -SchemaFile $SchemaFilePath

# Load networking configuration
$Configuration = Get-Content $ConfigurationFilePath | ConvertFrom-Json -Depth 100

Expand Down
5 changes: 5 additions & 0 deletions scripts/deployments/Functions/HubNetworkWithNVA.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ function Set-HubNetwork-With-NVA {

Set-AzContext -Subscription $SubscriptionId

$SchemaFilePath = "$($Context.SchemaDirectory)/landingzones/lz-platform-connectivity-hub-nva.json"

Write-Output "Validation JSON parameter configuration using $SchemaFilePath"
Get-Content -Raw $ConfigurationFilePath | Test-Json -SchemaFile $SchemaFilePath

# Load networking configuration
$Configuration = Get-Content $ConfigurationFilePath | ConvertFrom-Json -Depth 100

Expand Down
8 changes: 8 additions & 0 deletions scripts/deployments/Functions/Logging.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ function Get-LoggingConfiguration {

function Set-Logging {
param (
[Parameter(Mandatory = $true)]
$Context,

[Parameter(Mandatory = $true)]
[String]$Region,

Expand All @@ -52,6 +55,11 @@ function Set-Logging {

Set-AzContext -Subscription $SubscriptionId

$SchemaFilePath = "$($Context.SchemaDirectory)/landingzones/lz-platform-logging.json"

Write-Output "Validation JSON parameter configuration using $SchemaFilePath"
Get-Content -Raw $ConfigurationFilePath | Test-Json -SchemaFile $SchemaFilePath

Write-Output "Moving Subscription ($SubscriptionId) to Management Group ($ManagementGroupId)"
New-AzManagementGroupDeployment `
-ManagementGroupId $ManagementGroupId `
Expand Down
7 changes: 7 additions & 0 deletions scripts/deployments/Functions/Subscriptions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ function Set-Subscriptions {
Write-Output " - Archetype: $ArchetypeName"
Write-Output " - Region: $DeploymentRegion"

Set-AzContext -Subscription $SubscriptionId

$SchemaFilePath = "$($Context.SchemaDirectory)/landingzones/lz-$ArchetypeName.json"

Write-Output "Validation JSON parameter configuration using $SchemaFilePath"
Get-Content -Raw $FilePath | Test-Json -SchemaFile $SchemaFilePath

$Configuration = Get-Content $FilePath | ConvertFrom-Json -Depth 100

#region Check if Log Analytics Workspace Id is provided. Otherwise set it.
Expand Down
4 changes: 4 additions & 0 deletions scripts/deployments/RunWorkflows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ Param(

#Requires -Modules Az, powershell-yaml

$ErrorActionPreference = "Stop"

# In order to use this End to End script, you must configure ARM template configurations for Logging, Networking and Subscriptions.
# Please follow the instructions on https://github.com/Azure/CanadaPubSecALZ/blob/main/docs/onboarding/azure-devops-pipelines.md
# to setup the configuration files. Once the configuration files are setup, you can choose to run this script or use Azure DevOps.
Expand Down Expand Up @@ -188,6 +190,7 @@ if ($DeployRoles) {
if ($DeployLogging) {
Write-Host "Deploying Logging..."
Set-Logging `
-Context $Context `
-Region $Context.Variables['var-logging-region'] `
-ManagementGroupId $Context.Variables['var-logging-managementGroupId'] `
-SubscriptionId $Context.Variables['var-logging-subscriptionId'] `
Expand Down Expand Up @@ -266,6 +269,7 @@ if ($DeployHubNetworkWithAzureFirewall) {

# Create Azure Firewall Policy
Set-AzureFirewallPolicy `
-Context $Context `
-Region $Context.Variables['var-hubnetwork-region'] `
-SubscriptionId $Context.Variables['var-hubnetwork-subscriptionId'] `
-ConfigurationFilePath "$($Context.NetworkingDirectory)/$($Context.Variables['var-hubnetwork-azfwPolicy-configurationFileName'])"
Expand Down

0 comments on commit ce6c27f

Please sign in to comment.