Skip to content

Commit

Permalink
added-schemas to exported definitions (#397)
Browse files Browse the repository at this point in the history
Co-authored-by: Hunor Borondy <[email protected]>
  • Loading branch information
borondy and Hunor Borondy authored Oct 18, 2023
1 parent 507bdf2 commit 8a29136
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions Scripts/Helpers/Out-PolicyAssignmentFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function Out-PolicyAssignmentFile {
}

$assignmentDefinition = [ordered]@{
'$schema' = "https://raw.githubusercontent.com/Azure/enterprise-azure-policy-as-code/main/Schemas/policy-assignment-schema.json"
nodeName = "/root"
definitionEntry = $definitionEntry
}
Expand Down
9 changes: 8 additions & 1 deletion Scripts/Helpers/Out-PolicyDefinition.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ function Out-PolicyDefinition {

# Write the content
Remove-NullFields $Definition
$json = ConvertTo-Json $Definition -Depth 100
$outDefinition = [PSCustomObject]@{'$schema' = "https://raw.githubusercontent.com/Azure/enterprise-azure-policy-as-code/main/Schemas/policy-definition-schema.json" }

# update schema if policy set
if ($Definition.properties.policyDefinitions) {
$outDefinition.'$schema' = "https://raw.githubusercontent.com/Azure/enterprise-azure-policy-as-code/main/Schemas/policy-set-definition-schema.json"
}
$Definition.psobject.Properties.ForEach{ ($outDefinition).psobject.Properties.Add($_, $true) }
$json = ConvertTo-Json $outDefinition -Depth 100
$null = New-Item $fullPath -Force -ItemType File -Value $json
}
6 changes: 4 additions & 2 deletions Scripts/Helpers/Out-PolicyExemptions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ function Out-PolicyExemptions {
if (Test-Path $jsonFile) {
Remove-Item $jsonFile
}
$outputJsonObj = @{
$outputJsonObj = [ordered]@{
'$schema' = "https://raw.githubusercontent.com/Azure/enterprise-azure-policy-as-code/main/Schemas/policy-exemption-schema.json"
exemptions = $jsonArray
}
ConvertTo-Json $outputJsonObj -Depth 100 | Out-File $jsonFile -Force
Expand Down Expand Up @@ -187,7 +188,8 @@ function Out-PolicyExemptions {
if (Test-Path $jsonFile) {
Remove-Item $jsonFile
}
$outputJsonObj = @{
$outputJsonObj = [ordered]@{
'$schema' = "https://raw.githubusercontent.com/Azure/enterprise-azure-policy-as-code/main/Schemas/policy-exemption-schema.json"
exemptions = $jsonArray
}
ConvertTo-Json $outputJsonObj -Depth 100 | Out-File $jsonFile -Force
Expand Down

0 comments on commit 8a29136

Please sign in to comment.