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(removes nat_ip_allocate_option)!: add dynamic port mapping #73

Merged

Conversation

nikhilmakhijani
Copy link
Contributor

@nikhilmakhijani nikhilmakhijani commented Jun 21, 2022

This MR includes the following changes:

  1. Adding dynamic port mapping functionality
  2. Remove nat_ip_allocation_option variable

@github-actions
Copy link

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions bot added the Stale label Aug 20, 2022
@nikhilmakhijani nikhilmakhijani changed the title Fix/dynamic port feat: add dynamic port mapping Aug 27, 2022
@github-actions github-actions bot removed the Stale label Aug 27, 2022
@nikhilmakhijani
Copy link
Contributor Author

Please review @bharathkkb

@@ -57,6 +55,7 @@ resource "google_compute_router_nat" "main" {
tcp_established_idle_timeout_sec = var.tcp_established_idle_timeout_sec
tcp_transitory_idle_timeout_sec = var.tcp_transitory_idle_timeout_sec
enable_endpoint_independent_mapping = var.enable_endpoint_independent_mapping
enable_dynamic_port_allocation = var.enable_dynamic_port_allocation

Choose a reason for hiding this comment

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

This could be conditional, since the previous variable should be false if this one is true.

versions.tf Show resolved Hide resolved
Copy link
Member

@bharathkkb bharathkkb left a comment

Choose a reason for hiding this comment

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

Sorry for the delay @nikhilmakhijani

versions.tf Show resolved Hide resolved
variables.tf Outdated
variable "enable_endpoint_independent_mapping" {
type = bool
description = "Specifies if endpoint independent mapping is enabled."
default = null
default = true
Copy link
Member

Choose a reason for hiding this comment

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

Any reason for changing this default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is enabled by default as per the terraform documentation so I made it true here.

Copy link

Choose a reason for hiding this comment

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

This is not enabled by default in Google Cloud, see https://cloud.google.com/nat/docs/overview#specs-rfcs

By default, Endpoint-Independent Mapping is disabled when you create a NAT gateway.

The terraform documentation should probably be updated to match GCP and this set to false as default.

Copy link
Member

Choose a reason for hiding this comment

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

@jcalero I took a peek at the provider and it seems like they actually default to true. It might be worth opening an issue there to point out this difference. @nikhilmakhijani Could we keep this a null for now so we can follow the provider default?

https://github.com/hashicorp/terraform-provider-google/blob/53295dc35039ca8cd66da18cc758bf7487bd8c03/google/resource_compute_router_nat.go#L238-L243

Copy link
Contributor Author

@nikhilmakhijani nikhilmakhijani Dec 2, 2022

Choose a reason for hiding this comment

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

Yes, I have updated it to null for now. Can we check whether it should be enabled or disabled as per best practice then update it accordingly?

Copy link

Choose a reason for hiding this comment

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

It's worth noting that Endpoint-Independent Mapping (EIM) will be disabled by default in future Terraform provider versions in order to be in sync with the Google default setting:

hashicorp/terraform-provider-google#10609

Speaking personally, I would definitely say the best practice for 99% of all deployments is to disable EIM but do enable Dynamic Port Allocation (DPA) as this will manage port allocations more efficiently and decrease the chance of Cloud NAT drops.

At a bare minimum, it should be an option to leverage DPA as the feature has been out over a year and I've yet to see any downside to using it.

Copy link

@sclausson sclausson May 11, 2023

Choose a reason for hiding this comment

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

I believe when it is set to null it still ends up where is EIM is enabled. This is why I've opened a separate PR to set the value to false #113

@nikhilmakhijani nikhilmakhijani requested a review from a team as a code owner November 29, 2022 05:09
@comment-bot-dev
Copy link

@nikhilmakhijani
Thanks for the PR! 🚀
✅ Lint checks have passed.

@github-actions
Copy link

github-actions bot commented Feb 1, 2023

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

@apeabody
Copy link
Contributor

/gcbrun

@apeabody
Copy link
Contributor

Thanks for the contribution @nikhilmakhijani! I've triggered the CI, in the meantime can all the remaining comment threads be closed?

@apeabody
Copy link
Contributor

Hi @nikhilmakhijani, relevant output from the INT cI:

    subnetworks_test.go:45: 
        	Error Trace:	/workspace/test/integration/subnetworks/subnetworks_test.go:45
        	            				/builder/home/go/pkg/mod/github.com/!google!cloud!platform/cloud-foundation-toolkit/infra/blueprint-test@v0.5.0/pkg/tft/terraform.go:412
        	            				/builder/home/go/pkg/mod/github.com/!google!cloud!platform/cloud-foundation-toolkit/infra/blueprint-test@v0.5.0/pkg/tft/terraform.go:432
        	            				/builder/home/go/pkg/mod/github.com/!google!cloud!platform/cloud-foundation-toolkit/infra/blueprint-test@v0.5.0/pkg/utils/stages.go:31
        	            				/builder/home/go/pkg/mod/github.com/!google!cloud!platform/cloud-foundation-toolkit/infra/blueprint-test@v0.5.0/pkg/tft/terraform.go:432
        	Error:      	Not equal: 
        	            	expected: map[string]interface {}{"enableEndpointIndependentMapping":true, "endpointTypes":[]interface {}{"ENDPOINT_TYPE_VM"}, "icmpIdleTimeoutSec":15, "minPortsPerVm":128, "name":"my-cloud-nat-cft-cloud-nat-test-RANDOM_ID", "natIpAllocateOption":"MANUAL_ONLY", "sourceSubnetworkIpRangesToNat":"LIST_OF_SUBNETWORKS", "subnetworks":[]interface {}{map[string]interface {}{"name":"https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/us-east4/subnetworks/cft-cloud-nat-test-RANDOM_ID-a", "sourceIpRangesToNat":[]interface {}{"ALL_IP_RANGES"}}}, "tcpEstablishedIdleTimeoutSec":600, "tcpTimeWaitTimeoutSec":120, "tcpTransitoryIdleTimeoutSec":15, "udpIdleTimeoutSec":15}
        	            	actual  : map[string]interface {}{"enableDynamicPortAllocation":false, "enableEndpointIndependentMapping":true, "endpointTypes":[]interface {}{"ENDPOINT_TYPE_VM"}, "icmpIdleTimeoutSec":15, "minPortsPerVm":128, "name":"my-cloud-nat-cft-cloud-nat-test-RANDOM_ID", "natIpAllocateOption":"MANUAL_ONLY", "sourceSubnetworkIpRangesToNat":"LIST_OF_SUBNETWORKS", "subnetworks":[]interface {}{map[string]interface {}{"name":"https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/us-east4/subnetworks/cft-cloud-nat-test-RANDOM_ID-a", "sourceIpRangesToNat":[]interface {}{"ALL_IP_RANGES"}}}, "tcpEstablishedIdleTimeoutSec":600, "tcpTimeWaitTimeoutSec":120, "tcpTransitoryIdleTimeoutSec":15, "udpIdleTimeoutSec":15}
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -1,2 +1,3 @@
        	            	-(map[string]interface {}) (len=12) {
        	            	+(map[string]interface {}) (len=13) {
        	            	+ (string) (len=27) "enableDynamicPortAllocation": (bool) false,
        	            	  (string) (len=32) "enableEndpointIndependentMapping": (bool) true,
        	Test:       	TestSubnetworks

@github-actions github-actions bot removed the Stale label Mar 24, 2023
@apeabody
Copy link
Contributor

apeabody commented Apr 3, 2023

/gcbrun

@apeabody
Copy link
Contributor

apeabody commented Apr 4, 2023

/gcbrun

@sclausson
Copy link

@apeabody any updates on this one? Would be great to be able to add dynamic port mapping to the module.

@apeabody
Copy link
Contributor

/gcbrun

@apeabody
Copy link
Contributor

@apeabody any updates on this one? Would be great to be able to add dynamic port mapping to the module.

Hi @sclausson - I've retriggered the CI, but I suspect this is still relevant #73 (comment)

@nikhilmakhijani
Copy link
Contributor Author

/gcbrun

@nikhilmakhijani
Copy link
Contributor Author

@apeabody any updates on this one? Would be great to be able to add dynamic port mapping to the module.

Hi @sclausson - I've retriggered the CI, but I suspect this is still relevant #73 (comment)

Hi @apeabody I have updated the test case. Could you please check again?

@apeabody
Copy link
Contributor

/gcbrun

@apeabody
Copy link
Contributor

Hi @nikhilmakhijani here is the current INT output:

TestAdvanced 2023-05-11T16:34:02Z command.go:185: "cloud-foundation-cicd"
    advanced_test.go:45: 
        	Error Trace:	/workspace/test/integration/advanced/advanced_test.go:45
        	            				/builder/home/go/pkg/mod/github.com/!google!cloud!platform/cloud-foundation-toolkit/infra/blueprint-test@v0.5.1/pkg/tft/terraform.go:408
        	            				/builder/home/go/pkg/mod/github.com/!google!cloud!platform/cloud-foundation-toolkit/infra/blueprint-test@v0.5.1/pkg/tft/terraform.go:428
        	            				/builder/home/go/pkg/mod/github.com/!google!cloud!platform/cloud-foundation-toolkit/infra/blueprint-test@v0.5.1/pkg/utils/stages.go:31
        	            				/builder/home/go/pkg/mod/github.com/!google!cloud!platform/cloud-foundation-toolkit/infra/blueprint-test@v0.5.1/pkg/tft/terraform.go:428
        	Error:      	Not equal: 
        	            	expected: map[string]interface {}{"enableEndpointIndependentMapping":true, "endpointTypes":[]interface {}{"ENDPOINT_TYPE_VM"}, "icmpIdleTimeoutSec":15, "minPortsPerVm":128, "name":"my-cloud-nat-cft-cloud-nat-test-RANDOM_ID", "natIpAllocateOption":"MANUAL_ONLY", "sourceSubnetworkIpRangesToNat":"ALL_SUBNETWORKS_ALL_IP_RANGES", "tcpEstablishedIdleTimeoutSec":600, "tcpTimeWaitTimeoutSec":240, "tcpTransitoryIdleTimeoutSec":15, "udpIdleTimeoutSec":15}
        	            	actual  : map[string]interface {}{"enableDynamicPortAllocation":false, "enableEndpointIndependentMapping":true, "endpointTypes":[]interface {}{"ENDPOINT_TYPE_VM"}, "icmpIdleTimeoutSec":15, "minPortsPerVm":128, "name":"my-cloud-nat-cft-cloud-nat-test-RANDOM_ID", "natIpAllocateOption":"MANUAL_ONLY", "sourceSubnetworkIpRangesToNat":"ALL_SUBNETWORKS_ALL_IP_RANGES", "tcpEstablishedIdleTimeoutSec":600, "tcpTimeWaitTimeoutSec":240, "tcpTransitoryIdleTimeoutSec":15, "udpIdleTimeoutSec":15}
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -1,2 +1,3 @@
        	            	-(map[string]interface {}) (len=11) {
        	            	+(map[string]interface {}) (len=12) {
        	            	+ (string) (len=27) "enableDynamicPortAllocation": (bool) false,
        	            	  (string) (len=32) "enableEndpointIndependentMapping": (bool) true,
        	Test:       	TestAdvanced
        	```

@apeabody
Copy link
Contributor

/gcbrun

Copy link
Contributor

@apeabody apeabody left a comment

Choose a reason for hiding this comment

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

Thanks @nikhilmakhijani - a few final nits.

main.tf Outdated Show resolved Hide resolved
outputs.tf Outdated Show resolved Hide resolved
variables.tf Outdated Show resolved Hide resolved
versions.tf Outdated Show resolved Hide resolved
variables.tf Show resolved Hide resolved
@apeabody apeabody changed the title feat: add dynamic port mapping feat!: add dynamic port mapping May 11, 2023
@apeabody
Copy link
Contributor

/gcbrun

@apeabody apeabody changed the title feat!: add dynamic port mapping feat(removes nat_ip_allocate_option)!: add dynamic port mapping May 11, 2023
@apeabody apeabody merged commit 0cf1d69 into terraform-google-modules:master May 11, 2023
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

Successfully merging this pull request may close these issues.

9 participants