-
Notifications
You must be signed in to change notification settings - Fork 0
[TC-5] Add module for private dns zone with vnet links #15
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
base: main
Are you sure you want to change the base?
Changes from all commits
273257b
4afb629
ede7387
692b9aa
3b7622d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| private_dns_zones = { | ||
| storage_account_blob = { | ||
| resource_kind = "storage_blob" | ||
| resource_group_ref = "rg_test" | ||
| vnet_ref = ["vnet_test", "vnet_test2"] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename to |
||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| # pre-requisites | ||
| resource_groups = { | ||
| rg_test = { | ||
| name = "rg-test-dv-ne-01" | ||
| location = "northeurope" | ||
| } | ||
| } | ||
|
|
||
| virtual_networks = { | ||
| vnet_test = { | ||
| name = "vnet-test-dv-ne-01" | ||
| resource_group_ref = "rg_test" | ||
| cidr = ["10.0.0.0/16"] | ||
| subnets = { | ||
| snet_app = { | ||
| name = "snet-app" | ||
| cidr = ["10.0.0.128/25"] | ||
| service_endpoints = ["Microsoft.Storage"] | ||
| } | ||
| } | ||
| } | ||
| vnet_test2 = { | ||
| name = "vnet-test-dv-ne-02" | ||
| resource_group_ref = "rg_test" | ||
| cidr = ["10.1.0.0/16"] | ||
| subnets = { | ||
| snet_app_02 = { | ||
| name = "snet-app" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This example will not work if the subnets are named the same :) |
||
| cidr = ["10.1.0.128/25"] | ||
| service_endpoints = ["Microsoft.Storage"] | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| locals { | ||
| resource_group = var.resources.resource_groups[var.settings.resource_group_ref] | ||
|
|
||
| resource_group_name = local.resource_group.name | ||
| location = local.resource_group.location | ||
| tags = merge( | ||
| var.global_settings.tags, | ||
| var.global_settings.inherit_resource_group_tags ? local.resource_group.tags : {}, | ||
| try(var.settings.tags, {}) | ||
| ) | ||
| vnet_ids = { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This object is called |
||
| for vnet in var.settings.vnet_ref : | ||
| vnet => { | ||
| name = var.resources.virtual_networks[vnet].name | ||
| id = var.resources.virtual_networks[vnet].id | ||
| } | ||
| } | ||
| } | ||
| locals { | ||
| # local object used to map possible private dns zoone names | ||
| zone_names = { | ||
| "storage_blob" = "privatelink.blob.core.windows.net" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| "storage_tables" = "privatelink.table.core.windows.net" | ||
| "storage_queues" = "privatelink.queue.core.windows.net" | ||
| "storage_files" = "privatelink.file.core.windows.net" | ||
| "function_apps" = "privatelink.azurewebsites.net" | ||
| "keyvaults" = "privatelink.vaultcore.azure.net" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| output "id" { | ||
| value = azurerm_private_dns_zone.main.id | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| variable "global_settings" { | ||
| description = "Global settings for tinycaf" | ||
| } | ||
|
|
||
| variable "settings" { | ||
| description = "All the configuration for this resource" | ||
| } | ||
|
|
||
| variable "resources" { | ||
| type = object({ | ||
| resource_groups = map(any) | ||
| virtual_networks = map(any) | ||
| }) | ||
| description = "All required resources" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| resource "azurerm_private_dns_zone_virtual_network_link" "main" { | ||
| for_each = local.vnet_ids | ||
| name = "${each.value.name}-${azurerm_private_dns_zone.main.name}-link" | ||
| private_dns_zone_name = azurerm_private_dns_zone.main.name | ||
| resource_group_name = azurerm_private_dns_zone.main.resource_group_name | ||
| virtual_network_id = each.value.id | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| resource "azurerm_private_dns_zone" "main" { | ||
| name = try(local.zone_names[var.settings.resource_kind], var.settings.name) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Experience shows that the name field is not used in practice. I recommend relying completely on the local object instead. We'll modify the module to be able to override the name, once such a case emerges. |
||
| resource_group_name = local.resource_group_name | ||
| tags = try(local.tags, null) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will never fail. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,3 +59,15 @@ module "local_network_gateways" { | |
| resource_groups = module.resource_groups | ||
| } | ||
| } | ||
|
|
||
| module "private_dns_zones" { | ||
| source = "./modules/_networking/private_dns_zone" | ||
| for_each = var.private_dns_zones | ||
|
|
||
| global_settings = var.global_settings | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this must be |
||
| settings = each.value | ||
| resources = { | ||
| resource_groups = module.resource_groups | ||
| virtual_networks = module.virtual_networks | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to
pdns_storage_account_blob