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

Addresses Issue #248 (Add Support for Exporting PUPIs - Network Peering Module) #255

Merged
merged 4 commits into from Mar 4, 2021
Merged

Addresses Issue #248 (Add Support for Exporting PUPIs - Network Peering Module) #255

merged 4 commits into from Mar 4, 2021

Conversation

rglenn-accenture
Copy link
Contributor

@rglenn-accenture rglenn-accenture commented Mar 4, 2021

This introduces support for the export_subnet_routes_with_public_ip and import_subnet_routes_with_public_ip variables in the google_compute_network_peering resources. This is necessary when peering VPCs that are using Privately Used Public IPs (PUPIs) as the private subnet IPs.

Note - the defaults proposed in this PR are false for both variables, but the provider's default for export_subnet_routes_with_public_ip is true (the import variable is also set to false, by default, here); because these come in pairs (defining each end of the peering), and because the current Network Peering submodule doesn't override these defaults, it will cause each peering will attempt to export these subnets but neither peering will attempt to import them; not a problem, really, but the proposed solution also addresses this incongruence, by default.

Fixes #248

@rglenn-accenture rglenn-accenture requested a review from a team March 4, 2021 15:13
@comment-bot-dev
Copy link

comment-bot-dev commented Mar 4, 2021

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

Copy link
Contributor

@morgante morgante left a comment

Choose a reason for hiding this comment

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

Let's make the variable names and defaults match the provider.

@rglenn-accenture
Copy link
Contributor Author

Let's make the variable names and defaults match the provider.

A full match for the names doesn't make sense, given the provider handles one side of the connection, but the Network Peering module handles both sides. I'll match the naming convention of the other such variables in this module (introducing the interstitial "peer" or "local" designations).

@morgante
Copy link
Contributor

morgante commented Mar 4, 2021

Good point, yes let's match the existing convention.

@rglenn-accenture
Copy link
Contributor Author

rglenn-accenture commented Mar 4, 2021

Let's make the variable names and defaults match the provider.

Actually, for the default values, note that to make export_subnet_routes_with_public_ip true for both local and remote connections, we must negate the values for one side of the peering connection for it to match the provider defaults:

resource "google_compute_network_peering" "local_network_peering" {
  provider             = google-beta
  name                 = local.local_network_peering_name
  network              = var.local_network
  peer_network         = var.peer_network
  export_custom_routes = var.export_local_custom_routes
  import_custom_routes = var.export_peer_custom_routes

  # export_local_subnet_routes_with_public_ip defaults to true, to match the provider default
  export_subnet_routes_with_public_ip = var.export_local_subnet_routes_with_public_ip
  # export_peer_subnet_routes_with_public_ip defaults to false, to match the provider default
  import_subnet_routes_with_public_ip = var.export_peer_subnet_routes_with_public_ip

  depends_on = [null_resource.module_depends_on]
}

resource "google_compute_network_peering" "peer_network_peering" {
  provider             = google-beta
  name                 = local.peer_network_peering_name
  network              = var.peer_network
  peer_network         = var.local_network
  export_custom_routes = var.export_peer_custom_routes
  import_custom_routes = var.export_local_custom_routes

  # export_peer_subnet_routes_with_public_ip must be negated, to match the provider default
  export_subnet_routes_with_public_ip = var.export_peer_subnet_routes_with_public_ip ? false : true
  # export_local_subnet_routes_with_public_ip must be negated, to match the provider default
  import_subnet_routes_with_public_ip = var.export_local_subnet_routes_with_public_ip ? false : true

  depends_on = [null_resource.module_depends_on, google_compute_network_peering.local_network_peering]
}

I believe this might actually prevent certain valid route imports/exports.

I would imagine a prudent alternative would be to align the default values to the local peering, only, and acknowledge in the documentation that the remote peering (by default) will have exact-opposite-from-default controls for the subnet routes with public ips.

Another alternative would be to have export_peer_subnet_routes_with_public_ip, import_peer_subnet_routes_with_public_ip, export_local_subnet_routes_with_public_ip, import_local_subnet_routes_with_public_ip, but this seems unnecessary given the problem this module seems to address (which is ostensibly to simplify creating the peering connection, and avoid partial configuration due to exported routes that are not imported on the other end).

I will target the former option in an updated PR, but feel free to suggest a better approach.

@morgante
Copy link
Contributor

morgante commented Mar 4, 2021

The former sounds good, thanks. Let's just document it clearly.

@rglenn-accenture
Copy link
Contributor Author

I'm not sure why the lint trigger failed. The make docker_test_lint command seems to succeed for me locally, and I think my local copy of the gcr.io/cloud-foundation-cicd/cft/developer-tools:0.13 should be the same as what is used in the cloudbuild trigger (assuming it uses this ./build/lint.cloudbuild.yaml in the lint-trigger).
Is there any additional information in the CloudBuild logs?

@morgante morgante merged commit 8666553 into terraform-google-modules:master Mar 4, 2021
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.

Add Support for Exporting Privately Used Public IPs (PUPIs) - Network Peering Module
3 participants