terraform-google-modules/terraform-google-address

cross project error

Lynty opened this issue · 1 comments

Lynty commented

Summary

I'm using a shared VPC where the network project is the host and contains the VPC and subnets. I'm trying to create reserved IP's in the service projects but are in a subnet of the host network project. I typically receive a cross project error about 50% of the times I run terraform apply and it can be resolved by rerunning the apply. Rerunning the apply twice on an error that doesn't always occur is not ideal for automation or consistency and I would love to get this resolved.

Code

module "reserved_public_ips" {
  source = "terraform-google-modules/address/google"
  for_each = {
    for ip in local.regional_ips : "${ip.index}.${ip.region}.${ip.letter}" => ip
  }
  version = "2.1.0"

  subnetwork = module.network_public.subnets["${each.value.region}/${each.value.subnet_prefix}-public-subnet"].id
  project_id = each.value.type == "admin" ? local.admin_project_id : local.project_id
  region     = each.value.region
  addresses  = [cidrhost(lookup(module.network_public.subnets, "${each.value.region}/${each.value.subnet_prefix}-public-subnet").ip_cidr_range, (((each.value.index - 1) % local.num_ips_to_reserve) + 5))]

  names = [
    "dns-reserve-pub-${each.value.index}-${each.value.letter}-${each.value.iata}-g-${local.pretty_network_project_id}"
  ]
}
# here's a snippet of local.regional_ips
[  
  {
    "iata" = "sin"
    "index" = 15
    "letter" = "c"
    "region" = "asia-southeast1"
    "subnet_prefix" = "network-scratch-asia-southeast1-atomc"
    "type" = "regular"
  },
  {
    "iata" = "sin"
    "index" = 15
    "letter" = "d"
    "region" = "asia-southeast1"
    "subnet_prefix" = "network-scratch-asia-southeast1-atomd-admin"
    "type" = "admin"
  },
]

Error

* Error: Error creating Address: googleapi: Error 400: Invalid value for field 'resource.subnetwork': 'projects/network-scratch-f2ac/regions/asia-southeast1/subnetworks/network-scratch-asia-southeast1-atomd-admin-public-subnet'. Cross-project references for this resource are not allowed., invalid

(there's an error for each address that is trying to be created)

Seems like this was resolved with updates to the provider. Closing it now but please reopen if this persists.