Skip to content

Commit

Permalink
Add pre-commit to generate ARM template (#520)
Browse files Browse the repository at this point in the history
* Add pre-commit to generate json

* Updating readme per suggestion in #516

* Some extra lines

* Test updating child template
  • Loading branch information
ross-p-smith authored Apr 30, 2024
1 parent 59f63dd commit a85beac
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,15 @@ repos:
hooks:
- id: flake8
args: [--extend-ignore=E501]

- repo: local
hooks:
- id: bicep
name: bicep
description: Lint and build Bicep files
entry: ./infra/generate_arm_template.sh
language: script
files: \.bicep$
require_serial: true
args: # Bicep files that we want to generate ARM templates from
- -f=./infra/main.bicep
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ az deployment sub create --subscription <subscription-id> --location <location>

Or

To deploy with isolated network use following command. (Replace the parameter values where needed). If you do not fill in all three, the deployment will not deploy this to an isolated network.
To deploy with isolated network use following command. Replace the parameter values with the specifics of your isolated network. You **must** supply all three parameters (i.e. `vnetAddressSpace`, `proxySubnetAddressSpace` and `subnetAddressSpace`) if you wish to deploy to an isolated network.

```bash
az login
Expand Down
29 changes: 29 additions & 0 deletions infra/generate_arm_template.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

set -e

az bicep version 2>/dev/null || az bicep install

TEMPLATES=()
FILES=()

for ARG in $@; do
# If the argument is supplied with "-f", then it is a template file that needs to be built
if [[ $ARG == -f=* ]]; then
TEMPLATES+=(${ARG#-f=})
else
# Otherwise, it is a file that has been edited
az bicep format --insert-final-newline -f $ARG &
FILES+=($ARG)
fi
done

wait

git add ${FILES[@]}

# Build the templates
for TEMPLATE in ${TEMPLATES[@]}; do
az bicep build -f $TEMPLATE
git add "${TEMPLATE%.bicep}.json" # Change the extension from .bicep to .json
done
6 changes: 3 additions & 3 deletions infra/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"_generator": {
"name": "bicep",
"version": "0.26.170.59819",
"templateHash": "12432953680684304440"
"templateHash": "14273384520214979046"
}
},
"parameters": {
Expand Down Expand Up @@ -229,7 +229,7 @@
"_generator": {
"name": "bicep",
"version": "0.26.170.59819",
"templateHash": "14632940777771929108"
"templateHash": "2144895217405179275"
}
},
"parameters": {
Expand All @@ -248,7 +248,7 @@
"type": "string",
"defaultValue": "",
"metadata": {
"description": "Service principal that should be granted read access to the KeyVault. If unset, no service principal is granted access by default"
"description": "Service principal will be granted read access to the KeyVault. If unset, no service principal is granted access by default"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion infra/shared/keyvault.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ param name string
param location string = resourceGroup().location
param tags object = {}

@description('Service principal that should be granted read access to the KeyVault. If unset, no service principal is granted access by default')
@description('Service principal will be granted read access to the KeyVault. If unset, no service principal is granted access by default')
param principalId string = ''

var defaultAccessPolicies = !empty(principalId) ? [
Expand Down

0 comments on commit a85beac

Please sign in to comment.