Skip to content

Commit

Permalink
add www hostname binding
Browse files Browse the repository at this point in the history
  • Loading branch information
kahlstrm committed May 19, 2024
1 parent c129f95 commit 114d417
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
9 changes: 0 additions & 9 deletions modules/dns/root/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,3 @@ resource "azurerm_dns_a_record" "old_a" {
ttl = 300
records = ["130.233.48.30"]
}

# CNAME record for www.
resource "azurerm_dns_cname_record" "www_cname" {
name = "www"
resource_group_name = azurerm_resource_group.dns_rg.name
zone_name = azurerm_dns_zone.root_zone.name
ttl = 300
record = azurerm_dns_zone.root_zone.name
}
30 changes: 30 additions & 0 deletions modules/web/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ resource "azurerm_linux_web_app" "cms" {
}


# CNAME record for www.
resource "azurerm_dns_cname_record" "www_cname" {
name = "www"
resource_group_name = var.dns_resource_group_name
zone_name = var.root_zone_name
ttl = 300
record = azurerm_linux_web_app.web.default_hostname
}

resource "azurerm_app_service_custom_hostname_binding" "tikweb_hostname_binding" {
hostname = local.fqdn
app_service_name = azurerm_linux_web_app.web.name
Expand All @@ -149,6 +158,27 @@ resource "azurerm_app_service_custom_hostname_binding" "tikweb_hostname_binding"
azurerm_dns_txt_record.tikweb_asuid
]
}
resource "azurerm_app_service_custom_hostname_binding" "www_hostname_binding" {
hostname = "www.${local.fqdn}"
app_service_name = azurerm_linux_web_app.web.name
resource_group_name = var.resource_group_name
depends_on = [
azurerm_dns_cname_record.www_cname,
azurerm_dns_txt_record.tikweb_asuid_www
]

}

resource "azurerm_app_service_managed_certificate" "www_cert" {
custom_hostname_binding_id = azurerm_app_service_custom_hostname_binding.www_hostname_binding.id
}

resource "azurerm_app_service_certificate_binding" "www_cert_binding" {
hostname_binding_id = azurerm_app_service_custom_hostname_binding.www_hostname_binding.id
certificate_id = azurerm_app_service_managed_certificate.www_cert.id
ssl_state = "SniEnabled"
}

resource "random_password" "tikweb_cert_password" {
length = 48
special = false
Expand Down

0 comments on commit 114d417

Please sign in to comment.