Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
2603b82
add initial test and docu
rahalan Dec 16, 2021
ab90d2a
Merge remote-tracking branch 'origin/main' into users/rahalan/TestCon…
rahalan Dec 16, 2021
50ae948
Merge remote-tracking branch 'origin/main' into users/rahalan/TestCon…
rahalan Dec 16, 2021
cabea2e
minor changes
rahalan Dec 16, 2021
74f0bf0
fix path
rahalan Dec 16, 2021
3d87556
fix regex
rahalan Dec 16, 2021
8f47df4
update tests
rahalan Dec 16, 2021
18ecda1
update paths
rahalan Dec 16, 2021
c030ece
update paths
rahalan Dec 16, 2021
cfd8e06
update paths
rahalan Dec 16, 2021
01a8eea
fix path
rahalan Dec 16, 2021
db4fa77
update
rahalan Dec 16, 2021
4c13354
cleanup
rahalan Dec 16, 2021
47f3266
add test
rahalan Dec 16, 2021
f70e122
run script
rahalan Dec 16, 2021
4c77b27
cleanup
rahalan Dec 16, 2021
32dce73
update wiki
rahalan Dec 17, 2021
f3adc03
fix path, add metadata test
rahalan Dec 20, 2021
56b99b9
rename file
rahalan Dec 20, 2021
5aa387a
add test pipeline
rahalan Dec 20, 2021
005dfc0
fix trigger
rahalan Dec 20, 2021
5c204c9
test
rahalan Dec 20, 2021
2a5ccd1
update file name
rahalan Dec 20, 2021
8e75f22
update name
rahalan Dec 20, 2021
e76f6f1
test
rahalan Dec 20, 2021
fc1ef68
test
rahalan Dec 20, 2021
7ebfcc5
test
rahalan Dec 20, 2021
59677f0
test
rahalan Dec 20, 2021
b4f2a15
test
rahalan Dec 20, 2021
6d1ca47
test
rahalan Dec 20, 2021
341fa35
test
rahalan Dec 20, 2021
f32b43c
test
rahalan Dec 20, 2021
f6278b9
update
rahalan Dec 20, 2021
61e6222
test
rahalan Dec 20, 2021
2a680e1
test
rahalan Dec 20, 2021
d31964f
test
rahalan Dec 20, 2021
a38bd46
test
rahalan Dec 20, 2021
636319b
test
rahalan Dec 20, 2021
4045ad9
test
rahalan Dec 20, 2021
64454ab
test
rahalan Dec 20, 2021
92fb37d
serial
rahalan Dec 20, 2021
c9e87b5
test
rahalan Dec 20, 2021
f190797
update
rahalan Dec 20, 2021
263e286
fix path
rahalan Dec 20, 2021
3f2dbb8
add new tests
rahalan Dec 21, 2021
cdc7808
add more tests
rahalan Dec 21, 2021
3bd9b72
fix tests
rahalan Dec 21, 2021
caa7921
fix
rahalan Dec 21, 2021
c3845f5
remove trigger
rahalan Dec 21, 2021
2497e05
Update docs/wiki/ConversionScript.md
rahalan Dec 21, 2021
c66bde5
test
rahalan Dec 21, 2021
62a01a6
Merge branch 'users/rahalan/TestConversionScript' of https://github.c…
rahalan Dec 21, 2021
905a557
update WIKI
rahalan Dec 21, 2021
6b88823
trigger pipeline
rahalan Dec 21, 2021
50d3d57
finalize
rahalan Dec 21, 2021
a3c6b99
Update docs/wiki/ConversionScript.md
rahalan Dec 21, 2021
a9597cd
Update docs/wiki/ConversionScript.md
rahalan Dec 21, 2021
29430a7
updates
rahalan Dec 21, 2021
f27ce41
Merge branch 'users/rahalan/TestConversionScript' of https://github.c…
rahalan Dec 21, 2021
205caac
fix paths
rahalan Dec 21, 2021
1bb4735
Update .github/workflows/platform.convertToArmTemplate.tests.yml
rahalan Dec 21, 2021
b352ff6
Update docs/wiki/ConversionScript.md
rahalan Dec 21, 2021
6efd40a
Update docs/wiki/ConversionScript.md
rahalan Dec 21, 2021
4f86b05
Update docs/wiki/ConversionScript.md
rahalan Dec 21, 2021
fb625bd
Update docs/wiki/ConversionScript.md
rahalan Dec 21, 2021
c40356d
Update docs/wiki/ConversionScript.md
rahalan Dec 21, 2021
eb1f159
Simplified pipeline, simplified tests, extended Logic to ADO, fixed c…
AlexanderSehr Dec 22, 2021
f49887c
update wiki
rahalan Dec 22, 2021
4d6f470
update wiki
rahalan Dec 22, 2021
24a23a4
Update docs/wiki/UtilitiesConversionScript.md
rahalan Dec 22, 2021
2b79f17
Update docs/wiki/UtilitiesConversionScript.md
rahalan Dec 22, 2021
58966f1
wiki update
rahalan Dec 22, 2021
1c8bbe8
Merge branch 'users/rahalan/TestConversionScript' of https://github.c…
rahalan Dec 22, 2021
ffba882
update wiki
rahalan Dec 22, 2021
4bbc7b5
Update docs/wiki/UtilitiesConversionScript.md
rahalan Dec 22, 2021
d4e4423
Update docs/wiki/UtilitiesConversionScript.md
rahalan Dec 22, 2021
55a151b
Update docs/wiki/UtilitiesConversionScript.md
rahalan Dec 22, 2021
4f363d2
Update docs/wiki/UtilitiesConversionScript.md
rahalan Dec 22, 2021
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
50 changes: 50 additions & 0 deletions .github/workflows/platform.convertToArmTemplate.tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: '.Platform: Test - ConvertTo-ARMTemplate.ps1'

on:
push:
branches:
- main
paths:
- 'utilities/tools/ConvertTo-ARMTemplate.ps1'
- 'utilities/tools/tests/ConvertTo-ARMTemplate**'

jobs:
job_test_convert:
runs-on: ubuntu-latest
name: 'Test with parameter'
strategy:
fail-fast: false
matrix:
tags: ['Default', 'ConvertChildren', 'Skip']
steps:
- name: 'Checkout'
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: 'Run Pester tests'
shell: pwsh
run: |
Invoke-Pester -Configuration @{
Run = @{
Path = @(
Join-Path "$env:GITHUB_WORKSPACE" 'utilities' 'tools' 'tests' 'ConvertTo-ARMTemplate.Tests.ps1'
)
}
Filter = @{
Tag = '${{ matrix.tags }}'
}
TestResult = @{
TestSuiteName = 'Conversion Tests'
OutputPath = Join-Path "$env:GITHUB_WORKSPACE" 'utilities' 'tools' 'tests' 'conversion-testResults-${{ matrix.tags }}.xml'
OutputFormat = 'JUnitXml'
Enabled = $true
}
Output = @{
Verbosity = 'Detailed'
}
}
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
if: always()
with:
files: 'utilities/tools/tests/conversion-testResults-${{ matrix.tags }}.xml'
2 changes: 2 additions & 0 deletions docs/wiki/Home.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ If you're unfamiliar with Infrastructure as Code, or wonder how you can use the
- [Testing](./Testing)
- [Design](./TestingDesign)
- [Usage](./TestingUsage)
- [Utilities](./Utilities.md)
- [Bicep to ARM conversion script](./UtilitiesConversionScript.md)
- [Pipelines](./Pipelines)
- [Design](./PipelinesDesign)
- [Usage](./PipelinesUsage)
Expand Down
11 changes: 11 additions & 0 deletions docs/wiki/Utilities.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Utilities

This section and its sub-sections describe tools and utilities provided in this repository.

---

### _Navigation_

- [Bicep to ARM conversion script](./UtilitiesConversionScript.md)

---
52 changes: 52 additions & 0 deletions docs/wiki/UtilitiesConversionScript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Bicep to ARM conversion script

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.
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.
This page documents the conversion utility and how to use it.

---

### _Navigation_

- [Location](#location)
- [What it does](#what-it-does)
- [How to use it](#how-to-use-it)
- [Examples](#examples)

---
# Location

`You can find the script under /utilities/tools/ConvertTo-ARMTemplate.ps1`

# What it does

The script finds all 'deploy.bicep' files and tries to convert them to json-based ARM templates
by using the following steps.
1. Remove existing deploy.json files
1. Convert bicep files to json
1. Remove bicep metadata from json
1. Remove bicep files and folders
1. Update pipeline files - Replace .bicep with .json in pipeline files
# How to use it

The script can be called with the following parameters:

| name | description |
|-|-|
| -Path | The path to the root of the repo. |
| -ConvertChildren | Convert child resource modules to bicep. |
| -SkipMetadataCleanup | Skip Cleanup of bicep metadata from json files |
| -SkipBicepCleanUp | Skip removal of bicep files and folders |
| -SkipPipelineUpdate | Skip replacing .bicep with .json in pipeline files |

## Examples

Converts top level bicep modules to json based ARM template, cleaning up all bicep files and folders and updating the workflow files to use the json files.
```powershell
. .\utilities\tools\ConvertTo-ARMTemplate.ps1
```

Only converts top level bicep modules to json based ARM template, keeping metadata in json, keeping all bicep files and folders, and not updating workflows.
```powershell
. .\utilities\tools\ConvertTo-ARMTemplate.ps1 -ConvertChildren -SkipMetadataCleanup -SkipBicepCleanUp -SkipWorkflowUpdate
```
1 change: 1 addition & 0 deletions docs/wiki/_Sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- [Testing](./Testing)
- [Design](./TestingDesign)
- [Usage](./TestingUsage)
- [Utilities](./Utilities.md)
- [Pipelines](./Pipelines)
- [Design](./PipelinesDesign)
- [Parameter File Tokens](./ParameterFileTokens)
Expand Down
56 changes: 38 additions & 18 deletions utilities/tools/ConvertTo-ARMTemplate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ Optional. Skip Cleanup of Bicep metadata from json files
.PARAMETER SkipBicepCleanUp
Optional. Skip removal of bicep files and folders

.PARAMETER SkipWorkflowUpdate
.PARAMETER SkipPipelineUpdate
Optional. Skip replacing .bicep with .json in workflow files

.EXAMPLE
. .\utilities\tools\ConvertTo-ARMTemplate.ps1

Converts top level bicep modules to json based ARM template, cleaning up all bicep files and folders and updating the workflow files to use the json files.
Converts top level bicep modules to json-based ARM template, cleaning up all bicep files and folders and updating the workflow files to use the json files.

.EXAMPLE
. .\utilities\tools\ConvertTo-ARMTemplate.ps1 -ConvertChildren -SkipMetadataCleanup -SkipBicepCleanUp -SkipWorkflowUpdate
. .\utilities\tools\ConvertTo-ARMTemplate.ps1 -ConvertChildren -SkipMetadataCleanup -SkipBicepCleanUp -SkipPipelineUpdate

Only converts top level bicep modules to json based ARM template, keeping metadata in json, keeping all bicep files and folders, and not updating workflows.

Expand All @@ -52,7 +52,7 @@ param (
[switch] $SkipBicepCleanUp,

[Parameter(Mandatory = $false)]
[switch] $SkipWorkflowUpdate
[switch] $SkipPipelineUpdate
)

$rootPath = Get-Item -Path $Path | Select-Object -ExpandProperty 'FullName'
Expand Down Expand Up @@ -80,8 +80,10 @@ Write-Verbose 'Convert bicep files to json'

Write-Verbose "Convert bicep files to json - Processing [$($BicepFilesToConvert.count)] file(s)"
if ($PSCmdlet.ShouldProcess("[$($BicepFilesToConvert.count)] deploy.bicep file(s) in path [$armFolderPath]", 'az bicep build')) {
$BicepFilesToConvert | ForEach-Object -ThrottleLimit $env:NUMBER_OF_PROCESSORS -Parallel {
Invoke-Expression -Command "az bicep build --file '$_'"
# parallelism is not supported on GitHub runners
#$BicepFilesToConvert | ForEach-Object -ThrottleLimit $env:NUMBER_OF_PROCESSORS -Parallel {
$BicepFilesToConvert | ForEach-Object {
az bicep build --file $_
}
}

Expand All @@ -94,8 +96,9 @@ if (-not $SkipMetadataCleanup) {

Write-Verbose "Remove Bicep metadata from json - Processing [$($BicepFilesToConvert.count)] file(s)"
if ($PSCmdlet.ShouldProcess("[$($BicepFilesToConvert.count)] deploy.bicep file(s) in path [$armFolderPath]", 'Set-Content')) {
$BicepFilesToConvert | ForEach-Object -ThrottleLimit $env:NUMBER_OF_PROCESSORS -Parallel {

# parallelism is not supported on GitHub runners
#$BicepFilesToConvert | ForEach-Object -ThrottleLimit $env:NUMBER_OF_PROCESSORS -Parallel {
$BicepFilesToConvert | ForEach-Object {
function Remove-JSONMetadata {
<#
.SYNOPSIS
Expand Down Expand Up @@ -164,21 +167,38 @@ if (-not $SkipBicepCleanUp) {
}
#endregion

#region Update workflow files - Replace .bicep with .json in workflow files
if (-not $SkipWorkflowUpdate) {
Write-Verbose 'Update workflow files'
#region Update pipeline files - Replace .bicep with .json in workflow files
if (-not $SkipPipelineUpdate) {
Write-Verbose 'Update pipeline files'

# GitHub workflow files
$ghWorkflowFolderPath = Join-Path -Path $rootPath -ChildPath '.github\workflows'
$ghWorkflowFilesToUpdate = Get-ChildItem -Path $ghWorkflowFolderPath -Filter 'ms.*.yml' -File -Force
Write-Verbose ('Update workflow files - Processing [{0}] file(s)' -f $ghWorkflowFilesToUpdate.count)
if ($PSCmdlet.ShouldProcess(('[{0}] ms.*.yml file(s) in path [{1}]' -f $ghWorkflowFilesToUpdate.Count, $ghWorkflowFolderPath), 'Set-Content')) {
# parallelism is not supported on GitHub runners
#$ghWorkflowFilesToUpdate | ForEach-Object -ThrottleLimit $env:NUMBER_OF_PROCESSORS -Parallel {
$ghWorkflowFilesToUpdate | ForEach-Object {
$content = $_ | Get-Content
$content = $content -replace 'templateFilePath:(.*).bicep', 'templateFilePath:$1.json'
$_ | Set-Content -Value $content
}
}

$workflowFolderPath = Join-Path -Path $rootPath -ChildPath '.github\workflows'
$workflowFilesToUpdate = Get-ChildItem -Path $workflowFolderPath -Filter 'ms.*.yml' -File -Force
Write-Verbose "Update workflow files - Processing [$($workflowFilesToUpdate.count)] file(s)"
if ($PSCmdlet.ShouldProcess("[$($workflowFilesToUpdate.count)] ms.*.yml file(s) in path [$armFolderPath]", 'Set-Content')) {
$workflowFilesToUpdate | ForEach-Object -ThrottleLimit $env:NUMBER_OF_PROCESSORS -Parallel {
# Azure DevOps Pipelines
$adoPipelineFolderPath = Join-Path -Path $rootPath -ChildPath '.azuredevops\modulePipelines'
$adoPipelineFilesToUpdate = Get-ChildItem -Path $adoPipelineFolderPath -Filter 'ms.*.yml' -File -Force
Write-Verbose ('Update Azure DevOps pipeline files - Processing [{0}] file(s)' -f $adoPipelineFilesToUpdate.count)
if ($PSCmdlet.ShouldProcess(('[{0}] ms.*.yml file(s) in path [{1}]' -f $adoPipelineFilesToUpdate.Count, $adoPipelineFolderPath), 'Set-Content')) {
# parallelism is not supported on GitHub runners
#$adoPipelineFilesToUpdate | ForEach-Object -ThrottleLimit $env:NUMBER_OF_PROCESSORS -Parallel {
$adoPipelineFilesToUpdate | ForEach-Object {
$content = $_ | Get-Content
$content = $content.Replace('deploy.bicep', 'deploy.json')
$content = $content -replace 'templateFilePath:(.*).bicep', 'templateFilePath:$1.json'
$_ | Set-Content -Value $content
}
}

Write-Verbose 'Update workflow files - Done'
Write-Verbose 'Update pipeline files - Done'
}
#endregion
Loading