Skip to content

Instantly share code, notes, and snippets.

@johnlokerse
Created March 17, 2024 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnlokerse/68fedd5c4ac27babeb37c57b9c730a9a to your computer and use it in GitHub Desktop.
Save johnlokerse/68fedd5c4ac27babeb37c57b9c730a9a to your computer and use it in GitHub Desktop.
Create your own function in Azure Bicep with user-defined functions blog
@description('Arguments given for the deployment script')
param parScriptArguments deploymentScriptArgumentsType = [
{
name: 'FirstName'
value: 'John'
}
{
name: 'LastName'
value: 'Doe'
}
]
@description('Resource location')
param parLocation string = resourceGroup().location
resource resManagedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2022-01-31-preview' = {
name: 'ds-managed-identity'
location: parLocation
}
resource resDeploymentScript 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
name: 'ds-write-host-pwsh'
location: parLocation
kind: 'AzurePowerShell'
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'${resManagedIdentity.id}': {}
}
}
properties: {
azPowerShellVersion: '11.0'
retentionInterval: 'P1D'
arguments: funcFormatArguments(parScriptArguments, ' ')
scriptContent: '''
param (
[Parameter(Mandatory=$true)]
[string] $FirstName,
[Parameter(Mandatory=$true)]
[string] $LastName
)
Write-Host "Hello and welcome, $FirstName $LastName!"
'''
}
}
type deploymentScriptArgumentsType = {
name: string
value: string
}[]
func funcFormatArguments(arguments deploymentScriptArgumentsType, delimiter string) string => join(map(arguments, arg => '-${arg.name} ${arg.value}'), delimiter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment