-
-
Save johnlokerse/68fedd5c4ac27babeb37c57b9c730a9a to your computer and use it in GitHub Desktop.
Create your own function in Azure Bicep with user-defined functions blog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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