How to make an HTTP call from Bicep? #7857
-
Hello, I am trying to create an Azure Virtual Network Manager (AVNM) using Bicep and so far the experience is great. I am not able to find how to call it from Bicep, and, from my understanding, it seems that it is not possible as it deploy the resources using ARM templates. Does anyone how to do it from Bicep? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Generally you should check if there is a list* function available on the provider. That will allow for a POST call, which often works for some API calls. In this case that doesn't exist, so the next best option will be to use a DeploymentScript. which is calling az cli or powershell from Bicep. It's quite easy... here are a few examples... https://github.com/brwilkinson/AzureDeploymentFramework/blob/main/ADF/bicep/x.setCDNServicesCertificates.ps1.bicep resource deploymentUser 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
name: 'getDeploymentUser'
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'${resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', userAssignedIdentityName)}': {}
}
}
location: resourceGroup().location
kind: 'AzurePowerShell'
properties: {
azPowerShellVersion: '6.2.1'
arguments: ' -ResourceGroupID ${resourceGroupID} -DeploymentName ${deployment} -StartTime ${logStartMinsAgo}'
scriptContent: loadTextContent('../bicep/loadTextContext/setCDNServicesCertificates.ps1')
forceUpdateTag: now
cleanupPreference: 'OnSuccess'
retentionInterval: 'P1D'
timeout: 'PT${logStartMinsAgo}M'
}
} Then here is the directory with many of the actual scripts that you can test standalone, then just plug in... https://github.com/brwilkinson/AzureDeploymentFramework/tree/main/ADF/bicep/loadTextContext Then you can use PowerShell or az cli to call the REST method.... or just use a build in command in those tools. Invoke-azrestmethod is also great... also the DeploymentScript has a Managed Identity so that will be the account that makes the call. This is how to return results from the deploymentscript $DeploymentScriptOutputs = @{}
$DeploymentScriptOutputs['keyRotation'] = $result |
Beta Was this translation helpful? Give feedback.
Generally you should check if there is a list* function available on the provider.
https://docs.microsoft.com/en-us/azure/azure-resource-manager/bicep/bicep-functions-resource#implementations
That will allow for a POST call, which often works for some API calls.
In this case that doesn't exist, so the next best option will be to use a DeploymentScript. which is calling az cli or powershell from Bicep.
It's quite easy...
here are a few examples...
https://github.com/brwilkinson/AzureDeploymentFramework/blob/main/ADF/bicep/x.setCDNServicesCertificates.ps1.bicep
https://github.com/brwilkinson/AzureDeploymentFramework/blob/main/ADF/bicep/x.setStorageKeyRotation.bicep