Open petervandenabeele opened 6 years ago
OK, so this work-around does the trick. Maybe this issue is irrelevant then, or should we look for a cleaner solution when the network and/or subnetwork are created in the same terraform apply
run as the nat gateway that depends on them?
The reason I am doing this is to have our edge
GKE cluster and the egress NAT to our legacy servers (with fixed IP) re-created in full, whenever we want and e.g. every morning.
module "nat" {
source = "github.com/GoogleCloudPlatform/terraform-google-nat-gateway"
region = "${var.region}"
zone = "${var.zone}"
tags = ["${var.gke_node_tag}"]
- network = "${var.network}"
- subnetwork = "${var.subnetwork}"
+ // dependencies on self_link as a work-around for https://github.com/GoogleCloudPlatform/terraform-google-nat-gateway/issues/90
+ network = "${true ? var.network : google_compute_network.network.self_link}"
+ subnetwork = "${true ? var.subnetwork : google_compute_subnetwork.subnetwork.self_link}"
dest_range = "${var.dest_range}"
ip_address_name = "${var.ip_address_name}"
name = "${var.name}"
I'm encountering the same issue and have posted my logs here for reference: https://gist.github.com/sabrehagen/74a964e17834c5c87a27125a4069be33
I commented on your gist with a proposed test to validate the presumption that this is the cause.
I tried your fix and can confirm it works. I believe the dependency tree was lost when referencing "${local.environment_name}"
rather than "${google_compute_network.ci-host.self_link}"
. Thank you for your assistance.
Great :-)
Yes, one should be able to just point to a self_link
(instead of a name with regex '[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?'
) to keep a clean reference of that dependency when specifying the network of a google_compute_instance.
I am creating a nat, based on the
gke-nat-gateway
example, in my own terraform templates. The core code is below. I am (re-)creating the network and subnetwork in the same set of terraform templates and I think I see a race condition.network = "${var.network}"
and same for subnetwork, but this fails with:I presume that is because some nat.module resources want to be created before the network and subnetwork are fully created (using the
name
does not create a terraform dependency on the existance of the (sub)network ?).I presume I can fix this with forcing hard dependencies on the pre-existence of the network and subnetwork in some other way?
Is there a proper fix for this case ? Thanks :-)