|
| 1 | +--- |
| 2 | +title: "ARM templates" |
| 3 | +layout: default |
| 4 | +--- |
| 5 | + |
| 6 | +# ARM |
| 7 | + |
| 8 | +This module provides the following capabilities: |
| 9 | +- [ARM](#arm) |
| 10 | + - [Installation](#installation) |
| 11 | + - [Injecting content into an ARM template](#injecting-content-into-an-arm-template) |
| 12 | + - [Usage](#usage) |
| 13 | + - [Injection Instructions](#injection-instructions) |
| 14 | + - [Recommendations](#recommendations) |
| 15 | + |
| 16 | +## Installation |
| 17 | + |
| 18 | +To have access to the following features, you have to import the module: |
| 19 | + |
| 20 | +```powershell |
| 21 | +PS> Install-Module -Name Arcus.Scripting.ARM |
| 22 | +``` |
| 23 | + |
| 24 | +## Injecting content into an ARM template |
| 25 | + |
| 26 | +In certain scenarios, you have to embed content into an ARM template to deploy it. |
| 27 | + |
| 28 | +However, the downside of it is that it's buried inside the template and tooling around it might be less ideal - An example of this is OpenAPI specifications you'd want to deploy. |
| 29 | + |
| 30 | +By using this script, you can inject external files inside your ARM template. |
| 31 | + |
| 32 | +| Parameter | Mandatory | Description | |
| 33 | +| --------- | --------- | ----------------------------------------------------------------------------------------------- | |
| 34 | +| `Path` | no | The file path to the ARM template to inject the external files into (default: `$PSScriptRoot`) | |
| 35 | + |
| 36 | +### Usage |
| 37 | +Annotating content to inject: |
| 38 | + |
| 39 | +```json |
| 40 | +{ |
| 41 | + "type": "Microsoft.ApiManagement/service/apis", |
| 42 | + "name": "[concat(parameters('ApiManagement.Name'),'/', parameters('ApiManagement.Api.Name'))]", |
| 43 | + "apiVersion": "2019-01-01", |
| 44 | + "properties": { |
| 45 | + "subscriptionRequired": true, |
| 46 | + "path": "demo", |
| 47 | + "value": "${ FileToInject='.\\..\\openapi\\api-sample.json', InjectAsJsonObject}$", |
| 48 | + "format": "swagger-json" |
| 49 | + }, |
| 50 | + "tags": "[variables('Tags')]", |
| 51 | + "dependsOn": [ |
| 52 | + ] |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +Injecting the content: |
| 57 | + |
| 58 | +```powershell |
| 59 | +PS> Inject-ArmContent -Path deploy\arm-template.json |
| 60 | +``` |
| 61 | + |
| 62 | +### Injection Instructions |
| 63 | + |
| 64 | +It is possible to supply injection instructions in the injection annotation, this allows you to add specific functionality to the injection. These are the available injection instructions: |
| 65 | + |
| 66 | +| Injection Instruction | Description | |
| 67 | +| --------------------- | ----------------------------------------------------------------------------------------------------------- | |
| 68 | +| `EscapeJson` | Replace double quotes not preceded by a backslash with escaped quotes | |
| 69 | +| `ReplaceSpecialChars` | Replace newline characters with literal equivalents, tabs with spaces and `"` with `\"` | |
| 70 | +| `InjectAsJsonObject` | Tests if the content is valid JSON and makes sure the content is injected without surrounding double quotes | |
| 71 | + |
| 72 | +Usage of multiple injection instructions is supported as well, for example if you need both the `EscapeJson` and `ReplaceSpecialChars` functionality. |
| 73 | + |
| 74 | +Some examples are: |
| 75 | +```powershell |
| 76 | +${ FileToInject = ".\Parent Directory\file.xml" } |
| 77 | +${ FileToInject = ".\Parent Directory\file.xml", EscapeJson, ReplaceSpecialChars } |
| 78 | +${ FileToInject = '.\Parent Directory\file.json', InjectAsJsonObject } |
| 79 | +``` |
| 80 | + |
| 81 | +### Recommendations |
| 82 | +Always inject the content in your ARM template as soon as possible, preferably during release build that creates the artifact |
0 commit comments