Azure / Azure/terraform

module data source is not found when running a terraform refresh on a code that is calling a module!

Open
#138 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
HCL
Stars
925
Forks
930
Avg merge
4d 15h
Merged PRs (30d)
5

Description

Please open this issue in Terraform repo

_Originally posted by @yonzhan in https://github.com/Azure/azure-cli/issues/25271#issuecomment-1407819248_

Hello Team, Basically I have run the code given below through the Azure DevOps pipeline already. Got few existing resources so want to import the state file locally . However when I am running the terraform refresh, I get the below error ;

" Error: Route Table: (Name "platform-rt-uks-legacy-prd-zscl" / Resource Group "platform-rg-uks-legacy-prd") was not found

│ with module.landing_zone.data.azurerm_route_table.zscl["uks"],
│ on ..\module-tf-landing_zone\networking.tf line 43, in data "azurerm_route_table" "zscl":
│ 43: data "azurerm_route_table" "zscl" {
"
Although the above route exists in the portal.

Here is my code below:

resource "azurerm_route_table" "rt" {
for_each = var.Location

name = replace(replace(replace(local.roleCount, "type", "rt"), "role", "lz"), "count", "0${1 + index(keys(var.Location), each.key)}")
location = azurerm_resource_group.rg[each.key].location
resource_group_name = azurerm_resource_group.rg[each.key].name
disable_bgp_route_propagation = false
tags = local.tags
lifecycle {
ignore_changes = [
tags["FirstCreated"]
]
}
}
resource "azurerm_route" "routes" {
for_each = local.rt_routes

name = each.value.rt_key
resource_group_name = azurerm_resource_group.rg[each.value.loc_key].name
route_table_name = azurerm_route_table.rt[each.value.loc_key].name
address_prefix = each.value.prefix
next_hop_type = each.value.hop_type
next_hop_in_ip_address = each.value.region == "UK South" ? local.firewalls.uksouth : local.firewalls.ukwest
}

data "azurerm_route_table" "zscl" {
provider = azurerm.prd-hub

for_each = local.zscl-rt-table

name = each.value.name
resource_group_name = each.value.rg
}
resource "azurerm_route" "zscl-routes" {
provider = azurerm.prd-hub

for_each = local.zscl-routes

name = each.value.loc_key == "Primary" ? replace(local.baseName, "type", "RouteTo") : replace(local.baseNameSecondary, "type", "RouteTo")
resource_group_name = data.azurerm_route_table.zscl[each.value.zscl_key].resource_group_name
route_table_name = data.azurerm_route_table.zscl[each.value.zscl_key].name
address_prefix = each.value.address_space[0]
next_hop_type = "VirtualAppliance"
next_hop_in_ip_address = each.value.zscl_key == "ukw" ? local.firewalls.ukwest : local.firewalls.uksouth
}

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the Terraform refresh with the supplied module configuration and inspect module-tf-landing_zone/networking.tf at line 43, including the azurerm.prd-hub provider and route-table data source. Compare the lookup inputs with the existing Azure resource. Done means identifying why the existing route table is not found and documenting or fixing the relevant behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, terraform
Domain
cloud, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.