Search code examples
bashazure-cli

Azure CLI - Bash script to set up API Management custom domain


I am trying to set up a custom domain in api management using a bash script. I know it can be done using powershell

# Upload the custom ssl certificate to be applied to Proxy endpoint / Api Gateway endpoint
$proxyCertUploadResult = Import-AzApiManagementHostnameCertificate -Name $apimServiceName - 
ResourceGroupName $resourceGroupName -HostnameType "Proxy" -PfxPath $proxyCertificatePath - 
PfxPassword $proxyCertificatePassword

# Upload the custom ssl certificate to be applied to Portal endpoint
$portalCertUploadResult = Import-AzApiManagementHostnameCertificate -Name $apimServiceName - 
ResourceGroupName $resourceGroupName -HostnameType "Portal" -PfxPath $portalCertificatePath - 
PfxPassword $portalCertificatePassword

# Create the HostnameConfiguration object for Portal endpoint
$PortalHostnameConf = New-AzApiManagementHostnameConfiguration -Hostname $proxyHostname - 
CertificateThumbprint $proxyCertUploadResult.Thumbprint

# Create the HostnameConfiguration object for Proxy endpoint
$ProxyHostnameConf = New-AzApiManagementHostnameConfiguration -Hostname $portalHostname - 
CertificateThumbprint $portalCertUploadResult.Thumbprint

# Apply the configuration to API Management
Set-AzApiManagementHostnames -Name $apimServiceName -ResourceGroupName $resourceGroupName `
    -PortalHostnameConfiguration $PortalHostnameConf -ProxyHostnameConfiguration $ProxyHostnameConf

Is it possible to do a similar thing using bash?


Solution

  • If you want to configure custom domain for Azure API management with Azure CLI, we can use the command az apim update --set hostnameConfigurations={setting}. The hostnameConfigurations setting should be like

    [{
            "hostName": "bbb.beesphotos.net",
            "type": "Portal",
            "certificate": null,
            "certificatePassword": "<pfx file passsword>",
            "encodedCertificate": "Base64 Encoded certificate content"
        }, {
            "hostName": "huryapim.azure-api.net",
            "type": "Proxy",
            "certificate": null,
            "defaultSslBinding": true,
            "negotiateClientCertificate": false
        }
    ]
    

    enter image description here