Skip to content

Commit

Permalink
edited 121
Browse files Browse the repository at this point in the history
  • Loading branch information
Houssem Dellai committed Jan 5, 2024
1 parent 4c32fff commit 975c383
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 31 deletions.
Binary file modified .infracost/pricing.gob
Binary file not shown.
14 changes: 7 additions & 7 deletions 121_appservice_domain/Readme.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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.
23 changes: 1 addition & 22 deletions 121_appservice_domain/appservice_domain.tf
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 14 additions & 0 deletions 121_appservice_domain/dns_zone.tf
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 2 additions & 2 deletions 121_appservice_domain/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions 121_appservice_domain/rg.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Resource Group
resource "azurerm_resource_group" "rg" {
name = var.rg_name
location = var.location
}

0 comments on commit 975c383

Please sign in to comment.