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

Firewall support #470

Merged
merged 8 commits into from
Apr 23, 2020
Merged

Firewall support #470

merged 8 commits into from
Apr 23, 2020

Conversation

Dev25
Copy link
Contributor

@Dev25 Dev25 commented Mar 31, 2020

Closes #452

Add the 2 firewall rules raised in that issue, which can be opted out using var.firewall_enabled.

Common inbound ports are also white listed by default (8443/9443 and 15017 for istio 1.5) for a better UX (port list controlled by var.firewall_inbound_ports)

Refactoring:

  • Save "gke-${var.name}" network tag format into locals, this module already adds that network tag to all node pools
  • Move networks.tf to autogen/ so module variants have access to data.google_compute_subnetwork.gke_subnetwork which can be used to determine pod CIDR
  • Misc formatting fixes to templates so the latest docker image is happy for make build docker_test_lint

TODO:

  • README update, this requires the terraform runner to have necessary IAM permissions to make firewall changes in the VPC project

Signed-off-by: Dev <Dev25@users.noreply.github.com>
Signed-off-by: Dev <Dev25@users.noreply.github.com>
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.

Thanks for submitting this, just a few suggestions.

autogen/main/README.md Outdated Show resolved Hide resolved

{{ autogeneration_note }}

data "google_compute_network" "gke_network" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Note this might raise some issues with networks created inline. Could we make these data sources conditional on the firewall_enabled var?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will look into doing that.

Copy link
Member

Choose a reason for hiding this comment

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

I think the regular count conditional approach should work on datasources too

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is the only thing blocking merge 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.

Should be fixed in 8ffa5e8
Also removed the top level network datasource since it seems unused

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Plus ceef395 to fix attribute errors, not pretty but it works/keeps it all conditional.

Error: Unsupported attribute

  on .terraform/modules/blue_gke.gke/main.tf line 75, in locals:
  75:   cluster_alias_ranges_cidr = { for range in toset(data.google_compute_subnetwork.gke_subnetwork.*.secondary_ip_range) : range.range_name => range.ip_cidr_range }

autogen/main/variables.tf.tmpl Outdated Show resolved Hide resolved
autogen/main/variables.tf.tmpl Outdated Show resolved Hide resolved
Signed-off-by: Dev <Dev25@users.noreply.github.com>
Signed-off-by: Dev <Dev25@users.noreply.github.com>
Signed-off-by: Dev <Dev25@users.noreply.github.com>
@morgante
Copy link
Contributor

@Dev25 This is the error which shows up for that test:

       Error: project: required field is not set
       
         on ../../../main.tf line 22, in data "google_compute_zones" "available":
         22: data "google_compute_zones" "available" {
       
       
       
       Error: project: required field is not set
       
         on ../../../main.tf line 125, in data "google_container_engine_versions" "region":
        125: data "google_container_engine_versions" "region" {

@bharathkkb
Copy link
Member

bharathkkb commented Apr 21, 2020

That does seem weird, let me try re running - svpc example seems fine to me


{{ autogeneration_note }}

data "google_compute_network" "gke_network" {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is the only thing blocking merge now.

Signed-off-by: Dev <Dev25@users.noreply.github.com>
@Dev25
Copy link
Contributor Author

Dev25 commented Apr 22, 2020

btw a old CI job seems to be stuck, you may want to explicitly cancel it: https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/runs/605516376

Google Cloud Build / Trigger: 10ee403a-235b-42d6-8acc-5ebfe78cfcae
started 1d 6h 13m 32s ago

@bharathkkb
Copy link
Member

@Dev25 that succeeded on cloud build, for some reason it didnt report back to GH

Signed-off-by: Dev <Dev25@users.noreply.github.com>
@morgante morgante merged commit 16bdd6e into terraform-google-modules:master Apr 23, 2020
@@ -71,6 +71,9 @@ locals {
// auto upgrade by defaults only for regional cluster as long it has multiple masters versus zonal clusters have only have a single master so upgrades are more dangerous.
default_auto_upgrade = var.regional ? true : false

cluster_subnet_cidr = var.add_cluster_firewall_rules ? data.google_compute_subnetwork.gke_subnetwork[0].ip_cidr_range : null
cluster_alias_ranges_cidr = var.add_cluster_firewall_rules ? { for range in toset(data.google_compute_subnetwork.gke_subnetwork[0].secondary_ip_range) : range.range_name => range.ip_cidr_range } : {}
Copy link

@erichaase erichaase Jul 22, 2020

Choose a reason for hiding this comment

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

I'm getting the following error on terraform plan (also applies to apply, refresh, etc.) thrown by this line:

Error: Iteration over null value

  on .terraform/modules/corp-dev-us-east1-c-01.gke/terraform-google-kubernetes-engine-10.0.0/modules/beta-private-cluster-update-variant/main.tf line 72, in locals:
  72:   cluster_alias_ranges_cidr = var.add_cluster_firewall_rules ? { for range in toset(data.google_compute_subnetwork.gke_subnetwork[0].secondary_ip_range) : range.range_name => range.ip_cidr_range } : {}
    |----------------
    | data.google_compute_subnetwork.gke_subnetwork[0].secondary_ip_range is null

A null value cannot be used as the collection in a 'for' expression.

I'm having a hard time troubleshooting this on our end and would appreciate any feedback y'all have on this. cc: @bharathkkb @morgante

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you open a new issue w/ your Terraform config?

Copy link

@erichaase erichaase Jul 22, 2020

Choose a reason for hiding this comment

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

Yeah, sure: #608

CPL-markus pushed a commit to WALTER-GROUP/terraform-google-kubernetes-engine that referenced this pull request Jul 15, 2024
…s#470)

* Squash Commits

Signed-off-by: Dev <Dev25@users.noreply.github.com>

* Fix example

Signed-off-by: Dev <Dev25@users.noreply.github.com>

* Rename var + update README

Signed-off-by: Dev <Dev25@users.noreply.github.com>

* Set to false as default

Signed-off-by: Dev <Dev25@users.noreply.github.com>

* Enable firewall support in shared_vpc example

Signed-off-by: Dev <Dev25@users.noreply.github.com>

* Remove network datasource and make subnetwork conditional on firewall

Signed-off-by: Dev <Dev25@users.noreply.github.com>

* Fix attribute error

Signed-off-by: Dev <Dev25@users.noreply.github.com>
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 optional firewall support
4 participants