Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nat gateway doesn't get created even when its set to true #47

Closed
johnjackson17 opened this issue May 8, 2017 · 6 comments
Closed

Nat gateway doesn't get created even when its set to true #47

johnjackson17 opened this issue May 8, 2017 · 6 comments

Comments

@johnjackson17
Copy link

johnjackson17 commented May 8, 2017

I entered all the values in variables.tf file and set nat gateway to true and still doesn't get created when i run terraform apply, everything else gets created. No failures or error messages

@antonbabenko
Copy link
Member

Could you please make a gist with content of your variables.tf and I will give it a try. I am not using this module myself, so can't judge if something has been broken lately. Thanks!

@NeckBeardPrince
Copy link

NeckBeardPrince commented May 10, 2017

+1

Same thing

resource "aws_nat_gateway" "natgw" {
  allocation_id = "${element(aws_eip.nateip.*.id, count.index)}"
  subnet_id     = "${element(aws_subnet.public.*.id, count.index)}"
  count         = "${length(var.private_subnets) * lookup(map(var.enable_nat_gateway, 1), "true", 1)}"

  depends_on = ["aws_internet_gateway.default"]
}

If I set "true", 1 instead of 0 it works
Every option that has "true", 0 needs to be 1 and then it will create the NAT GW

@ashb
Copy link

ashb commented May 17, 2017

Ah okay, I found out the problem.

Its a difference between true and "true". I (and I guess @NeckBeardPrince and @johnjackson17 ) put this:

module "vpc" {
  source = "github.com/terraform-community-modules/tf_aws_vpc?ref=v1.0.4"
  enable_dns_hostnames = true
  enable_dns_support = false
  enable_nat_gateway = true
  ...
}

However the problem is that enable_nat_gateway needs to be a string.

This example works for instance:

module "vpc" {
  source = "github.com/terraform-community-modules/tf_aws_vpc?ref=v1.0.4"
  enable_dns_hostnames = true
  enable_dns_support = false
  enable_nat_gateway = "true"
  ...
}

I will see if there's a way around this in terraform.

@ashb
Copy link

ashb commented May 17, 2017

It looks like using conditionals which are new in TF v0.8 we can get it to work both ways. @antonbabenko What is the support policy for this repo? (I think the conditional version is more understandable, but if we want to support older than 0.8 it's not an option)

Given this mian.tf:

variable "enable_nat_gateway_string" {
  default = "true"
}
variable "enable_nat_gateway_bool" {
  default = true
}
variable "enable_nat_gateway_empty_string" {
  default = ""
}
> "${var.enable_nat_gateway_empty_string != "" ? 1 : 0}"
0
> "${var.enable_nat_gateway_bool != "" ? 1 : 0}"
1
> "${var.enable_nat_gateway_string != "" ? 1 : 0}"
1

(We need the != "" because otherwise we get this error:

> "${var.enable_nat_gateway_empty_string ? 1 : 0}"
__builtin_StringToBool: strconv.ParseBool: parsing "": invalid syntax in:

${"${var.enable_nat_gateway_empty_string ? 1 : 0}"}

@ashb
Copy link

ashb commented May 17, 2017

(The 0.7 compat way of fixing this is to change it from:

lookup(map(var.enable_nat_gateway, 1), "true", 0)

to

lookup(map("true", 1, "1", 1), "${var.enable_nat_gateway}", 0)

which looks more correct to me anywayx = {"$enable" : 1 } seems odd, x = {"true": 1} )

n8io added a commit to n8io/tf_aws_vpc that referenced this issue Jul 23, 2017
n8io added a commit to n8io/tf_aws_vpc that referenced this issue Jul 23, 2017
🐛 terraform-community-modules#47  Fix issue with string vs bool value with enable_nat_gateway input
n8io added a commit to n8io/tf_aws_vpc that referenced this issue Jul 30, 2017
@n8io
Copy link
Contributor

n8io commented Aug 1, 2017

@antonbabenko I believe this issue can be closed now.

antonbabenko pushed a commit that referenced this issue Aug 2, 2017
* 🐛 #47  Fix issue with string vs bool value with enable_nat_gateway input

* ✨ #42 Add support for provisioning only a single NAT Gateway
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants