0

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?

David
  • 1,203
  • 6
  • 25
  • 48

2 Answers2

3

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

Jim Xu
  • 21,610
  • 2
  • 19
  • 39
  • I might not have the syntax right but when I run az apim update --name myapim --resource-group MyRG --set hostnameConfigurations={[{"hostName": "bbb.hostname.com.au", "type": "Proxy", "keyVaultId": "https://mykeyvault/secrets/mysecret", "defaultSslBinding": true,"negotiateClientCertificate": true}]} I get the following error - Couldn't find 'bbb' in 'bbb.hostname'. – David Nov 16 '20 at 11:26
  • Please try to convert the json to string via https://tools.knowledgewalls.com/jsontostring. Then run again. – Jim Xu Nov 16 '20 at 12:26
0

You can use this approach:

        az apim update --resource-group $rgName --name $apiMgmtName `
        --add hostnameConfigurations type=Proxy host_name=$hostName `
        encodedCertificate=$certData certificatePassword=$certPassword `
        negotiateClientCertificate=false
i0pr1m3
  • 46
  • 1