Skip to content

Commit cb72e20

Browse files
Added further utilities readme files to Wiki (#840)
* Update to latest * Update to latest * Update to latest * Update to latest * Update to latest * Update to latest
1 parent 550e0fa commit cb72e20

15 files changed

Lines changed: 280 additions & 65 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ This repository includes a collection of advanced and curated Modules consisting
115115

116116
| Name | Status | Docs |
117117
| - | - | - |
118-
| [ConvertTo-ARMTemplate](https://github.com/Azure/ResourceModules/blob/main/utilities/tools/ConvertTo-ARMTemplate.ps1) | [![.Platform: Test - ConvertTo-ARMTemplate.ps1](https://github.com/Azure/ResourceModules/actions/workflows/platform.convertToArmTemplate.tests.yml/badge.svg?branch=main)](https://github.com/Azure/ResourceModules/actions/workflows/platform.convertToArmTemplate.tests.yml) | [link](https://github.com/Azure/ResourceModules/wiki/UtilitiesConversionScript) |
118+
| [ConvertTo-ARMTemplate](https://github.com/Azure/ResourceModules/blob/main/utilities/tools/ConvertTo-ARMTemplate.ps1) | [![.Platform: Test - ConvertTo-ARMTemplate.ps1](https://github.com/Azure/ResourceModules/actions/workflows/platform.convertToArmTemplate.tests.yml/badge.svg?branch=main)](https://github.com/Azure/ResourceModules/actions/workflows/platform.convertToArmTemplate.tests.yml) | [link](https://github.com/Azure/ResourceModules/wiki/UtilitiesConvertToARMTemplate) |
119119

120120
## Contributing
121121

docs/wiki/Home.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ If you're unfamiliar with Infrastructure as Code, or wonder how you can use the
2121
- [Design](./TestingDesign)
2222
- [Usage](./TestingUsage)
2323
- [Utilities](./Utilities)
24-
- [Bicep to ARM conversion script](./UtilitiesConversionScript)
24+
- [Bicep to ARM conversion script](./UtilitiesConvertToARMTemplate)
25+
- [Register Azure DevOps pipelines script](./UtilitiesRegisterAzureDevOpsPipeline)
26+
- [Set Module ReadMe script](./UtilitiesSetModuleReadMe)
27+
- [Get formatted RBAC roles script](./UtilitiesGetFormattedRBACRoleList)
2528
- [Pipelines](./Pipelines)
2629
- [Design](./PipelinesDesign)
2730
- [Parameter File Tokens](./ParameterFileTokens)

docs/wiki/ModulesDesign.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Microsoft.Sql
7676
└─ databases [child-module/resource]
7777
```
7878

79-
In this folder we recommend to place the child-resource-template alongside a ReadMe (that can be generated via the `.github\workflows\scripts\Set-ModuleReadMe.ps1` script) and optionally further nest additional folders for it's child-resources.
79+
In this folder we recommend to place the child-resource-template alongside a ReadMe (that can be generated via the [Set-ModuleReadMe](./UtilitiesSetModuleReadMe) script) and optionally further nest additional folders for it's child-resources.
8080

8181
The parent template should reference all it's direct child-templates to allow for an end-to-end deployment experience while allowing any user to also reference 'just' the child-resource itself. In the case of the SQL-server example the server template would reference the database module and encapsulate it it in a loop to allow for the deployment of n-amount of databases. For example
8282

@@ -180,7 +180,7 @@ module <mainResource>_rbac '.bicep/nested_rbac.bicep' = [for (roleAssignment, in
180180
Here you specify the platform roles available for the main resource.
181181

182182
The `builtInRoleNames` variable contains the list of applicable roles for the specific resource to which the nested_rbac.bicep module applies.
183-
>**Note**: You can find a helper script `Get-FormattedRBACRoles.ps1` in the `utilities\tools` folder of the repository. You can use this script to extract a formatted list of RBAC roles used in the CARML modules based on the RBAC lists in Azure.
183+
>**Note**: You use the helper script [Get-FormattedRBACRoles.ps1](./UtilitiesGetFormattedRBACRoleList) to extract a formatted list of RBAC roles used in the CARML modules based on the RBAC lists in Azure.
184184
185185
The element requires you to provide both the `principalIds` & `roleDefinitionOrIdName` to assign to the principal IDs. Also, the `resourceId` is target resource's resource ID that allows us to reference it as an `existing` resource. Note, the implementation of the `split` in the resource reference becomes longer the deeper you go in the child-resource hierarchy.
186186

@@ -194,7 +194,6 @@ var builtInRoleNames = {
194194
'Contributor': subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'b24988ac-6180-42a0-ab88-20f7382dd24c')
195195
'Reader': subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'acdd72a7-3385-48ef-bd42-f606fba81ae7')
196196
// <optionalAdditionalRoles>
197-
// You can find a helper script `Get-FormattedRBACRoles.ps1` in the `tools` folder of the repository to fetch the roles.
198197
199198
}
200199
@@ -524,7 +523,7 @@ Its primary components are in order:
524523
- A **Template references** section listing relevant resources [ARM template reference](https://docs.microsoft.com/en-us/azure/templates).
525524
526525
Note the following recommendations
527-
- Use our module generation script `Set-ModuleReadMe` that will do most of the work for you. Currently you can find it at 'utilities\tools\Set-ModuleReadMe.ps1'. Just load the file and invoke the function like this `Set-ModuleReadMe -TemplateFilePath '<pathToModule>/deploy.bicep'`
526+
- Use our module ReadMe generation script [Set-ModuleReadMe](./UtilitiesSetModuleReadMe) that will do most of the work for you.
528527
- It is not recommended to describe how to use child resources in the parent readme file (for example 'How to define a [container] entry for the [storage account]'). Instead it is recommended to reference the child resource's ReadMe instead (for example 'container/readme.md').
529528
530529
# Parameter files

docs/wiki/Utilities.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ This section and its sub-sections describe tools and utilities provided in this
66

77
### _Navigation_
88

9-
- [Bicep to ARM conversion script](./UtilitiesConversionScript)
9+
- [Bicep to ARM conversion script](./UtilitiesConvertToARMTemplate)
10+
- [Register Azure DevOps pipelines script](./UtilitiesRegisterAzureDevOpsPipeline)
11+
- [Set Module ReadMe script](./UtilitiesSetModuleReadMe)
12+
- [Get formatted RBAC roles script](./UtilitiesGetFormattedRBACRoleList)
1013

1114
---

docs/wiki/UtilitiesConversionScript.md

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Bicep to ARM conversion script
2+
3+
At the time of writing bicep is still in a beta phase. For this reason, some people may want to wait for bicep's _General Availability_ and prefer to use ARM Templates for the time being.
4+
For these scenarios, the CARML library provides a script that uses the Bicep Toolkit translator/compiler to support the conversion of CARML Bicep modules to ARM templates.
5+
This page documents the conversion utility and how to use it.
6+
7+
---
8+
9+
### _Navigation_
10+
11+
- [Location](#location)
12+
- [How it works](#what-it-does)
13+
- [How to use it](#how-to-use-it)
14+
- [Examples](#examples)
15+
16+
---
17+
# Location
18+
19+
You can find the script under `/utilities/tools/ConvertTo-ARMTemplate.ps1`
20+
21+
# How it works
22+
23+
The script finds all 'deploy.bicep' files and tries to convert them to json-based ARM templates
24+
by using the following steps.
25+
1. Remove existing deploy.json files
26+
1. Convert bicep files to json
27+
1. Remove bicep metadata from json
28+
1. Remove bicep files and folders
29+
1. Update pipeline files - Replace .bicep with .json in pipeline files
30+
31+
# How to use it
32+
33+
For details on how to use the function please refer to the script's local documentation.
34+
> **Note:** The script must be loaded before the function can be invoked
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Get formatted RBAC roles Script
2+
3+
Use this script to format a given raw 'Roles' table from Azure to the format required by either bicep or ARM in any RBAC deployment.
4+
5+
---
6+
7+
### _Navigation_
8+
9+
- [Location](#location)
10+
- [How it works](#what-it-does)
11+
- [How to use it](#how-to-use-it)
12+
- [Examples](#examples)
13+
14+
---
15+
# Location
16+
17+
You can find the script under `/utilities/tools/Get-FormattedRBACRoles.ps1`
18+
19+
# How it works
20+
21+
1. From the provided raw and plain roles list, create a list of only the contained role names
22+
1. Fetch all available roles from Azure
23+
1. Go through all provided role names, match them with those from Azure to get the matching RoleDefinitionId and format a string like `'<roleName>': subscriptionResourceId('Microsoft.Authorization/roleDefinitions','<roleDefinitionId>')` for each match
24+
1. Print the result to the terminal
25+
26+
# How to use it
27+
28+
The script does not accept any custom parameter per se, but expects you to replace the placeholder in the `rawRoles` variable inside the script
29+
30+
```PowerShell
31+
$rawRoles = @'
32+
<paste the table here>
33+
'@
34+
```
35+
36+
To get the list of roles in the expected format:
37+
1. Navigate to Azure
38+
1. Deploy one instance of the service you want to fetch the roles for
39+
1. Navigate to the `Access Control (IAM)` blade in the resource
40+
1. Open the `Roles` tab
41+
1. Set the `Type` in the dropdown to `BuiltInRole`
42+
43+
<img src="media/rbacRoles.png" alt="Complete deployment flow filtered" height="300">
44+
45+
1. Select and copy the entire table as is to the PowerShell variable.
46+
47+
The result should look similar to
48+
49+
```PowerShell
50+
$rawRoles = @'
51+
Owner
52+
Grants full access to manage all resources, including the ability to assign roles in Azure RBAC.
53+
builtInRole
54+
General
55+
View
56+
Contributor
57+
Grants full access to manage all resources, but does not allow you to assign roles in Azure RBAC, manage assignments in Azure Blueprints, or share image galleries.
58+
BuiltInRole
59+
General
60+
View
61+
Reader
62+
View all resources, but does not allow you to make any changes.
63+
BuiltInRole
64+
General
65+
View
66+
'@
67+
```
68+
1. Execute the script. The output for the above example would be
69+
70+
```yml
71+
VERBOSE: Bicep
72+
VERBOSE: -----
73+
'Owner': subscriptionResourceId('Microsoft.Authorization/roleDefinitions','8e3af657-a8ff-443c-a75c-2fe8c4bcb635')
74+
'Contributor': subscriptionResourceId('Microsoft.Authorization/roleDefinitions','b24988ac-6180-42a0-ab88-20f7382dd24c')
75+
'Reader': subscriptionResourceId('Microsoft.Authorization/roleDefinitions','acdd72a7-3385-48ef-bd42-f606fba81ae7')
76+
VERBOSE:
77+
VERBOSE: ARM
78+
VERBOSE: ---
79+
"Owner": "[subscriptionResourceId('Microsoft.Authorization/roleDefinitions','8e3af657-a8ff-443c-a75c-2fe8c4bcb635')]",
80+
"Contributor": "[subscriptionResourceId('Microsoft.Authorization/roleDefinitions','b24988ac-6180-42a0-ab88-20f7382dd24c')]",
81+
"Reader": "[subscriptionResourceId('Microsoft.Authorization/roleDefinitions','acdd72a7-3385-48ef-bd42-f606fba81ae7')]",
82+
```
83+
1. Copy the output into the RBAC file into the `buildInRoleNames` variable. Again, for the same example using bicep this would be:
84+
85+
```bicep
86+
var builtInRoleNames = {
87+
'Owner': subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '8e3af657-a8ff-443c-a75c-2fe8c4bcb635')
88+
'Contributor': subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'b24988ac-6180-42a0-ab88-20f7382dd24c')
89+
'Reader': subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'acdd72a7-3385-48ef-bd42-f606fba81ae7')
90+
}
91+
```
92+
93+
For further details on how to use the function please refer to the script's local documentation.
94+
> **Note:** The script must be loaded before the function can be invoked
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Register Azure DevOps Pipelines
2+
3+
Use this script to automatically register all specified Azure DevOps pipelines in a target Azure DevOps project. This is especially useful to register the initial module pipelines as there is one for each module in the repository.
4+
5+
---
6+
7+
### _Navigation_
8+
9+
- [Location](#location)
10+
- [How it works](#what-it-does)
11+
- [How to use it](#how-to-use-it)
12+
- [Examples](#examples)
13+
14+
---
15+
# Location
16+
17+
You can find the script under `/utilities/tools/Register-AzureDevOpsPipeline.ps1`
18+
19+
# How it works
20+
21+
1. Get all pipelines in a given target folder (for example `.azuredevops/modulePipelines`)
22+
1. Fetch all currently registered pipelines in the target Azure DevOps project
23+
1. Compare the local defined and remote-registered pipelines to detect which need to be created and which skipped
24+
1. Create all pipelines that are missing
25+
1. Optionally register the pipelines also for build validation (i.e. they registered to be required for Pull Requests)
26+
27+
# How to use it
28+
29+
> **Note:** You'll need the 'azure-devops' extension to run this function: `az extension add --upgrade -n azure-devops`
30+
31+
The steps you'd want to follow are
32+
1. (if pipelines are in GitHub) Create a service connection to the target GitHub repository using e.g. oAuth
33+
1. Create a PAT token for the Azure DevOps environment in which you want to register the pipelines in
34+
1. Run this script with the corresponding input parameters
35+
1. Create any required element required to execute the pipelines. For example:
36+
- Library group(s) used in the pipeline(s)
37+
- Service connection(s) used in the pipeline(s)
38+
- Agent pool(s) used in the pipeline(s) if not using the default available agents
39+
40+
For further details on how to use the function please refer to the script's local documentation.
41+
> **Note:** The script must be loaded before the function can be invoked
42+
43+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Module ReadMe Generation Script
2+
3+
Use this script to generate most parts of a templates ReadMe file. It will take care of all aspects but the description & module-specific parameter usage examples. However, the latter are added for default cases such as `tags` or `roleAssignments` if the corresponding parameter exists in the provided template.
4+
5+
For further information about the parameter usage blocks, please refer to the [section](#special-case-parameter-usage-section) below.
6+
7+
---
8+
9+
### _Navigation_
10+
11+
- [Location](#location)
12+
- [How it works](#what-it-does)
13+
- [Special case: 'Parameter Usage' section](#special-case-parameter-usage-section)
14+
- [How to use it](#how-to-use-it)
15+
- [Examples](#examples)
16+
17+
---
18+
# Location
19+
20+
You can find the script under `/utilities/tools/Set-ModuleReadMe.ps1`
21+
22+
# How it works
23+
24+
1. Using the provided template path, the script first makes sure to convert it to ARM if necessary (i.e. if a path to a bicep file was provided)
25+
1. If the intended readMe file does not yet exist in the expected path, it is generated with a skeleton (with e.g. a generated header name, etc.)
26+
1. It then goes through all sections defined as `SectionsToRefresh` (by default all) and refreshes the section content (for example for the `Parameters`) based on the values in the ARM template. It detects sections by their header and regenerates always the full section.
27+
1. Once all are refreshed, the current ReadMe file is overwritten. **Note:** The script can be invoked with a `WhatIf` in combination with `Verbose` to just receive an console-output of the updated content.
28+
29+
## Special case: 'Parameter Usage' section
30+
31+
The 'Parameter Usage' examples are located just beneath the 'Parameters' table. They are intended to show how to use complex objects/arrays that can be provided as parameters (excluding child-resources as they have their own readMe).
32+
33+
For the most part, this section is to be populated manually. However, for a specific set of common parameters, we automatically add their example to the readMe if the parameter exists in the template. At the time of this writing these are:
34+
- Private Endpoints
35+
- Role Assignments
36+
- Tags
37+
- User Assigned Identities
38+
39+
To be able to change this list with minimum effort, the script reads the content from markdown files in the folder: `utilities/tools/moduleReadMeSource` and matches their title against the parameters of the template file. If a match is found, it's content is added to the readme alongside the generated header. This means, if you want to add another case, you just need to add a new file to the `moduleReadMeSource` folder and follow the naming pattern `resourceUsage-<parameteRName>.md`.
40+
41+
For example, the content of file `resourceUsage-roleAssignments.md` in folder `moduleReadMeSource` is added to a template's readMe if it contains a parameter `roleAssignments`. The combined result is:
42+
43+
```markdown
44+
### Parameter Usage: `roleAssignments`
45+
46+
<[resourceUsage-roleAssignments.md] file content>
47+
```
48+
49+
# How to use it
50+
51+
For details on how to use the function please refer to the script's local documentation.
52+
> **Note:** The script must be loaded before the function can be invoked

docs/wiki/media/rbacRoles.png

104 KB
Loading

0 commit comments

Comments
 (0)