GoogleCloudPlatform / terraform-google-nat-gateway

Modular NAT Gateway on Google Compute Engine for Terraform.
Apache License 2.0
156 stars 133 forks source link

NAT Gateway not creating #19

Open Ruwan-Ranganath opened 6 years ago

Ruwan-Ranganath commented 6 years ago

Using terraform to create nat-gateway using this module. https://registry.terraform.io/modules/GoogleCloudPlatform/nat-gateway/google/1.1.3

using this code :

module "nat" {
        source                  = "GoogleCloudPlatform/nat-gateway/google"
        region                  = "${var.gcloud-region}"
        network                 = "${google_compute_network.vpc-network.name}"
        subnetwork              = "${google_compute_subnetwork.vpc-subnetwork-public.name}"
        machine_type    = "${var.vm-type-nat-gateway}"
}

Other snippets :

variable "gcloud-region"                        { default = "europe-west1" }
variable "vm-type-nat-gateway"                  { default = "n1-standard-2"}

resource "google_compute_network" "vpc-network" {
    name                        = "foobar-vpc-network"
    auto_create_subnetworks     = false
}

resource "google_compute_subnetwork" "vpc-subnetwork-public" {
    name                        = "foobar-vpc-subnetwork-public"
    ip_cidr_range               = "10.0.1.0/24"
    network                     = "${google_compute_network.vpc-network.self_link}"
    region                      = "${var.gcloud-region}"
    private_ip_google_access    = false
}

================

  • module.nat.google_compute_route.nat-gateway: 1 error(s) occurred:

  • module.nat.google_compute_route.nat-gateway: element: element() may not be used with an empty list in:

${element(split("/", element(module.nat-gateway.instances[0], 0)), 10)}


Above errror coming up and whole terraform script get stop , and unable to run

terraform apply or terraform destroy at any changes,

any possible issue causing this ?

Ruwan-Ranganath commented 6 years ago

Hi, Assume I don't want to have any code level change in my terraform script ? and just doing terraform init will work ?

I managed to run this once but again receiving same kind of error .

* module.nat.google_compute_route.nat-gateway: element: element() may not be used with an empty list in:

${element(split("/", element(module.nat-gateway.instances[0], 0)), 10)}
* module.nat.output.instance: element: element() may not be used with an empty list in:

${element(module.nat-gateway.instances[0], 0)}
sysC0D commented 6 years ago

Hi, I had the same problem. To solve that, just change the name of your module. Your module name must be different of the name "nat-gateway" already use inside module terraform-google-nat-gateway.

mafrosis commented 6 years ago

After an error on the first run, the module now does not work with the above error

* module.nat.google_compute_route.nat-gateway: element: element() may not be used with an empty list in:

${element(split("/", element(module.nat-gateway.instances[0], 0)), 10)}
danisla commented 6 years ago

@mafrosis, can you post a snippet of your code and your terraform and provider versions?

mafrosis commented 6 years ago

Terraform version 11.7, and provider version 1.16. Nothing special happening with our use of the module - the code is as you would expect:

resource "google_compute_subnetwork" "nat_subnet" {
  name          = "nat-subnet"
  ip_cidr_range = "10.255.255.0/24"
  project       = "${google_project.host_project.project_id}"
  region        = "${var.region}"
  network       = "${google_compute_network.shared_network.self_link}"
}

module "nat" {
  source     = "GoogleCloudPlatform/nat-gateway/google"
  region      = "${var.region}"
  network     = "${var.project_id}-vpc"
  subnetwork  = "${google_compute_subnetwork.nat_subnet.name}"
  project     = "${google_project.host_project.project_id}"
}

AFAICT the issue stemmed from a timeout when the MIG was creating, which left the terraform in an unrecoverable state with the error I pasted above.

I recovered with some manual intervention and judicious application of terraform state rm.

rvaidya commented 5 years ago

Also experiencing this issue, the MIG is taking a long time to create. Terraform times out, and then every operation after that hangs. If I delete the instance (but not the MIG) I get that error.

rvaidya commented 5 years ago

The causing issue for this for me was that I was not specifying subnetwork when I needed to - it seems like stuff like this causes this terraform module to go into an unrecoverable state.