Skip to content
This repository has been archived by the owner on Mar 29, 2023. It is now read-only.

Why are we adding public subnet to the Router NAT #52

Closed
syedrakib opened this issue Mar 28, 2020 · 12 comments · Fixed by #53
Closed

Why are we adding public subnet to the Router NAT #52

syedrakib opened this issue Mar 28, 2020 · 12 comments · Fixed by #53

Comments

@syedrakib
Copy link

syedrakib commented Mar 28, 2020

We use NAT for the private instances to reach out to the internet.

Referring to Lines68-74, the comment says "Manually define the subnetworks ... exclude the public subnetwork".

However, in the subnetwork block it is then selecting vpc_subnetwork_public. Shouldn't it be selecting the vpc_subnetwork_private instead so that we can allow the private subnet to use the NAT?

@itsmunim
Copy link

itsmunim commented Mar 29, 2020

@syedrakib this is what I think-

  1. The NAT is there for you to be able to connect to your VPC from any services you might have on premise or any public IP you expose from your public subnet. The NAT defined here is to limit the range of public IPs can be allocated from your VPC. Cause as per design, the public subnet and private subnet both are anyhow just subnets, to differentiate public subnet as public and limit the public IP ranges to be allocated only from that subnet, the NAT has been used.

  2. That's a typo. It will actually be private subnetwork not public around those lines.

@syedrakib
Copy link
Author

syedrakib commented Mar 29, 2020

The google_compute_router_nat resource in Terraform creates a CloudNAT on GCP. CloudNATs are used for outbound connection from VPC to the world - not for inbound - irrespective of there are on-premise machines or not. CloudNATs are meant to allow a VPC's VM instances without ExternalIPs (which would usually reside in the private subnet of the VPC) to communicate with the public internet to download software/os updates & patches.

@syedrakib
Copy link
Author

syedrakib commented Mar 29, 2020

You are right that there is a typo here between the comment and the code. After playing around with the TF resource and observing its changes in GCP, i realised that the typo is actually in the code and not in the comment.

The value for subnetwork:name should be vpc_subnetwork_private.self_link (instead of vpc_subnetwork_public.self_link) as private subnets would generally have instances without ExternalIPs and those are the ones that we want to be able to fetch updates from the internet through the CloudNAT.

I was still hoping there could be a confirmation from the author of this file that the typo is in the code or in the comment. Because, for a newcomer the comment/code is misleading.

@itsmunim
Copy link

The google_compute_router_nat resource in Terraform creates a CloudNAT on GCP. CloudNATs are used for outbound connection from VPC to the world - not for inbound - irrespective of there are on-premise machines or not. CloudNATs are meant to allow a VPC's VM instances without ExternalIPs (which would usually reside in the private subnet of the VPC) to communicate with the public internet to download software/os updates & patches.

  • You are right. Just checked. Was referring the normal definition of NATs. In that case, it will only make sense if they add private subnet while creating the NAT.

@Bluesboy
Copy link

I applied this configuration with private instead of public and my nodes can't connect to internet anymore.

@robmorgan
Copy link
Contributor

@onsails
Copy link

onsails commented Jul 21, 2020

Same for me. I am using v0.4.0.

module "gke-cluster" {
  ...
  subnetwork = module.vpc_network.public_subnetwork 
  enable_private_nodes = "true"
}

@snyman
Copy link

snyman commented Aug 4, 2020

I believe the change made in PR #53 was an error. The documentation states:

A VPC network defines two subnetworks instances can reside in;

  • public - instances are able to communicate over the public internet through Cloud NAT if an external IP was not provided
  • private - instances are exclusively able to communicate within your network or with private Google services if an external IP was not provided

This means that the NAT should be on for the public subnet, and not for the private subnet, as it was originally.

@robmorgan
Copy link
Contributor

After re-reading this issue and the docs I'm also under the impression that the changes in #53 were incorrect and I'm going to revert them in the next release.

@Jojoooo1
Copy link

Jojoooo1 commented Nov 3, 2020

Any news on that ?

robmorgan added a commit that referenced this issue Nov 12, 2020
@robmorgan
Copy link
Contributor

I've reverted the change. Its pending approval in #57

robmorgan added a commit that referenced this issue Nov 16, 2020
@robmorgan
Copy link
Contributor

Released in https://github.com/gruntwork-io/terraform-google-network/releases/tag/v0.5.0

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

Successfully merging a pull request may close this issue.

7 participants