Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2158] Replace terrafile #220

Merged
merged 3 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ terraform/application/vendor
terraform/domains/environment_domains/vendor
terraform/domains/infrastructure/vendor/
terraform.tfstate*
bin/terrafile

.env
34 changes: 19 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
TERRAFILE_VERSION=0.8
ARM_TEMPLATE_TAG=1.1.10
RG_TAGS={"Product" : "Find a teaching school hub"}
REGION=UK South
Expand Down Expand Up @@ -48,15 +47,13 @@ ci:
$(eval SKIP_AZURE_LOGIN=true)
$(eval SKIP_CONFIRM=true)

bin/terrafile: ## Install terrafile to manage terraform modules
curl -sL https://github.com/coretech/terrafile/releases/download/v${TERRAFILE_VERSION}/terrafile_${TERRAFILE_VERSION}_$$(uname)_x86_64.tar.gz \
| tar xz -C ./bin terrafile

set-azure-account:
[ "${SKIP_AZURE_LOGIN}" != "true" ] && az account set -s ${AZURE_SUBSCRIPTION} || true

terraform-init: composed-variables bin/terrafile set-azure-account
./bin/terrafile -p terraform/application/vendor/modules -f terraform/application/config/$(CONFIG)_Terrafile
terraform-init: composed-variables set-azure-account
rm -rf terraform/application/vendor/modules/aks
git -c advice.detachedHead=false clone --depth=1 --single-branch --branch ${TERRAFORM_MODULES_TAG} https://github.com/DFE-Digital/terraform-modules.git terraform/application/vendor/modules/aks

terraform -chdir=terraform/application init -upgrade -reconfigure \
-backend-config=resource_group_name=${RESOURCE_GROUP_NAME} \
-backend-config=storage_account_name=${STORAGE_ACCOUNT_NAME} \
Expand Down Expand Up @@ -97,8 +94,9 @@ deploy-arm-resources: arm-deployment ## Validate ARM resource deployment. Usage:

validate-arm-resources: set-what-if arm-deployment ## Validate ARM resource deployment. Usage: make domains validate-arm-resources

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
domains-infra-init: domains composed-variables set-azure-account
rm -rf terraform/domains/infrastructure/vendor/modules/domains
git -c advice.detachedHead=false clone --depth=1 --single-branch --branch ${TERRAFORM_MODULES_TAG} https://github.com/DFE-Digital/terraform-modules.git terraform/domains/infrastructure/vendor/modules/domains

terraform -chdir=terraform/domains/infrastructure init -reconfigure -upgrade \
-backend-config=resource_group_name=${RESOURCE_GROUP_NAME} \
Expand All @@ -111,14 +109,18 @@ domains-infra-plan: domains domains-infra-init ## Terraform plan for DNS infras
domains-infra-apply: domains domains-infra-init ## Terraform apply for DNS infrastructure (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
domains-init: domains composed-variables set-azure-account
rm -rf terraform/domains/environment_domains/vendor/modules/domains
git -c advice.detachedHead=false clone --depth=1 --single-branch --branch ${TERRAFORM_MODULES_TAG} https://github.com/DFE-Digital/terraform-modules.git terraform/domains/environment_domains/vendor/modules/domains

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-destroy: domains-init ## Terraform destroy for DNS environment domains. Usage: make development domains domains-destroy
terraform -chdir=terraform/domains/environment_domains destroy -var-file config/${CONFIG}.tfvars.json

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

Expand All @@ -138,12 +140,14 @@ get-cluster-credentials: set-azure-account
kubelogin convert-kubeconfig -l $(if ${GITHUB_ACTIONS},spn,azurecli)

aks-console: get-cluster-credentials
$(if $(PULL_REQUEST_NUMBER), $(eval export APP_ID=review-$(PULL_REQUEST_NUMBER)) , $(eval export APP_ID=$(CONFIG_LONG)))
kubectl -n ${NAMESPACE} exec -ti --tty deployment/cpd-tsh-${APP_ID} -- /bin/sh -c "cd /app && bundle exec rails c"
$(if $(PULL_REQUEST_NUMBER), $(eval export APP_ID=review-$(PULL_REQUEST_NUMBER)) , $(eval export APP_ID=$(CONFIG)))
$(eval NAMESPACE=$(shell jq -r '.namespace' terraform/application/config/${CONFIG}.tfvars.json))
kubectl -n ${NAMESPACE} exec -ti deployment/cpd-tsh-${APP_ID} -- /bin/sh -c "cd /app && bundle exec rails c"

aks-ssh: get-cluster-credentials
$(if $(PULL_REQUEST_NUMBER), $(eval export APP_ID=review-$(PULL_REQUEST_NUMBER)) , $(eval export APP_ID=$(CONFIG_LONG)))
kubectl -n ${NAMESPACE} exec -ti --tty deployment/teaching-school-hub-finder-${APP_ID} -- /bin/sh
$(if $(PULL_REQUEST_NUMBER), $(eval export APP_ID=review-$(PULL_REQUEST_NUMBER)) , $(eval export APP_ID=$(CONFIG)))
$(eval NAMESPACE=$(shell jq -r '.namespace' terraform/application/config/${CONFIG}.tfvars.json))
kubectl -n ${NAMESPACE} exec -ti deployment/cpd-tsh-${APP_ID} -- /bin/sh

.PHONY: install-konduit
install-konduit: ## Install the konduit script, for accessing backend services
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

Live version of the service can be find here: https://find-a-teaching-school-hub.education.gov.uk/

## Test environments
- [Staging](https://staging.find-a-teaching-school-hub.education.gov.uk/)
- [Sandbox](https://sandbox.find-a-teaching-school-hub.education.gov.uk/)
- Review apps: the link is posted in the pull request

## Setup

### Prerequisites
Expand Down
1 change: 1 addition & 0 deletions global_config/domains.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ AZURE_SUBSCRIPTION=s189-teacher-services-cloud-production
AZURE_RESOURCE_PREFIX=s189p01
CONFIG_SHORT=dom
DISABLE_KEYVAULTS=true
TERRAFORM_MODULES_TAG=stable
2 changes: 1 addition & 1 deletion global_config/production.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ CONFIG_SHORT=pd
AZURE_SUBSCRIPTION=s189-teacher-services-cloud-production
AZURE_RESOURCE_PREFIX=s189p01
ENABLE_KV_DIAGNOSTICS=true
CONFIG_LONG=production
NAMESPACE=cpd-production
TERRAFORM_MODULES_TAG=stable
2 changes: 1 addition & 1 deletion global_config/review.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ CONFIG_SHORT=rv
AZURE_SUBSCRIPTION=s189-teacher-services-cloud-test
AZURE_RESOURCE_PREFIX=s189t01
KV_PURGE_PROTECTION=false
CONFIG_LONG=review
NAMESPACE=cpd-review
TERRAFORM_MODULES_TAG=main
1 change: 1 addition & 0 deletions global_config/sandbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ ENVIRONMENT=sandbox
CONFIG_SHORT=sb
AZURE_SUBSCRIPTION=s189-teacher-services-cloud-production
AZURE_RESOURCE_PREFIX=s189p01
TERRAFORM_MODULES_TAG=testing
1 change: 1 addition & 0 deletions global_config/staging.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ CONFIG_SHORT=st
AZURE_SUBSCRIPTION=s189-teacher-services-cloud-test
AZURE_RESOURCE_PREFIX=s189t01
KV_PURGE_PROTECTION=false
TERRAFORM_MODULES_TAG=testing
30 changes: 16 additions & 14 deletions terraform/application/.terraform.lock.hcl

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

3 changes: 0 additions & 3 deletions terraform/application/config/production_Terrafile

This file was deleted.

3 changes: 0 additions & 3 deletions terraform/application/config/review_Terrafile

This file was deleted.

3 changes: 0 additions & 3 deletions terraform/application/config/sandbox_Terrafile

This file was deleted.

3 changes: 0 additions & 3 deletions terraform/application/config/staging_Terrafile

This file was deleted.

1 change: 1 addition & 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.

This file was deleted.

This file was deleted.

This file was deleted.

16 changes: 16 additions & 0 deletions terraform/domains/environment_domains/config/sandbox.tfvars.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"hosted_zone": {
"find-a-teaching-school-hub.education.gov.uk": {
"front_door_name": "s189p01-cpdtsh-dom-fd",
"resource_group_name": "s189p01-cpdtsh-dom-rg",
"domains": [
"sandbox"
],
"cached_paths": [
"/assets/*"
],
"environment_short": "sb",
"origin_hostname": "cpd-tsh-sandbox.teacherservices.cloud"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"hosted_zone": {
"teaching-school-hub-finder.education.gov.uk": {
"find-a-teaching-school-hub.education.gov.uk": {
"front_door_name": "s189p01-cpdtsh-dom-fd",
"resource_group_name": "s189p01-cpdtsh-dom-rg",
"domains": [
Expand All @@ -9,8 +9,8 @@
"cached_paths": [
"/assets/*"
],
"environment_short": "dv",
"origin_hostname": "teaching-school-hub-finder-staging.test.teacherservices.cloud"
"environment_short": "st",
"origin_hostname": "cpd-tsh-staging.test.teacherservices.cloud"
}
}
}

This file was deleted.

1 change: 1 addition & 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.

3 changes: 0 additions & 3 deletions terraform/domains/infrastructure/config/zones_Terrafile

This file was deleted.

Loading