Skip to content

Commit

Permalink
fix: fixed private endoint dns issue
Browse files Browse the repository at this point in the history
  • Loading branch information
13archit committed Jun 8, 2023
1 parent 6b7bf4d commit 898d2f8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 39 deletions.
45 changes: 6 additions & 39 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,16 @@ resource "azurerm_container_registry_webhook" "main" {
##-----------------------------------------------------------------------------
resource "azurerm_private_endpoint" "pep1" {
count = var.enable && var.enable_private_endpoint ? 1 : 0
name = format("%s-pe-acr", module.labels.id)
name = format("%s-%s-pe-acr", var.container_registry_config.name, module.labels.id)
location = var.location
resource_group_name = var.resource_group_name
subnet_id = join("", var.subnet_id)
private_dns_zone_group {
name = format("%s-%s-acr", var.container_registry_config.name, "dns-zone-group")
private_dns_zone_ids = var.existing_private_dns_zone == null ? [azurerm_private_dns_zone.dnszone1[0].id] : var.existing_private_dns_zone_id
}
private_service_connection {
name = "containerregistryprivatelink"
name = format("%s-%s-acr", var.container_registry_config.name, "private-link")
is_manual_connection = false
private_connection_resource_id = azurerm_container_registry.main[0].id
subresource_names = ["registry"]
Expand Down Expand Up @@ -241,43 +245,6 @@ resource "azurerm_private_dns_zone_virtual_network_link" "addon_vent_link" {
tags = module.labels.tags
}

##-----------------------------------------------------------------------------
## Below resource will create a-record in private dns zone when private dns zone is in same subscription.
##-----------------------------------------------------------------------------
resource "azurerm_private_dns_a_record" "arecord-same_sub" {
count = var.enable && var.enable_private_endpoint && var.diff_sub == false ? 1 : 0
name = join("", azurerm_container_registry.main.*.name)
zone_name = local.private_dns_zone_name
resource_group_name = local.valid_rg_name
ttl = 3600
records = [data.azurerm_private_endpoint_connection.private-ip.0.private_service_connection.0.private_ip_address]
tags = module.labels.tags
lifecycle {
ignore_changes = [
tags,
]
}
}

##-----------------------------------------------------------------------------
## Below resource will create a-record in private dns zone when private dns zone is in different subscription.
##-----------------------------------------------------------------------------
resource "azurerm_private_dns_a_record" "arecord_diff-sub" {
count = var.enable && var.enable_private_endpoint && var.diff_sub == true ? 1 : 0
provider = azurerm.peer
name = join("", azurerm_container_registry.main.*.name)
zone_name = local.private_dns_zone_name
resource_group_name = local.valid_rg_name
ttl = 3600
records = [data.azurerm_private_endpoint_connection.private-ip.0.private_service_connection.0.private_ip_address]
tags = module.labels.tags
lifecycle {
ignore_changes = [
tags,
]
}
}

##-----------------------------------------------------------------------------
## Below resource will create diagnostic setting for ACR.
##-----------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,8 @@ output "container_registry_private_endpoint_fqdn" {
description = "Azure Container Registry private endpoint FQDN Addresses"
value = var.enable_private_endpoint ? flatten(azurerm_private_endpoint.pep1.0.custom_dns_configs.*.fqdn) : null
}

output "private_dns_zone_id" {
description = "ID of private dns zone. To be used when there is existing dns zone and id is to be passed in private endpoint dns configuration group."
value = tolist(azurerm_private_dns_zone.dnszone1.*.id)
}
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,10 @@ variable "same_vnet" {
type = bool
default = false
description = "Variable to be set when multiple acr having common DNS in same vnet."
}

variable "existing_private_dns_zone_id" {
type = list(any)
default = null
description = "ID of existing private dns zone. To be used in dns configuration group in private endpoint."
}

0 comments on commit 898d2f8

Please sign in to comment.