To have your own domain name (custom domain) for Api Management by using Terraform, I'm using the following script to have custom domain name for the Developer Portal and Proxy (the api). You can also have your own name for Management and SCM.
This scipt require that you have a pfx (certificate), named letsencrypt.pfx
in same directory as you Terraform script.
resource "azurerm_api_management" "mngmnt" {
name = "ApiManagementTest"
location = "northeurope"
resource_group_name = "ApiManagement--rg"
publisher_name = "Api pubisher"
publisher_email = "[email protected]"
hostname_configuration {
portal = [{
host_name = "api-portal.customdomain.com"
certificate = "${base64encode(file("letsencrypt.pfx"))}"
certificate_password = "topSecretPwd123"
}]
proxy = [{
host_name = "api.customdomain.com"
certificate = "${base64encode(file("letsencrypt.pfx"))}"
certificate_password = "topSecretPwd123"
}]
}
sku {
name = "Developer"
capacity = "1"
}
}
To have custom domain work you must also remember to add a CNAME record in your public DNS to the following:
api-portal.customdomain.com -> [your name of the Api Management].portal.azure-api.net
api.customdomain.com -> [your name of the Api Management].azure-api.net
Example by using name from our script, it would be:
api-portal.customdomain.com -> ApiManagementTest.portal.azure-api.net
api.customdomain.com -> ApiManagementTest.azure-api.net