Skip to content

Commit

Permalink
Merge pull request #858 from DFE-Digital/2048-aytq-migrate-domains
Browse files Browse the repository at this point in the history
2048 aytq migrate domains
  • Loading branch information
shaheislamdfe authored Sep 30, 2024
2 parents ad345ce + 2dce643 commit 056f6e2
Show file tree
Hide file tree
Showing 20 changed files with 241 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ tmp/pids/*
.terraform/
fetch_config.rb
terraform/application/vendor
terraform/domains/infrastructure/vendor
terraform/domains/environment_domains/vendor
bin/terrafile

# Active Storage folder
Expand Down
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ aks-preprod: test-cluster
aks-production: production-cluster
$(eval include global_config/production.sh)

.PHONY: domains
domains:
$(eval include global_config/domains.sh)

composed-variables: ## Compose variables needed for deployments
$(eval RESOURCE_GROUP_NAME=${AZURE_RESOURCE_PREFIX}-${SERVICE_SHORT}-${CONFIG_SHORT}-rg)
$(eval KEYVAULT_NAMES='("${AZURE_RESOURCE_PREFIX}-${SERVICE_SHORT}-${CONFIG_SHORT}-app-kv", "${AZURE_RESOURCE_PREFIX}-${SERVICE_SHORT}-${CONFIG_SHORT}-inf-kv")')
Expand Down Expand Up @@ -270,3 +274,31 @@ validate-arm-resources: set-what-if arm-deployment ## Validate ARM resource depl
get-cluster-credentials: set-azure-account ## Get AKS cluster credentials
az aks get-credentials --overwrite-existing -g ${CLUSTER_RESOURCE_GROUP_NAME} -n ${CLUSTER_NAME}
kubelogin convert-kubeconfig -l $(if ${GITHUB_ACTIONS},spn,azurecli)

domains-infra-init: bin/terrafile domains composed-variables set-azure-account
./bin/terrafile -p terraform/domains/infrastructure/vendor/modules -f terraform/domains/infrastructure/config/zones_Terrafile

terraform -chdir=terraform/domains/infrastructure init -reconfigure -upgrade \
-backend-config=resource_group_name=${RESOURCE_GROUP_NAME} \
-backend-config=storage_account_name=${STORAGE_ACCOUNT_NAME} \
-backend-config=key=domains_infrastructure.tfstate

domains-infra-plan: domains domains-infra-init ## Terraform plan for DNS infrastructure (DNS zone and front door). Usage: make domains-infra-plan
terraform -chdir=terraform/domains/infrastructure plan -var-file config/zones.tfvars.json

domains-infra-apply: domains domains-infra-init ## Terraform apply for DNS infrastructure (DNS zone and front door). Usage: make domains-infra-apply
terraform -chdir=terraform/domains/infrastructure apply -var-file config/zones.tfvars.json ${AUTO_APPROVE}

domains-init: bin/terrafile domains composed-variables set-azure-account
./bin/terrafile -p terraform/domains/environment_domains/vendor/modules -f terraform/domains/environment_domains/config/${CONFIG}_Terrafile

terraform -chdir=terraform/domains/environment_domains init -upgrade -reconfigure \
-backend-config=resource_group_name=${RESOURCE_GROUP_NAME} \
-backend-config=storage_account_name=${STORAGE_ACCOUNT_NAME} \
-backend-config=key=${ENVIRONMENT}.tfstate

domains-plan: domains-init ## Terraform plan for DNS environment domains. Usage: make development domains-plan
terraform -chdir=terraform/domains/environment_domains plan -var-file config/${CONFIG}.tfvars.json

domains-apply: domains-init ## Terraform apply for DNS environment domains. Usage: make development domains-apply
terraform -chdir=terraform/domains/environment_domains apply -var-file config/${CONFIG}.tfvars.json ${AUTO_APPROVE}
4 changes: 4 additions & 0 deletions global_config/domains.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
AZURE_SUBSCRIPTION=s189-teacher-services-cloud-production
AZURE_RESOURCE_PREFIX=s189p01
CONFIG_SHORT=dom
DISABLE_KEYVAULTS=true
22 changes: 22 additions & 0 deletions terraform/domains/environment_domains/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions terraform/domains/environment_domains/config/preprod.tfvars.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"hosted_zone": {
"access-your-teaching-qualifications.education.gov.uk": {
"front_door_name": "s189p01-aytq-dom-fd",
"resource_group_name": "s189p01-aytq-dom-rg",
"domains": ["preprod"],
"environment_short": "pp",
"origin_hostname": "s165t01-aytq-preprod-app.azurewebsites.net"
},
"check-a-teachers-record.education.gov.uk": {
"front_door_name": "s189p01-ctr-dom-fd",
"resource_group_name": "s189p01-aytq-dom-rg",
"domains": ["preprod"],
"environment_short": "pp",
"origin_hostname": "s165t01-aytq-preprod-app.azurewebsites.net"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
domains:
source: "https://github.com/DFE-Digital/terraform-modules"
version: "testing"
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"hosted_zone": {
"access-your-teaching-qualifications.education.gov.uk": {
"front_door_name": "s189p01-aytq-dom-fd",
"resource_group_name": "s189p01-aytq-dom-rg",
"domains": ["apex", "www"],
"environment_short": "pd",
"redirect_rules": [
{
"from-domain": "www",
"to-domain": "access-your-teaching-qualifications.education.gov.uk"
}
],
"origin_hostname": "s165p01-aytq-production-app.azurewebsites.net"
},
"check-a-teachers-record.education.gov.uk": {
"front_door_name": "s189p01-ctr-dom-fd",
"resource_group_name": "s189p01-aytq-dom-rg",
"domains": ["apex", "www"],
"environment_short": "pd",
"redirect_rules": [
{
"from-domain": "www",
"to-domain": "check-a-teachers-record.education.gov.uk"
}
],
"origin_hostname": "s165p01-aytq-production-app.azurewebsites.net"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
domains:
source: "https://github.com/DFE-Digital/terraform-modules"
version: "stable"
18 changes: 18 additions & 0 deletions terraform/domains/environment_domains/config/test.tfvars.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"hosted_zone": {
"access-your-teaching-qualifications.education.gov.uk": {
"front_door_name": "s189p01-aytq-dom-fd",
"resource_group_name": "s189p01-aytq-dom-rg",
"domains": ["test"],
"environment_short": "test",
"origin_hostname": "s165t01-aytq-test-app.azurewebsites.net"
},
"check-a-teachers-record.education.gov.uk": {
"front_door_name": "s189p01-ctr-dom-fd",
"resource_group_name": "s189p01-aytq-dom-rg",
"domains": ["test"],
"environment_short": "test",
"origin_hostname": "s165t01-aytq-test-app.azurewebsites.net"
}
}
}
3 changes: 3 additions & 0 deletions terraform/domains/environment_domains/config/test_Terrafile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
domains:
source: "https://github.com/DFE-Digital/terraform-modules"
version: "testing"
14 changes: 14 additions & 0 deletions terraform/domains/environment_domains/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Used to create domains to be managed by front door.
module "domains" {
for_each = var.hosted_zone
source = "./vendor/modules/domains//domains/environment_domains"
zone = each.key
front_door_name = each.value.front_door_name
resource_group_name = each.value.resource_group_name
domains = each.value.domains
environment = each.value.environment_short
host_name = each.value.origin_hostname
null_host_header = try(each.value.null_host_header, false)
cached_paths = try(each.value.cached_paths, [])
redirect_rules = try(each.value.redirect_rules, [])
}
19 changes: 19 additions & 0 deletions terraform/domains/environment_domains/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
terraform {

required_version = "= 1.6.4"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.116.0"
}
}
backend "azurerm" {
container_name = "terraform-state"
}
}

provider "azurerm" {
features {}

skip_provider_registration = true
}
4 changes: 4 additions & 0 deletions terraform/domains/environment_domains/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "hosted_zone" {
type = map(any)
default = {}
}
22 changes: 22 additions & 0 deletions terraform/domains/infrastructure/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions terraform/domains/infrastructure/config/zones.tfvars.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"hosted_zone": {
"access-your-teaching-qualifications.education.gov.uk": {
"resource_group_name": "s189p01-aytq-dom-rg",
"front_door_name": "s189p01-aytq-dom-fd"
},
"check-a-teachers-record.education.gov.uk": {
"resource_group_name": "s189p01-aytq-dom-rg",
"front_door_name": "s189p01-ctr-dom-fd"
}
}
}
3 changes: 3 additions & 0 deletions terraform/domains/infrastructure/config/zones_Terrafile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
domains:
source: "https://github.com/DFE-Digital/terraform-modules"
version: "stable"
5 changes: 5 additions & 0 deletions terraform/domains/infrastructure/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module "domains_infrastructure" {
source = "./vendor/modules/domains//domains/infrastructure"
hosted_zone = var.hosted_zone
deploy_default_records = var.deploy_default_records
}
19 changes: 19 additions & 0 deletions terraform/domains/infrastructure/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
terraform {
required_version = "= 1.6.4"

required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.116.0"
}
}
backend "azurerm" {
container_name = "terraform-state"
}
}

provider "azurerm" {
features {}

skip_provider_registration = true
}
7 changes: 7 additions & 0 deletions terraform/domains/infrastructure/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
variable "hosted_zone" {
type = map(any)
}

variable "deploy_default_records" {
default = true
}
1 change: 1 addition & 0 deletions terraform/domains/infrastructure/vendor/modules/domains
Submodule domains added at 799927

0 comments on commit 056f6e2

Please sign in to comment.