diff --git a/.infracost/pricing.gob b/.infracost/pricing.gob index a6c14b8..2921e6d 100644 Binary files a/.infracost/pricing.gob and b/.infracost/pricing.gob differ diff --git a/121_appservice_domain/Readme.md b/121_appservice_domain/Readme.md index a27db25..e53aa07 100644 --- a/121_appservice_domain/Readme.md +++ b/121_appservice_domain/Readme.md @@ -1,5 +1,9 @@ # Azure App Service Domain in Terraform +## News + +This is now available as Terraform module on Terraform Registry: https://registry.terraform.io/modules/HoussemDellai/appservice-domain/azapi/ + ## Problem You can create a custom domain name in Azure using App Service Domain service. @@ -13,7 +17,7 @@ However for labs, workshops and demonstrations, this is very useful to make the ## Solution -We'll provide a Terraform implemntation for creating a custom domain name using Azure App Service Domain. +We'll provide a Terraform implementation for creating a custom domain name using Azure App Service Domain. We'll use `AzApi` provider to create the resource. More info about AzApi here: https://registry.terraform.io/providers/Azure/azapi/latest/docs/resources/azapi_resource. The AzApi will call the REST API and pass the required JSON file containing the needed attributes. @@ -23,7 +27,7 @@ We also create an Azure DNS Zone to manage and configure the domain name. And we create an A record "test" to make sure the configuration works. -The complete Terraform implemntation is in this current folder. +The complete Terraform implementation is in this current folder. But here is a ```terraform @@ -106,16 +110,12 @@ az appservice domain create ` ## Important notes -You should use a Pay-As-You-Go azure subcription to be able to create Azure App Service Domain. +You should use a Pay-As-You-Go azure subscription to be able to create Azure App Service Domain. MSDN/VisualStudio and Free Azure subscriptions doesn't work. Within the terraform config file, you can change the contact info for the contactAdmin, contactRegistrant, contactBilling and contactTech. It worked for me when reusing the same contact ! -We didn't create any link between DNS Zone and App Service Domain. -How the DNS Zone was linked/bound to the custom domain name ? -I suppose it is a default Azure configuration, as the two resources are in the same resource group and/or the use the same domain name. - ## What is next ? You can explore App Service Domain with Azure Container Apps (ACA) in this lab: https://github.com/HoussemDellai/aca-course/tree/main/14_aca_custom_domain. \ No newline at end of file diff --git a/121_appservice_domain/appservice_domain.tf b/121_appservice_domain/appservice_domain.tf index 25ce821..511538d 100644 --- a/121_appservice_domain/appservice_domain.tf +++ b/121_appservice_domain/appservice_domain.tf @@ -1,29 +1,8 @@ -# Resource Group -resource "azurerm_resource_group" "rg" { - name = var.rg_name - location = var.location -} - -# DNS Zone to configure the domain name -resource "azurerm_dns_zone" "dns_zone" { - name = var.domain_name - resource_group_name = azurerm_resource_group.rg.name -} - -# DNS Zone A record -resource "azurerm_dns_a_record" "dns_a_record" { - name = "test" - zone_name = azurerm_dns_zone.dns_zone.name - resource_group_name = azurerm_resource_group.rg.name - ttl = 300 - records = ["1.2.3.4"] # just example IP address -} - # App Service Domain # REST API reference: https://docs.microsoft.com/en-us/rest/api/appservice/domains/createorupdate resource "azapi_resource" "appservice_domain" { type = "Microsoft.DomainRegistration/domains@2022-09-01" - name = "mycompany.com" + name = var.domain_name parent_id = azurerm_resource_group.rg.id location = "global" schema_validation_enabled = true diff --git a/121_appservice_domain/dns_zone.tf b/121_appservice_domain/dns_zone.tf new file mode 100644 index 0000000..b82d056 --- /dev/null +++ b/121_appservice_domain/dns_zone.tf @@ -0,0 +1,14 @@ +# DNS Zone to configure the domain name +resource "azurerm_dns_zone" "dns_zone" { + name = var.domain_name + resource_group_name = azurerm_resource_group.rg.name +} + +# DNS Zone A record +resource "azurerm_dns_a_record" "dns_a_record" { + name = "test" + zone_name = azurerm_dns_zone.dns_zone.name + resource_group_name = azurerm_resource_group.rg.name + ttl = 300 + records = ["1.2.3.4"] # just example IP address +} diff --git a/121_appservice_domain/providers.tf b/121_appservice_domain/providers.tf index ecd3d64..27a6e95 100644 --- a/121_appservice_domain/providers.tf +++ b/121_appservice_domain/providers.tf @@ -6,12 +6,12 @@ terraform { azurerm = { source = "hashicorp/azurerm" - version = "= 3.68.0" + version = "= 3.85.0" } azapi = { source = "Azure/azapi" - version = "1.8.0" + version = "1.11.0" } } } diff --git a/121_appservice_domain/rg.tf b/121_appservice_domain/rg.tf new file mode 100644 index 0000000..073ef9e --- /dev/null +++ b/121_appservice_domain/rg.tf @@ -0,0 +1,5 @@ +# Resource Group +resource "azurerm_resource_group" "rg" { + name = var.rg_name + location = var.location +} \ No newline at end of file