Skip to content
This repository was archived by the owner on Dec 10, 2021. It is now read-only.
This repository was archived by the owner on Dec 10, 2021. It is now read-only.

How to resolve dependency on newly created custom (sub)network? #90

@petervandenabeele

Description

@petervandenabeele

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.

 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}"
+  network         = "${google_compute_network.network.self_link}"
+  subnetwork      = "${google_compute_subnetwork.subnetwork.self_link}"
   dest_range      = "${var.dest_range}"
   ip_address_name = "${var.ip_address_name}"
   name            = "${var.name}"
  1. First I tried with network = "${var.network}" and same for subnetwork, but this fails with:
* module.nat.google_compute_firewall.nat-gateway: 1 error(s) occurred:

* google_compute_firewall.nat-gateway: Error creating Firewall: googleapi: Error 404: The resource 'projects/<hidden>-edge/global/networks/network-v2' was not found, notFound
* module.nat.module.nat-gateway.google_compute_instance_template.default: 1 error(s) occurred:

* google_compute_instance_template.default: Error creating instance template: googleapi: Error 404: The resource 'projects/<hidden>-edge/regions/europe-west1/subnetworks/subnetwork-v2-a' was not found, notFound
* module.nat.module.nat-gateway.google_compute_firewall.default-ssh: 1 error(s) occurred:

* google_compute_firewall.default-ssh: Error creating Firewall: googleapi: Error 404: The resource 'projects/<hidden>-edge/global/networks/network-v2' was not found, notFound

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 ?).

  1. Then I tried to use the self_link to force this dependency on the existence of the (sub)network, before starting to create the nat resources. This worked better, but failed on this error where a value with dns compatible regex is required (and not a self_link).
1 error(s) occurred:

* module.nat.data.google_compute_network.network: data.google_compute_network.network: Error reading Network Not Found : https://www.googleapis.com/compute/v1/projects/<hidden>-edge/global/networks/network-v2: googleapi: Error 400: Invalid value 'https://www.googleapis.com/compute/v1/projects/<hidden>-edge/global/networks/network-v2'. Values must match the following regular expression: '[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?', invalidParameter

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 :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions