Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Invoke-PolicyToBicep.ps1 Scripts to Handle -'s, 's (spaces) & ' apostrophes + Fix #254 #288

Merged
merged 26 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8d2de73
update policy to bicep script to handle spaces and hyphens for txt fi…
jtracey93 Jul 15, 2022
7dc3568
add support for apostrophe escaping
jtracey93 Jul 18, 2022
05cc1bb
adding parameters
SeSeicht Jul 18, 2022
1e43b21
update path and name vars
SeSeicht Jul 18, 2022
28684c7
Merge pull request #1 from SeSeicht/seseicht/policyScriptOptimization
jtracey93 Jul 18, 2022
dc3ddbe
add more params
SeSeicht Jul 18, 2022
edbf454
remove comment
SeSeicht Jul 18, 2022
1db4cdd
add param vars for sets
jtracey93 Jul 18, 2022
6ea09f0
Merge remote-tracking branch 'jack/fix-pol-to-bicep-hyphens' into ses…
SeSeicht Jul 18, 2022
f65a8a2
fixing empty paramters file bug
SeSeicht Jul 18, 2022
e929e9e
Merge pull request #2 from SeSeicht/seseicht/PolicytoBicepScriptParams
jtracey93 Jul 18, 2022
f207eb9
ps1 updates
jtracey93 Jul 18, 2022
84a2aa6
updates
jtracey93 Jul 18, 2022
2f75364
linter fixes
jtracey93 Jul 18, 2022
be8dbfb
add should process
jtracey93 Jul 18, 2022
269d177
surpress false positives
jtracey93 Jul 18, 2022
5a96fe3
update azure public policies
jtracey93 Jul 18, 2022
dcf28e7
update mc policies
jtracey93 Jul 18, 2022
dc665c3
wiki update
jtracey93 Jul 18, 2022
16752b6
update codetour
jtracey93 Jul 18, 2022
ff98612
more docs
jtracey93 Jul 18, 2022
574bc67
add hyphen support
jtracey93 Jul 18, 2022
c6b5d85
updates to indents
jtracey93 Jul 18, 2022
3cb0031
docs
jtracey93 Jul 18, 2022
f9371d5
Update .github/scripts/Invoke-PolicyToBicep-China.ps1
jtracey93 Jul 19, 2022
ccae11e
Update .github/scripts/Invoke-PolicyToBicep.ps1
jtracey93 Jul 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
293 changes: 192 additions & 101 deletions .github/scripts/Invoke-PolicyToBicep-China.ps1

Large diffs are not rendered by default.

293 changes: 192 additions & 101 deletions .github/scripts/Invoke-PolicyToBicep.ps1

Large diffs are not rendered by default.

50 changes: 24 additions & 26 deletions .vscode/tours/upstreamPolicyUpdateProcess.tour
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,11 @@
},
"end": {
"line": 11,
"character": 155
"character": 18
}
},
"description": "Create and overwrite the `_policyDefinitionsBicepInput.txt` file in the specified directory with a new empty file with `utf8` encoding"
"description": "Create and overwrite the `_policyDefinitionsBicepInput.txt` file in the specified directory with a new empty file with `utf8` encoding",
"line": 44
},
{
"file": ".github/scripts/Invoke-PolicyToBicep.ps1",
Expand All @@ -223,7 +224,8 @@
"character": 264
}
},
"description": "For every `.json` file in the `lib/policy_definitions` directory extract the policy definition name and the file path and then write them (append) into the `_policyDefinitionsBicepInput.txt` file in a Bicep formatted output (see end of line 21)"
"description": "For every `.json` file in the `lib/policy_definitions` directory extract the policy definition name and the file path and then write them (append) into the `_policyDefinitionsBicepInput.txt` file in a Bicep formatted output (see end of line 54)",
"line": 47
},
{
"file": ".github/scripts/Invoke-PolicyToBicep.ps1",
Expand All @@ -237,49 +239,42 @@
"character": 102
}
},
"description": "Count the number of policy definitions in the `lib/policy_definitions` directory and output to the console the total number"
"description": "Count the number of policy definitions in the `lib/policy_definitions` directory and output to the console the total number",
"line": 57
},
{
"file": ".github/scripts/Invoke-PolicyToBicep.ps1",
"selection": {
"start": {
"line": 30,
"line": 110,
"character": 1
},
"end": {
"line": 31,
"character": 162
"line": 112,
"character": 117
}
},
"description": "Create and overwrite the `_policySetDefinitionsBicepInput.txt` file in the specified directory with a new empty file with `utf8` encoding"
"description": "Count the number of policy set definitions in the `lib/policy_set_definitions` directory and output to the console the total number"
},
{
"file": ".github/scripts/Invoke-PolicyToBicep.ps1",
"selection": {
"start": {
"line": 35,
"line": 30,
"character": 1
},
"end": {
"line": 108,
"character": 2
"line": 31,
"character": 162
}
},
"description": "For every `.json` file in the `lib/policy_set_definitions` directory extract the policy set definitions (initiative) name and the file path and then write them (append) into the `_policySetDefinitionsBicepInput.txt` file in a Bicep formatted output (see end of line 93, 101 and 106).\r\n\r\nIt also creates a parameters file (not an ARM complaint one, just a JSON compliant document). And it also loops through all the child policy definitions of each policy set definition (initiative) and extracts the definition reference ID and the definition ID and adds them to the output in the `_policySetDefinitionsBicepInput.txt` file"
"description": "Create and overwrite the `_policySetDefinitionsBicepInput.txt` file in the specified directory with a new empty file with `utf8` encoding",
"line": 69
},
{
"file": ".github/scripts/Invoke-PolicyToBicep.ps1",
"selection": {
"start": {
"line": 110,
"character": 1
},
"end": {
"line": 112,
"character": 117
}
},
"description": "Count the number of policy set definitions in the `lib/policy_set_definitions` directory and output to the console the total number"
"description": "For every `.json` file in the `lib/policy_set_definitions` directory extract the policy set definitions (initiative) name and the file path and then write them (append) into the `_policySetDefinitionsBicepInput.txt` file in a Bicep formatted output (see end of line 145, 168 and 172).\r\n\r\nIt also creates a parameters file (not an ARM complaint one, just a JSON compliant document). And it also loops through all the child policy definitions of each policy set definition (initiative) and extracts the definition reference ID and the definition ID and adds them to the output in the `_policySetDefinitionsBicepInput.txt` file",
"line": 64
},
{
"file": ".github/scripts/Invoke-PolicyToBicep.ps1",
Expand All @@ -293,7 +288,8 @@
"character": 155
}
},
"description": "Create and overwrite the `_policyAssignmentsBicepInput.txt` file in the specified directory with a new empty file with `utf8` encoding"
"description": "Create and overwrite the `_policyAssignmentsBicepInput.txt` file in the specified directory with a new empty file with `utf8` encoding",
"line": 200
},
{
"file": ".github/scripts/Invoke-PolicyToBicep.ps1",
Expand All @@ -307,7 +303,8 @@
"character": 2
}
},
"description": "For every `.json` file in the `lib/policy_assignments` directory extract the policy assignment's name and the file path and then write them (append) into the `_policyAssignmentsBicepInput.txt` file in a Bicep formatted output (see end of line 131)."
"description": "For every `.json` file in the `lib/policy_assignments` directory extract the policy assignment's name and the file path and then write them (append) into the `_policyAssignmentsBicepInput.txt` file in a Bicep formatted output (see end of line 131).",
"line": 203
},
{
"file": ".github/scripts/Invoke-PolicyToBicep.ps1",
Expand All @@ -321,7 +318,8 @@
"character": 109
}
},
"description": "Count the number of policy assignments in the `lib/policy_assignments` directory and output to the console the total number"
"description": "Count the number of policy assignments in the `lib/policy_assignments` directory and output to the console the total number",
"line": 218
},
{
"file": ".github/workflows/update-policy.yml",
Expand Down
8 changes: 5 additions & 3 deletions docs/wiki/AddingPolicyDefs.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ We recommend were possible to use option 1 and extend the current `ALZ-Bicep` ap

## How do I extend the `ALZ-Bicep` Custom Policy Definitions module?

> ✋ Where possible avoid using `-`'s (hyphens/dashes) as these are an unsupported character in Bicep. camelCase or use `_` instead 👍

To extend the [Custom Policy Definitions module](https://github.com/Azure/ALZ-Bicep/tree/main/infra-as-code/bicep/modules/policy/definitions) from `ALZ-Bicep` follow the below process.

1. Navigate to the relevant `lib` directory
Expand All @@ -38,7 +40,7 @@ To extend the [Custom Policy Definitions module](https://github.com/Azure/ALZ-Bi
4. Run the [`Invoke-PolicyToBicep.ps1`](https://github.com/Azure/ALZ-Bicep/blob/main/.github/scripts/Invoke-PolicyToBicep.ps1) script to update the `_policyDefinitionsBicepInput.txt` and/or `_policySetDefinitionsBicepInput.txt` files in the `lib` folders
1. Copy the entire contents of the relevant `.txt` file and replace the contents of the associated variable in the [Custom Policy Definitions module](https://github.com/Azure/ALZ-Bicep/tree/main/infra-as-code/bicep/modules/policy/definitions)
- Policy Definition = `_policyDefinitionsBicepInput.txt` placed into variable named `varCustomPolicyDefinitionsArray` (place copied contents inside of array `[]`)
- Policy Initiative (Set) = `_policySetDefinitionsBicepInput.txt` placed into variable named `varCustomPolicySetDefinitionsArray` (place copied contents inside of array `[]`)
- Policy Initiative (Set) & Parameter Variables = Copy the entire contents of `_policySetDefinitionsBicepInput.txt` and replace variable named `varCustomPolicySetDefinitionsArray` and parameter variables below it with copied contents
5. Redeploy the updated [Custom Policy Definitions module](https://github.com/Azure/ALZ-Bicep/tree/main/infra-as-code/bicep/modules/policy/definitions) via your configured method (locally via Azure CLI or PowerShell or via Azure DevOps pipeline or GitHub action)
6. New Policy Definitions now deployed to intermediate root Management Group (e.g. `Contoso`)

Expand All @@ -48,9 +50,9 @@ To extend the [Custom Policy Definitions module](https://github.com/Azure/ALZ-Bi

As Bicep is ultimately just compiling ARM templates behind the scenes, deployments of Bicep files/modules are still subject to the same limits as ARM Templates. The main limit to be aware of here is the `4 MB` total size limit for a single ARM Template.

Today the [Custom Policy Definitions module](https://github.com/Azure/ALZ-Bicep/tree/main/infra-as-code/bicep/modules/policy/definitions) from `ALZ-Bicep` results in a `2.56 MB` ARM Template file `JSON` file being created.
Today the [Custom Policy Definitions module](https://github.com/Azure/ALZ-Bicep/tree/main/infra-as-code/bicep/modules/policy/definitions) from `ALZ-Bicep` results in a `874 KB` ARM Template file `JSON` file being created.

This has plenty of room for expansion but it is worth keeping in mind as you may hit the 4MB limit and see the errors of `JobSizeExceededException` or `DeploymentJobSizeExceededException`.
This has plenty of room for expansion but it is worth keeping in mind as you may hit the `4 MB` limit and see the errors of `JobSizeExceededException` or `DeploymentJobSizeExceededException`.

### The fix

Expand Down
Loading