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

feat: Added custom route for NAT gateway #748

Conversation

piersf
Copy link
Contributor

@piersf piersf commented Feb 7, 2022

Description

When having a VPC with public and private subnets, there are cases where traffic from the private subnet that is destined for 0.0.0.0/0 does not need to go to the NAT Gateway but instead, it should be sent to another destination (e.g., transit gateway). And then only specific traffic that is destined for the internet (e.g., 8.8.8.8/32) should be sent to the NAT Gateway.

Therefore, this change adds a new conditional variable that enables us to pass a custom destination CIDR block for the NAT Gateway.

Motivation and Context

When having a VPC with public and private subnets, there are cases where traffic from the private subnet that is destined for 0.0.0.0/0 does not need to go to the NAT Gateway but instead, it should be sent to another destination (e.g., transit gateway). And then only specific traffic that is destined for the internet (e.g., 8.8.8.8/32) should be sent to the NAT Gateway.

Breaking Changes

No breaking changes were noticed.

How Has This Been Tested?

  • I have tested and validated these changes using one or more of the provided examples/* projects

@piersf piersf changed the title Feat: private NAT gateway custom route feat: private NAT gateway custom route Feb 7, 2022
@piersf piersf changed the title feat: private NAT gateway custom route feat: Added custom route private NAT gateway Feb 7, 2022
@piersf piersf changed the title feat: Added custom route private NAT gateway feat: Added custom route for private NAT gateway Feb 7, 2022
@piersf
Copy link
Contributor Author

piersf commented Feb 7, 2022

@antonbabenko is it possible to prioritize the review of this PR? Should be a simple change to review.

variables.tf Outdated
variable "private_nat_gateway_destination_route" {
description = "Used to pass a custom destination route for private NAT Gateway. If not specified, the default 0.0.0.0/0 is used as a destination route."
type = string
default = null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haven't looked in depth, but wouldn't it make more sense to just set the default here as 0.0.0.0/0 and then on line 1046 its just destination_cidr_block = var.private_nat_gateway_destination_cidr_block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely, yes. I just took a conditional approach. Will change that now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected. If that works for you, I can resolve this conversation.

variables.tf Outdated
@@ -298,6 +298,12 @@ variable "enable_nat_gateway" {
default = false
}

variable "private_nat_gateway_destination_route" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
variable "private_nat_gateway_destination_route" {
variable "nat_gateway_destination_cidr_block" {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now fixed.

@antonbabenko
Copy link
Member

@piersf Please fix the docs (run pre-commit run -a and commit changes) and I will merge it.

@piersf
Copy link
Contributor Author

piersf commented Feb 7, 2022

@piersf Please fix the docs (run pre-commit run -a and commit changes) and I will merge it.

@antonbabenko silly question but how do I run pre-commit run -a? That gives me a command not found on my machine as obviously, I don't have such a package/tool installed.

@antonbabenko
Copy link
Member

You need to install it - https://pre-commit.com/#installation and terraform-docs (see github workflow config for more).

Just let me know if you want me to fix this and release it.

@piersf
Copy link
Contributor Author

piersf commented Feb 7, 2022

Just let me know if you want me to fix this and release it.

If you can, I'd really appreciate it. I don't have many of these prerequisites installed like terraform-docs and tflint and will take me some time to install them due to policies on the machine.

@antonbabenko antonbabenko changed the title feat: Added custom route for private NAT gateway feat: Added custom route for NAT gateway Feb 7, 2022
@antonbabenko antonbabenko merged commit 728a4d1 into terraform-aws-modules:master Feb 7, 2022
antonbabenko pushed a commit that referenced this pull request Feb 7, 2022
## [3.12.0](v3.11.5...v3.12.0) (2022-02-07)

### Features

* Added custom route for NAT gateway ([#748](#748)) ([728a4d1](728a4d1))
@antonbabenko
Copy link
Member

This PR is included in version 3.12.0 🎉

@antonbabenko
Copy link
Member

No problems, I've just fixed it. Thank you for your contribution!

harrythebot pushed a commit to lolocompany/terraform-aws-vpc that referenced this pull request May 11, 2022
harrythebot pushed a commit to lolocompany/terraform-aws-vpc that referenced this pull request May 11, 2022
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 28, 2022
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 this pull request may close these issues.

None yet

3 participants