I’m deploying nginx as a reverse proxy in an Azure Container App environment.
As I’m proxy-passing dynamically, I need to explicitly set a resolver/dns ip address in the NGINX config.
I was on consumption plan until now, and had the resolver hardcoded to 10.0.0.2
, which worked fine.
I now switched to a dedicated workload profile, with which that address no longer worked. It now seems to be changing dynamically upon environment creation.
Thus, I tried to dynamically alter the config file via terraform by using the app environment’s platform_reserved_dns_ip_address. However, this value is just empty and does not pass a validation like below.
As per terraform documentation, infrastructure_subnet_id
is configured so that should not be the issue.
Is there any way to either retrieve that resolver ip or workaround differently to be able to dynamically proxy in an ACA environment using NGINX?
Some code snippets:
# terraform excerpts from different modules
resource "azurerm_container_app_environment" "main" {
name = "foo"
location = var.location
resource_group_name = var.resource_group_name
log_analytics_workspace_id = azurerm_log_analytics_workspace.main.id
infrastructure_subnet_id = azurerm_subnet.containerEnv.id
internal_load_balancer_enabled = var.ingress_vnet_only
# note I'm only having the issue in dedicated, ie not consumption plan
workload_profile {
name = local.workload_profile.name
workload_profile_type = local.workload_profile.workload_profile_type
minimum_count = local.workload_profile.minimum_count
maximum_count = local.workload_profile.maximum_count
}
}
# output app environment
output "dns_ip_address" {
value = azurerm_container_app_environment.main.platform_reserved_dns_ip_address
}
# input nginx
variable "dns_ip_address" {
description = "IP address of the DNS server"
type = string
validation {
condition = length(var.dns_ip_address) > 0
error_message = "dns_ip_address must not be empty"
}
}
# dynamic nginx config adaptation
resource "local_file" "nginx_config" {
content = templatefile("${path.module}/config/nginx-template.conf", {
dns_ip_address = var.dns_ip_address
})
filename = "${path.module}/auto-generated/nginx.conf"
}
# nginx conf excerpt
resolver ${dns_ip_address};
server {
listen 80;
server_name ~^(.*).foo.bar$;
location / {
set $upstream_url http://$dynamic_address
proxy_pass $upstream_url;
proxy_http_version 1.1;
}
}
Also the JSON view of the app environment will say the IP address is null: "platformReservedDnsIP": null
2
Answers
I have now opened an issue here and have figured out a workaround, which uses the fact that the name server will still be present in a container's
/etc/resolv.conf
. It will just replace a variable in the config before NGINX is started:Platform_reserved_dns_ip_address
property only visible wheninfrastructure_subnet_id
is configured and it will be a in a range within theCIDR
of the Subnet.Refer terraform registry attribute reference for the relevant information.
Saying that, I have deployed a container app environment with
infrastructure_subnet
enabled and also within the range of CIDR under vnet integration and was able to view the reserved dns Ip address successfully.Output block
:Deployment succeeded:
Reference Blog Thomas Thornton for the above
azapi
terraform code.After deployment, I have verified the same by using
data
block for container app environment and was also able to retrieve it as expected.