-
Notifications
You must be signed in to change notification settings - Fork 6
Introduce separate networking submodule #25
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -5,21 +5,28 @@ locals { | |||
| }) | ||||
| } | ||||
|
|
||||
|
|
||||
| provider "google" { | ||||
| project = var.project_id | ||||
| region = var.region | ||||
| } | ||||
|
|
||||
| module "gke" { | ||||
| source = "./modules/gke" | ||||
| module "networking" { | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like we always had it there and it was just duplicated in the prociders.tf file as well: terraform-google-materialize/main.tf Line 170 in c4eb806
|
||||
| source = "./modules/networking" | ||||
|
|
||||
| project_id = var.project_id | ||||
| region = var.region | ||||
| prefix = var.prefix | ||||
| subnet_cidr = var.network_config.subnet_cidr | ||||
| pods_cidr = var.network_config.pods_cidr | ||||
| services_cidr = var.network_config.services_cidr | ||||
| } | ||||
|
|
||||
| module "gke" { | ||||
| source = "./modules/gke" | ||||
|
|
||||
| depends_on = [module.networking] | ||||
|
|
||||
| project_id = var.project_id | ||||
| region = var.region | ||||
| prefix = var.prefix | ||||
| network_name = module.networking.network_name | ||||
| subnet_name = module.networking.subnet_name | ||||
| network_dependency = module.networking.private_vpc_connection | ||||
|
|
||||
| node_count = var.gke_config.node_count | ||||
| machine_type = var.gke_config.machine_type | ||||
|
|
@@ -34,15 +41,18 @@ module "gke" { | |||
| module "database" { | ||||
| source = "./modules/database" | ||||
|
|
||||
| depends_on = [module.gke] | ||||
| depends_on = [ | ||||
| module.networking, | ||||
| module.gke | ||||
| ] | ||||
|
|
||||
| database_name = var.database_config.db_name | ||||
| database_user = var.database_config.username | ||||
|
|
||||
| project_id = var.project_id | ||||
| region = var.region | ||||
| prefix = var.prefix | ||||
| network_id = module.gke.network_id | ||||
| network_id = module.networking.network_id | ||||
|
|
||||
| tier = var.database_config.tier | ||||
| db_version = var.database_config.version | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,83 +1,9 @@ | ||
| resource "google_compute_network" "vpc" { | ||
| name = "${var.prefix}-network" | ||
| auto_create_subnetworks = false | ||
| project = var.project_id | ||
|
|
||
| lifecycle { | ||
| create_before_destroy = true | ||
| prevent_destroy = false | ||
| } | ||
| } | ||
|
|
||
| resource "google_compute_route" "default_route" { | ||
| name = "${var.prefix}-default-route" | ||
| project = var.project_id | ||
| network = google_compute_network.vpc.name | ||
| dest_range = "0.0.0.0/0" | ||
| priority = 1000 | ||
| next_hop_gateway = "default-internet-gateway" | ||
|
|
||
| # Ensure this is destroyed before the network | ||
| depends_on = [google_compute_network.vpc] | ||
|
|
||
| lifecycle { | ||
| create_before_destroy = true | ||
| } | ||
| } | ||
|
|
||
| resource "google_compute_subnetwork" "subnet" { | ||
| name = "${var.prefix}-subnet" | ||
| project = var.project_id | ||
| network = google_compute_network.vpc.id | ||
| ip_cidr_range = var.subnet_cidr | ||
| region = var.region | ||
|
|
||
| private_ip_google_access = true | ||
|
|
||
| secondary_ip_range { | ||
| range_name = "pods" | ||
| ip_cidr_range = var.pods_cidr | ||
| } | ||
|
|
||
| secondary_ip_range { | ||
| range_name = "services" | ||
| ip_cidr_range = var.services_cidr | ||
| } | ||
| } | ||
|
|
||
| resource "google_service_account" "gke_sa" { | ||
| project = var.project_id | ||
| account_id = "${var.prefix}-gke-sa" | ||
| display_name = "GKE Service Account for Materialize" | ||
| } | ||
|
|
||
| resource "google_compute_global_address" "private_ip_address" { | ||
| provider = google | ||
| project = var.project_id | ||
| name = "${var.prefix}-private-ip" | ||
| purpose = "VPC_PEERING" | ||
| address_type = "INTERNAL" | ||
| prefix_length = 16 | ||
| network = google_compute_network.vpc.id | ||
|
|
||
| lifecycle { | ||
| create_before_destroy = true | ||
| } | ||
| } | ||
|
|
||
| resource "google_service_networking_connection" "private_vpc_connection" { | ||
| provider = google | ||
| network = google_compute_network.vpc.id | ||
| service = "servicenetworking.googleapis.com" | ||
| reserved_peering_ranges = [google_compute_global_address.private_ip_address.name] | ||
|
|
||
| lifecycle { | ||
| create_before_destroy = true | ||
| } | ||
|
|
||
| deletion_policy = "ABANDON" | ||
| } | ||
|
|
||
| resource "google_service_account" "workload_identity_sa" { | ||
| project = var.project_id | ||
| account_id = "${var.prefix}-materialize-sa" | ||
|
|
@@ -92,18 +18,16 @@ resource "google_container_cluster" "primary" { | |
| depends_on = [ | ||
| google_service_account.gke_sa, | ||
| google_service_account.workload_identity_sa, | ||
| google_service_networking_connection.private_vpc_connection, | ||
| google_compute_subnetwork.subnet, | ||
| google_compute_route.default_route | ||
| var.network_dependency # This ensures the network is created first | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the gke module dependency on the networking dependency also ensure the network is created first? I'm guessing you wouldn't have done this if it did, but that's weird.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, just tested this without the extra redundancy of the network_dependency var and it works well as well. |
||
| ] | ||
|
|
||
| name = "${var.prefix}-gke" | ||
| location = var.region | ||
| project = var.project_id | ||
|
|
||
| networking_mode = "VPC_NATIVE" | ||
| network = google_compute_network.vpc.name | ||
| subnetwork = google_compute_subnetwork.subnet.name | ||
| network = var.network_name | ||
| subnetwork = var.subnet_name | ||
|
|
||
| remove_default_node_pool = true | ||
| initial_node_count = 1 | ||
|
|
@@ -171,10 +95,8 @@ resource "google_container_node_pool" "primary_nodes" { | |
|
|
||
| lifecycle { | ||
| create_before_destroy = true | ||
|
|
||
| prevent_destroy = false | ||
| prevent_destroy = false | ||
| } | ||
|
|
||
| } | ||
|
|
||
| resource "google_service_account_iam_binding" "workload_identity" { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Below in the output section, should we add the
output "network" {section?