From c5bc59e6b66b45a457d55c39cf7a9ef536354977 Mon Sep 17 00:00:00 2001 From: Yuping Wei <56525716+yupwei68@users.noreply.github.com> Date: Mon, 28 Sep 2020 17:18:33 +0800 Subject: [PATCH] update (#36) --- README.md | 6 +++--- main.tf | 16 +++++++--------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f653901..a75ffe1 100644 --- a/README.md +++ b/README.md @@ -101,8 +101,8 @@ module "vnet" { resource "azurerm_network_security_group" "ssh" { name = "ssh" - location = "westus" - resource_group_name = "${var.resource_group_name}" + resource_group_name = azurerm_resource_group.example.name + location = azurerm_resource_group.example.location security_rule { name = "test123" @@ -152,9 +152,9 @@ module "vnet" { } resource "azurerm_route_table" "example" { - location = azurerm_resource_group.example.location name = "MyRouteTable" resource_group_name = azurerm_resource_group.example.name + location = azurerm_resource_group.example.location } resource "azurerm_route" "example" { diff --git a/main.tf b/main.tf index f1fdec6..de83d0d 100644 --- a/main.tf +++ b/main.tf @@ -21,23 +21,21 @@ resource "azurerm_subnet" "subnet" { service_endpoints = lookup(var.subnet_service_endpoints, var.subnet_names[count.index], null) } -data "azurerm_subnet" "import" { - for_each = var.nsg_ids - name = each.key - resource_group_name = data.azurerm_resource_group.vnet.name - virtual_network_name = azurerm_virtual_network.vnet.name - - depends_on = [azurerm_subnet.subnet] +locals { + azurerm_subnets = { + for index, subnet in azurerm_subnet.subnet : + subnet.name => subnet.id + } } resource "azurerm_subnet_network_security_group_association" "vnet" { for_each = var.nsg_ids - subnet_id = data.azurerm_subnet.import[each.key].id + subnet_id = local.azurerm_subnets[each.key] network_security_group_id = each.value } resource "azurerm_subnet_route_table_association" "vnet" { for_each = var.route_tables_ids route_table_id = each.value - subnet_id = data.azurerm_subnet.import[each.key].id + subnet_id = local.azurerm_subnets[each.key] } \ No newline at end of file