-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add google's terraform module 'kubernetes-engine' to our local modules * use zonal with minimal node pool as default for gke instance. This has the added benefit of quick provisioning, taking advantage of the GCP free tier, and keeping our configs simple * move network topgraphy definition our of k8 module
- Loading branch information
1 parent
e48fdb2
commit 6246921
Showing
12 changed files
with
228 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,54 @@ | ||
module "gcp_apis" { | ||
source = "../modules/gcp-apis" | ||
locals { | ||
subnet_base_name = "${var.vpc_name}-subnet" | ||
k8_subnet_pod_ip_range = "${local.subnet_base_name}-pods" | ||
k8_subnet_service_ip_range = "${local.subnet_base_name}-services" | ||
} | ||
|
||
project = var.project | ||
module "gcp_apis" { | ||
source = "../modules/gcp-apis" | ||
project = var.project | ||
services = [ | ||
"compute.googleapis.com", | ||
"container.googleapis.com" | ||
] | ||
} | ||
|
||
module "vpc" { | ||
source = "../modules/network" | ||
vpc_name = var.vpc_name | ||
project = var.project | ||
region = var.region | ||
depends_on = [module.gcp_apis] | ||
subnets = [ | ||
{ | ||
subnet_name = local.subnet_base_name | ||
subnet_ip = "10.0.0.0/16" | ||
subnet_region = var.region | ||
} | ||
] | ||
secondary_ranges = { | ||
(local.subnet_base_name) = [ | ||
{ | ||
range_name = local.k8_subnet_pod_ip_range | ||
ip_cidr_range = "10.1.0.0/24" | ||
}, | ||
{ | ||
range_name = local.k8_subnet_service_ip_range | ||
ip_cidr_range = "10.2.0.0/24" | ||
} | ||
] | ||
} | ||
} | ||
|
||
module "k8" { | ||
source = "../modules/k8" | ||
name = "haztrak-gke" | ||
network = module.vpc.network | ||
project = var.project | ||
region = var.region | ||
zones = [var.zone] | ||
subnet_name = local.subnet_base_name | ||
pod_ip_range_name = local.k8_subnet_pod_ip_range | ||
service_ip_range_name = local.k8_subnet_service_ip_range | ||
depends_on = [module.gcp_apis, module.vpc] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
locals { | ||
env_name = var.environment == "prod" ? var.name : "${var.name}-${var.environment}" | ||
name = var.regional ? local.env_name : "${local.env_name}-zonal" | ||
cluster_type = "simple-autopilot-public" | ||
} | ||
module "gke" { | ||
source = "terraform-google-modules/kubernetes-engine/google" | ||
description = var.description | ||
project_id = var.project | ||
name = local.name | ||
regional = false | ||
region = var.region | ||
zones = var.zones | ||
network = var.network | ||
service_account = "create" | ||
service_account_name = "${var.project}-tf-sa" | ||
subnetwork = var.subnet_name | ||
ip_range_pods = var.pod_ip_range_name | ||
ip_range_services = var.service_ip_range_name | ||
release_channel = "REGULAR" | ||
enable_vertical_pod_autoscaling = false | ||
horizontal_pod_autoscaling = false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
output "endpoint" { | ||
value = module.gke.endpoint | ||
} | ||
|
||
output "ca_certificate" { | ||
value = module.gke.ca_certificate | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
variable "project" { | ||
description = "The Google Cloud project ID to enable services in." | ||
type = string | ||
validation { | ||
error_message = "GCP project length must be greater than zero" | ||
condition = length(var.project) > 0 | ||
} | ||
} | ||
|
||
variable "name" { | ||
description = "The name of the GKE cluster." | ||
type = string | ||
} | ||
|
||
variable "environment" { | ||
description = "The environment to deploy to" | ||
type = string | ||
default = "dev" | ||
validation { | ||
condition = contains(["dev", "prod"], var.environment) | ||
error_message = "Environment must be one of [dev, prod]" | ||
} | ||
} | ||
|
||
variable "regional" { | ||
description = "Whether to deploy a regional cluster (multiple zones) or zonal (single zone)" | ||
type = bool | ||
default = false | ||
} | ||
|
||
variable "region" { | ||
description = "The region to deploy to" | ||
default = "us-east1" | ||
type = string | ||
validation { | ||
condition = can(regex("^[a-z]{2,}-[a-z]*[1-9]{1}$", var.region)) | ||
error_message = "Invalid GCP region format. See 'gcloud compute regions list' for available options" | ||
} | ||
} | ||
|
||
variable "zones" { | ||
type = list(string) | ||
description = "The zone to host the cluster in (required if is a zonal cluster)" | ||
} | ||
|
||
variable "description" { | ||
type = string | ||
description = "The description of the cluster" | ||
default = "Haztrak GKE Cluster" | ||
} | ||
|
||
variable "network" { | ||
type = string | ||
description = "The VPC network to host the cluster in (required)" | ||
} | ||
|
||
variable "subnet_name" { | ||
type = string | ||
description = "The name of the subnet to host the cluster in (required)" | ||
} | ||
|
||
variable "pod_ip_range_name" { | ||
type = string | ||
description = "The name of the secondary IP range the pods will be assigned to." | ||
} | ||
|
||
variable "service_ip_range_name" { | ||
type = string | ||
description = "The name of the secondary IP range the services will be assigned to." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
output "network" { | ||
value = module.vpc.network | ||
} | ||
|
||
output "vpc" { | ||
value = module.vpc.network_id | ||
value = module.vpc.network_name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters