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

NAT Gateway not creating #19

Open
Ruwan-Ranganath opened this issue Mar 19, 2018 · 7 comments
Open

NAT Gateway not creating #19

Ruwan-Ranganath opened this issue Mar 19, 2018 · 7 comments

Comments

@Ruwan-Ranganath
Copy link

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 ?

sgirones added a commit to sgirones/terraform-google-nat-gateway that referenced this issue Mar 19, 2018
@Ruwan-Ranganath
Copy link
Author

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
Copy link
Contributor

sysC0D commented Aug 9, 2018

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
Copy link

mafrosis commented Aug 30, 2018

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
Copy link
Contributor

danisla commented Aug 31, 2018

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

@mafrosis
Copy link

mafrosis commented Sep 1, 2018

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
Copy link

rvaidya commented Jan 15, 2019

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
Copy link

rvaidya commented Jan 23, 2019

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants