Azure App Service (Web Apps) Custom Hostname Binding
This page shows how to write Terraform and Azure Resource Manager for App Service (Web Apps) Custom Hostname Binding and write them securely.
azurerm_app_service_custom_hostname_binding (Terraform)
The Custom Hostname Binding in App Service (Web Apps) can be configured in Terraform with the resource name azurerm_app_service_custom_hostname_binding
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_app_service_custom_hostname_binding" "example" {
hostname = "www.mywebsite.com"
app_service_name = azurerm_app_service.example.name
resource_group_name = azurerm_resource_group.example.name
ssl_state = "IpBasedEnabled"
}
resource "azurerm_app_service_custom_hostname_binding" "example" {
hostname = "www.mywebsite.com"
app_service_name = azurerm_app_service.example.name
resource_group_name = azurerm_resource_group.example.name
ssl_state = "IpBasedEnabled"
}
resource "azurerm_app_service_custom_hostname_binding" "app_binding" {
hostname = var.hostname
app_service_name = var.app_service_name
resource_group_name = var.resource_group_name
ssl_state = var.ssl_state
thumbprint = var.thumbprint
resource "azurerm_app_service_custom_hostname_binding" "panel" {
hostname = "panel.faithfulknights.com"
app_service_name = var.panel_name
resource_group_name = var.resource_group_name
}
resource "azurerm_app_service_custom_hostname_binding" "this" {
app_service_name = var.app_service_name
hostname = var.hostname
resource_group_name = var.resource_group_name
ssl_state = var.ssl_state
thumbprint = var.thumbprint
resource "azurerm_app_service_custom_hostname_binding" "function_custom_domain_binding" {
hostname = var.CUSTOM_DOMAIN
app_service_name = azurerm_function_app.function_app.name
resource_group_name = var.RESOURCE_GROUP_NAME
}
resource "azurerm_app_service_custom_hostname_binding" "customDomain" {
for_each = local.azure_webApps_data
hostname = var.your_domain
app_service_name = each.value.name
resource_group_name = each.value.resource_group
resource "azurerm_app_service_custom_hostname_binding" "pasionporlosbits_binding_dns" {
hostname = var.url_site
app_service_name = azurerm_app_service.pasionporlosbits_webapp.name
resource_group_name = azurerm_resource_group.CharlaResourceGroup.name
ssl_state = "SniEnabled"
thumbprint = var.cert_thumbprint
resource "azurerm_app_service_custom_hostname_binding" "hostname_binding" {
hostname = trim(azurerm_dns_cname_record.dns_cname_record.fqdn, ".")
app_service_name = var.app_service_name
resource_group_name = var.resource_group_name
ssl_state = var.ssl_state
thumbprint = var.custom_domain.certificate_thumbprint
resource "azurerm_app_service_custom_hostname_binding" "webapp_host_binding" {
hostname = var.app_dns_url
app_service_name = azurerm_app_service.webapp.name
resource_group_name = var.rg_name
count = var.create_host_binding
ssl_state = "SniEnabled"
Parameters
-
app_service_name
required - string -
hostname
required - string -
id
optional computed - string -
resource_group_name
required - string -
ssl_state
optional computed - string -
thumbprint
optional computed - string -
virtual_ip
optional computed - string -
timeouts
single block
Explanation in Terraform Registry
Manages a Hostname Binding within an App Service (or Function App).
Tips: Best Practices for The Other Azure App Service (Web Apps) Resources
In addition to the azurerm_app_service, Azure App Service (Web Apps) has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
azurerm_app_service
Ensure your App Service is accessible via HTTPS only
It is better to configure the App Service to be accessible via HTTPS only. By default, both HTTP and HTTPS are available.
azurerm_function_app
Ensure to enable authentication to prevent anonymous request being accepted
It is better to enable authentication to prevent anonymous requests and ensure all communications in the application are authenticated.
Microsoft.Web/sites/hostNameBindings (Azure Resource Manager)
The sites/hostNameBindings in Microsoft.Web can be configured in Azure Resource Manager with the resource name Microsoft.Web/sites/hostNameBindings
. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
"contentVersion": "1.0.0.0",
"metadata" : {
"comments": "This ARM template deploys Azure resources included in the Health Bot Reference Architecture",
"type": "Microsoft.Web/sites/hostNameBindings",
"apiVersion": "2018-11-01",
"name": "[concat(parameters('sites_tmdemo_ceurope_name'), '/alexdemo-europe.trafficmanager.net')]",
"location": "France Central",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', parameters('sites_tmdemo_ceurope_name'))]"
"type": "Microsoft.Web/sites/hostNameBindings",
"apiVersion": "2018-11-01",
"name": "[concat(parameters('siteName'), '/', parameters('fqdn'))]",
"location": "[resourceGroup().location]",
"properties": {
"siteName": "[parameters('siteName')]",
"resourceType": "Microsoft.Web/sites/hostNameBindings",
"resourceLocation": "[parameters('webSiteHostBindingResourceLocation')]",
"hostName": "[parameters('webSiteHostBindingHostName')]",
"thumbprint":"[parameters('webSiteHostBindingCertificateThumbprint')]"
}
}
"type": "Microsoft.Web/sites/hostNameBindings",
"apiVersion": "2018-11-01",
"name": "[concat(parameters('siteName'), '/', parameters('fqdn'))]",
"location": "[resourceGroup().location]",
"properties": {
"siteName": "[parameters('siteName')]",
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
"contentVersion": "1.0.0.0",
"parameters": {
"certificateBinding": {
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"domainName": {
"type": "Microsoft.Web/sites/hostNameBindings",
"apiVersion": "2018-11-01",
"name": "[concat(variables('AppServiceName'), '/', parameters('customDomain'))]",
"location": "[resourceGroup().location]",
"dependsOn": [
],
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appName": {
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
"contentVersion": "1.0.0.0",
"parameters": {
"certificateBinding": {
Parameters
apiVersion
required - stringkind
optional - stringKind of resource.
name
required - stringHostname in the hostname binding.
properties
requiredazureResourceName
optional - stringAzure resource name.
azureResourceType
optional - stringAzure resource type.
customHostNameDnsRecordType
optional - stringCustom DNS record type.
domainId
optional - stringFully qualified ARM domain resource URI.
hostNameType
optional - stringHostname type.
siteName
optional - stringApp Service app name.
sslState
optional - stringSSL type.
thumbprint
optional - stringSSL certificate thumbprint
type
required - string
Frequently asked questions
What is Azure App Service (Web Apps) Custom Hostname Binding?
Azure App Service (Web Apps) Custom Hostname Binding is a resource for App Service (Web Apps) of Microsoft Azure. Settings can be wrote in Terraform.
Where can I find the example code for the Azure App Service (Web Apps) Custom Hostname Binding?
For Terraform, the gilyas/infracost, infracost/infracost and W2-Global-Data/azurerm_modules source code examples are useful. See the Terraform Example section for further details.
For Azure Resource Manager, the microsoft/HealthBotRefArchDeploy, true-while/Az204-demos and goodtocode/azure-arm source code examples are useful. See the Azure Resource Manager Example section for further details.