Skip to content

Commit 44dca8d

Browse files
fix: DTOSS-8428 letsencrypt certificate module supports multiple DNS domains (#142)
* fix: letsencrypt cert module supports multiple DNS domains * fix endless RBAC role redeploys for SQL logs storage account
1 parent a4b94bb commit 44dca8d

File tree

22 files changed

+182
-70
lines changed

22 files changed

+182
-70
lines changed

infrastructure/modules/app-service-plan/autoscale.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
resource "azurerm_monitor_autoscale_setting" "asp_autoscale" {
32
name = "${var.name}-autoscale"
43
resource_group_name = var.resource_group_name
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
resource "azurerm_app_service_certificate" "wildcard" {
2+
count = var.wildcard_ssl_cert_key_vault_secret_id != null ? 1 : 0
3+
4+
name = var.wildcard_ssl_cert_name
5+
resource_group_name = var.resource_group_name
6+
location = var.location
7+
8+
app_service_plan_id = azurerm_service_plan.appserviceplan.id
9+
key_vault_secret_id = var.wildcard_ssl_cert_key_vault_secret_id
10+
key_vault_id = var.wildcard_ssl_cert_key_vault_id
11+
}

infrastructure/modules/app-service-plan/main.tf

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
resource "azurerm_service_plan" "appserviceplan" {
2-
32
name = var.name
43
resource_group_name = var.resource_group_name
54
location = var.location
@@ -21,10 +20,6 @@ resource "azurerm_app_service_virtual_network_swift_connection" "appservice_vnet
2120
subnet_id = var.vnet_integration_subnet_id
2221
}
2322

24-
/* --------------------------------------------------------------------------------------------------
25-
Diagnostic Settings
26-
-------------------------------------------------------------------------------------------------- */
27-
2823
module "diagnostic-settings" {
2924
source = "../diagnostic-settings"
3025

@@ -33,6 +28,4 @@ module "diagnostic-settings" {
3328
log_analytics_workspace_id = var.log_analytics_workspace_id
3429
#enabled_log = var.enabled_log
3530
metric = var.monitor_diagnostic_setting_appserviceplan_metrics
36-
3731
}
38-
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
output "app_service_plan_name" {
32
value = azurerm_service_plan.appserviceplan.name
43
}
@@ -7,3 +6,6 @@ output "app_service_plan_id" {
76
value = azurerm_service_plan.appserviceplan.id
87
}
98

9+
output "wildcard_ssl_cert_id" {
10+
value = var.wildcard_ssl_cert_key_vault_secret_id != null ? azurerm_app_service_certificate.wildcard[0].id : null
11+
}

infrastructure/modules/app-service-plan/variables.tf

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ variable "sku_name" {
3535
default = "B1"
3636
}
3737

38+
variable "tags" {
39+
type = map(string)
40+
description = "Resource tags to be applied throughout the deployment."
41+
default = {}
42+
}
43+
3844
variable "vnet_integration_enabled" {
3945
type = bool
4046
description = "Indicates whether the App Service Plan is integrated with a VNET."
@@ -47,18 +53,32 @@ variable "vnet_integration_subnet_id" {
4753
default = ""
4854
}
4955

50-
variable "tags" {
51-
type = map(string)
52-
description = "Resource tags to be applied throughout the deployment."
53-
default = {}
56+
variable "wildcard_ssl_cert_key_vault_secret_id" {
57+
type = string
58+
description = "Wildcard SSL certificate Key Vault secret id, for App Service Custom Domain binding."
59+
default = null
5460
}
5561

62+
variable "wildcard_ssl_cert_key_vault_id" {
63+
type = string
64+
description = "Wildcard SSL certificate Key Vault id, needed if the Key Vault is in a different subscription."
65+
default = null
66+
}
67+
68+
variable "wildcard_ssl_cert_name" {
69+
type = string
70+
description = "Wildcard SSL certificate name, for Custom Domain binding."
71+
default = null
72+
}
73+
74+
5675
## autoscale rule ##
5776

5877
variable "metric" {
5978
type = string
6079
default = "MemoryPercentage"
6180
}
81+
6282
variable "capacity_min" {
6383
type = string
6484
default = "1"

infrastructure/modules/lets-encrypt-certificate/data.tf renamed to infrastructure/modules/lets-encrypt-certificates/data.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
data "azurerm_dns_zone" "lookup" {
2-
name = var.dns_zone_name
2+
for_each = var.dns_zone_names
3+
4+
name = each.value
35
resource_group_name = var.dns_zone_resource_group_name
46
}
57

infrastructure/modules/lets-encrypt-certificate/main.tf renamed to infrastructure/modules/lets-encrypt-certificates/main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ resource "local_file" "certbot_ini_file" {
55
content = <<EOT
66
dns_azure_use_cli_credentials = true
77
dns_azure_environment = "AzurePublicCloud"
8-
dns_azure_zone1 = ${var.dns_zone_name}:${data.azurerm_dns_zone.lookup.id}
8+
%{for name, zone in var.dns_zone_names~}
9+
dns_azure_zone${index(keys(var.dns_zone_names), name) + 1} = ${zone}:${data.azurerm_dns_zone.lookup[name].id}
10+
%{endfor~}
911
EOT
1012
}
1113

infrastructure/modules/lets-encrypt-certificate/output.tf renamed to infrastructure/modules/lets-encrypt-certificates/output.tf

File renamed without changes.

infrastructure/modules/lets-encrypt-certificate/scripts/certbot.sh renamed to infrastructure/modules/lets-encrypt-certificates/scripts/certbot.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ if [[ ${#kv_names[@]} -eq 0 || -z "${email}" || -z "${subscription_id_target}" |
7474
fi
7575

7676
# Temporary until version 4 is actually working with library josepy 2.0.0
77-
pip3 install 'certbot==2.11.1' certbot-dns-azure
77+
pip3 install 'certbot==3.3.0' certbot-dns-azure
7878
#pip3 install certbot certbot-dns-azure
7979

8080
mkdir -p .terraform/certbot
@@ -84,7 +84,7 @@ echo "Attempting retrieval of stored certificate creation state..."
8484
az account set --subscription "${subscription_id_hub}"
8585
az storage blob download --account-name "${storage_account_name}" --container-name "${container_name}" --name "${environment}.zip" --file "./certbot_state.zip" --auth-mode login || true # continue on failure
8686
if [[ -e ./certbot_state.zip ]]; then
87-
unzip -o ./certbot_state.zip
87+
unzip -oq ./certbot_state.zip
8888
rm ./certbot_state.zip
8989
# reset canonical paths in renewal conf files to match the local environment
9090
sed -i "s#agent_workdir#${agent_workdir}#g" certbot/config/renewal/*.conf
@@ -136,7 +136,7 @@ done
136136
echo "Persisting certificate creation state to Azure Storage Account..."
137137
# reset canonical paths in renewal conf files to something predictable
138138
sed -i "s#${agent_workdir}#agent_workdir#g" certbot/config/renewal/*.conf
139-
zip -ry certbot_state.zip certbot/config certbot/logs
139+
zip -ryq certbot_state.zip certbot/config certbot/logs
140140
az account set --subscription "${subscription_id_hub}"
141141
az storage blob upload --account-name "${storage_account_name}" --container-name "${container_name}" --file "./certbot_state.zip" --name "${environment}.zip" --overwrite --auth-mode login
142142

infrastructure/modules/lets-encrypt-certificate/variables.tf renamed to infrastructure/modules/lets-encrypt-certificates/variables.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ variable "certificates" {
33
type = map(string)
44
}
55

6-
variable "dns_zone_name" {
7-
type = string
6+
variable "dns_zone_names" {
7+
type = map(string)
8+
description = "Map of zone identifiers to their full private DNS zone names"
89
}
910

1011
variable "dns_zone_resource_group_name" {

0 commit comments

Comments
 (0)