Skip to content

Commit

Permalink
Add DNS to each environment (pt. 1) (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
benchiverton authored Jul 1, 2024
1 parent 5465edf commit ea87372
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/instance-deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
TF_VAR_environment: prod
TF_VAR_acr_username: ${{ secrets.ACR_USERNAME }}
TF_VAR_acr_password: ${{ secrets.ACR_TOKEN }}
TF_VAR_website_dns_subdomain: www
- name: Terraform Apply
id: apply
run: terraform -chdir=instance apply -auto-approve
Expand All @@ -69,6 +70,7 @@ jobs:
TF_VAR_environment: prod
TF_VAR_acr_username: ${{ secrets.ACR_USERNAME }}
TF_VAR_acr_password: ${{ secrets.ACR_TOKEN }}
TF_VAR_website_dns_subdomain: www
- name: Save terraform outputs
shell: bash
run: |
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/instance-deploy-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ jobs:
TF_VAR_environment: ${{ github.head_ref }}
TF_VAR_acr_username: ${{ secrets.ACR_USERNAME }}
TF_VAR_acr_password: ${{ secrets.ACR_TOKEN }}
TF_VAR_website_dns_subdomain: ${{ github.head_ref }}
- name: Terraform Apply
id: apply
run: terraform -chdir=instance apply -auto-approve
Expand All @@ -68,6 +69,7 @@ jobs:
TF_VAR_environment: ${{ github.head_ref }}
TF_VAR_acr_username: ${{ secrets.ACR_USERNAME }}
TF_VAR_acr_password: ${{ secrets.ACR_TOKEN }}
TF_VAR_website_dns_subdomain: ${{ github.head_ref }}
- name: Save terraform outputs
shell: bash
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/instance-destroy-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ jobs:
env:
TF_VAR_acr_username: "not-used"
TF_VAR_acr_password: "not-used"
TF_VAR_website_dns_subdomain: "not-used"
1 change: 1 addition & 0 deletions .github/workflows/instance-plan-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
TF_VAR_environment: prod
TF_VAR_acr_username: ${{ secrets.ACR_USERNAME }}
TF_VAR_acr_password: ${{ secrets.ACR_TOKEN }}
TF_VAR_website_dns_subdomain: www
- name: Find Comment
uses: peter-evans/find-comment@v1
id: fc
Expand Down
5 changes: 2 additions & 3 deletions terraform/instance/container_apps.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
resource "azurerm_container_app_environment" "apps" {
data "azurerm_container_app_environment" "apps" {
name = "${var.name}-containerapps"
resource_group_name = azurerm_resource_group.instance.name
location = azurerm_resource_group.instance.location
resource_group_name = "onlinestore-shared-rg"
}

resource "azurerm_container_app" "api" {
Expand Down
5 changes: 5 additions & 0 deletions terraform/instance/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ variable "acr_password" {
description = "The password to log in to ACR"
sensitive = true
}

variable "website_dns_subdomain" {
type = string
description = "DNS subdomain for website"
}
28 changes: 14 additions & 14 deletions terraform/shared/.terraform.lock.hcl

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

5 changes: 5 additions & 0 deletions terraform/shared/container-app-environment.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "azurerm_container_app_environment" "apps" {
name = "${var.name}-containerapps"
resource_group_name = azurerm_resource_group.shared.name
location = azurerm_resource_group.shared.location
}
22 changes: 22 additions & 0 deletions terraform/shared/dns.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
data "azurerm_dns_zone" "rockpal-co-uk" {
name = "rockpal.co.uk"
resource_group_name = "onlinestore-shared-rg"
}

resource "azurerm_dns_a_record" "apps" {
name = azurerm_container_app_environment.apps.name
zone_name = data.azurerm_dns_zone.rockpal-co-uk.name
resource_group_name = data.azurerm_dns_zone.rockpal-co-uk.resource_group_name
ttl = 300
records = [azurerm_container_app_environment.apps.default_domain]
}

resource "azurerm_dns_txt_record" "apps" {
name = "asuid.${azurerm_container_app_environment.apps.name}"
zone_name = data.azurerm_dns_zone.rockpal-co-uk.name
resource_group_name = data.azurerm_dns_zone.rockpal-co-uk.resource_group_name
ttl = 300
record {
value = azurerm_container_app_environment.apps.custom_domain_verification_id
}
}
2 changes: 1 addition & 1 deletion terraform/shared/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=3.42.0"
version = "=3.109.0"
}
}
backend "azurerm" {
Expand Down

0 comments on commit ea87372

Please sign in to comment.