Save-Module -Name Az.KeyVault -Path ./modules -Force
# Edit variables as needed
$location='canadaeast'
$resourceGroup='rg-psfunccontainer-demo'
$acrName='crpsfunccontainerdemo'
$storageName='stpsfunccontainerdemo'
$appServicePlanName='asp-psfunccontainerdemo'
$functionappName='funcmypwshfunc'
$imageName='mypwshfunc'
$imageTag='v1'
az group create -g $resourceGroup -l $location
az acr create -n $acrName -l $location -g $resourceGroup --sku Standard
# Build container registry
az acr login -n $acrName
az acr build -r $acrName -t mypwshfunc:v1 ./
# Create functionapp
az storage account create -n $storageName -g $resourceGroup -l $location --sku Standard_LRS --kind StorageV2
az appservice plan create -n $appServicePlanName -g $resourceGroup -l $location --sku B1 --is-linux
az functionapp create -n $functionappName -g $resourceGroup --plan $appServicePlanName --storage-account $storageName --functions-version 4 --registry-server $acrLoginServer --image "${imageName}:${imageTag}"
# Setup AcrPull permission
az functionapp identity assign -n $functionappName -g $resourceGroup
$funcPrincipalId=az functionapp identity show -n $functionappName -g rc-psfunccontainer-demo --query principalId --output tsv
$acrResourceId=az acr show -n $acrName --query id --output tsv
az role assignment create --assignee $funcPrincipalId --role AcrPull --scope $acrResourceId
$acrLoginServer=az acr show -n $acrName --query loginServer --output tsv
# Enable managed identity auth to container registry
$funcResourceId=az functionapp show -n $functionappName -g $resourceGroup --query id --output tsv
az resource update --ids $funcResourceId --set properties.siteConfig.acrUseManagedIdentityCreds=true
# # Set image
# az functionapp config container set -n $functionappName -g $resourceGroup --registry-server $acrLoginServer --image "${imageName}:${imageTag}"