Skip to content

GlueOps/terraform-module-cloud-gcp-kubernetes-cluster

Repository files navigation

terraform-module-cloud-gcp-kubernetes-cluster

This terraform module is to help you quickly deploy a GKE cluster on Google Cloud Platform. This is part of the opionated GlueOps Platform.

Example usage of module

module "captain" {
  source = "git::https://github.com/GlueOps/terraform-module-cloud-gcp-kubernetes-cluster.git"
  kubernetes_network_ranges = {
    "kubernetes_pods" : "10.65.0.0/16",
    "kubernetes_services" : "10.64.224.0/20",
    "kubernetes_nodes" : "10.64.64.0/23"
  }
  private_connection_to_services = [
    {
      cidrs   = [{ name = "gcp-services-network-primary", cidr = "10.0.128.0/19" }, { name = "gcp-services-network-another", cidr = "10.1.128.0/19" }]
      service = "servicenetworking.googleapis.com"
    }
  ]
  private_connect_services = [
  #   {
  #   name = "db-mysql"
  #   service_attachment_uri = "projects/o12236157d3bd7c3ep-tp/regions/us-central1/serviceAttachments/a-7197c4ad7e38-psc-service-attachment-40adaaa378076d07"
  # },
  ]  
  project_id = "replace-with-actual-project-id"
  region     = "us-central1"
  zonal      = false
  cluster_supported_node_pool_zones = ["a","b","c"]
  node_pools = [
    {
      name         = "glueops-platform-node-pool-1"
      machine_type = "c2-standard-4"
      disk_type    = "pd-standard"
      disk_size_gb = 30
      auto_upgrade = false
      auto_repair  = true
      gke_version  = "1.28.11-gke.1172000"
      node_count   = 2
      spot         = false
      preemptible  = false
      node_pool_zones = ["a","b"]
      kubernetes_labels = {
        "glueops.dev/role" : "glueops-platform"
      }
      kubernetes_taints = [
        {
          key    = "glueops.dev/role"
          value  = "glueops-platform"
          effect = "NO_SCHEDULE"
        }
      ]
    },
    {
      name         = "glueops-node-pool-argocd-app-ctrl-1"
      machine_type = "c2-standard-4"
      disk_type    = "pd-standard"
      disk_size_gb = 30
      auto_upgrade = false
      auto_repair  = true
      gke_version  = "1.28.11-gke.1172000"
      node_count   = 2
      spot         = false
      preemptible  = false
      node_pool_zones = ["a","b"]
      kubernetes_labels = {
        "glueops.dev/role" : "glueops-platform-argocd-app-controller"
      }
      kubernetes_taints = [
        {
          key    = "glueops.dev/role"
          value  = "glueops-platform-argocd-app-controller"
          effect = "NO_SCHEDULE"
        }
      ]
    },
    {
      name         = "clusterwide-node-pool-1"
      machine_type = "c2-standard-4"
      disk_type    = "pd-standard"
      disk_size_gb = 30
      auto_upgrade = false
      auto_repair  = true
      gke_version  = "1.28.11-gke.1172000"
      node_count   = 2
      spot         = false
      preemptible  = false
      node_pool_zones = ["a","b"]
      kubernetes_labels = {}
      kubernetes_taints = []
    },
  ]
  gke_version = "1.28.11-gke.1172000"
  network_peering_configurations = [
#    {
#    peer_network                        = "projects/example-project/global/networks/example-network-2"
#    peering_name                        = "peering-networkA-to-networkB"
#    export_custom_routes                = false
#    export_subnet_routes_with_public_ip = true
#    import_custom_routes                = false
#    }
  ]
}

Requirements

No requirements.

Providers

Name Version
google n/a

Modules

No modules.

Resources

Name Type
google_compute_address.private_service_connect_address resource
google_compute_forwarding_rule.private_service_connect_forwarding_rule resource
google_compute_global_address.gcp_managed_services resource
google_compute_network.vpc_network resource
google_compute_network_peering.peering resource
google_compute_route.default resource
google_compute_router.router resource
google_compute_subnetwork.kubernetes resource
google_container_cluster.captain resource
google_container_node_pool.custom_pools resource
google_project_iam_member.gke-project-roles resource
google_project_service.activate_apis resource
google_service_account.gke_node_pool resource
google_service_networking_connection.private_connection resource
google_project.project data source

Inputs

Name Description Type Default Required
cluster_supported_node_pool_zones n/a list(string)
[
"a",
"b",
"c"
]
no
gke_version Static Channel GKE version to use. This applies only to the master/control plane and not the nodes. Please specify a matching version for the nodes in the node pool definition. ref: https://cloud.google.com/kubernetes-engine/docs/release-notes string "1.28.11-gke.1260000" no
kubernetes_network_ranges CIDR ranges to use for the cluster deployment. map(string)
{
"kubernetes_nodes": "10.64.64.0/23",
"kubernetes_pods": "10.65.0.0/16",
"kubernetes_services": "10.64.224.0/20"
}
no
network_peering_configurations A list of network peering configurations. Each configuration is an object with the following attributes:
- 'peer_network': The self-link of the peer network for the peering (e.g., 'projects/[PROJECT_ID]/global/networks/[NETWORK_NAME]').
- 'peering_name': A unique name for the peering connection.
- 'export_custom_routes': A boolean indicating whether custom routes will be exported from the network (default: false).
- 'export_subnet_routes_with_public_ip': A boolean indicating whether subnet routes with public IP will be exported (default: false).
- 'import_custom_routes': A boolean indicating whether custom routes will be imported from the peer network (default: false).

This variable enables the dynamic creation and management of multiple network peerings.
The default is an empty list, indicating no peerings will be established if not specified.

Example:
[
{
peer_network = "projects/example-project/global/networks/example-network-1"
peering_name = "example-peering-1"
export_custom_routes = false
export_subnet_routes_with_public_ip = true
import_custom_routes = false
},
{
peer_network = "projects/example-project/global/networks/example-network-2"
peering_name = "example-peering-2"
export_custom_routes = true
export_subnet_routes_with_public_ip = false
import_custom_routes = true
}
]
list(object({
peer_network = string
peering_name = string
export_custom_routes = bool
export_subnet_routes_with_public_ip = bool
import_custom_routes = bool
}))
[] no
node_pools node pool configurations:
- name (string): Name of the node pool. MUST BE UNIQUE! Recommended to use YYYYMMDD in the name
- node_count (number): number of nodes to create in the node pool.
- machine_type (string): Machine type to use for the nodes. ref: https://gcpinstances.doit-intl.com/
- disk_type (string): Disk type to use for the nodes. ref: https://cloud.google.com/compute/docs/disks
- disk_size_gb (number): Disk size in GB for the nodes.
- gke_version (string): GKE version to use for the nodes. ref: https://cloud.google.com/kubernetes-engine/docs/release-notes
- spot (bool): Enable spot instances for the nodes. DO NOT ENABLE IN PROD!
list(object({
name = string
node_count = number
machine_type = string
disk_type = string
disk_size_gb = number
gke_version = string
spot = bool
preemptible = bool
kubernetes_labels = map(string)
kubernetes_taints = list(object({
key = string
value = string
effect = string
}))
node_pool_zones = list(string)
}))
[
{
"disk_size_gb": 20,
"disk_type": "pd-standard",
"gke_version": "1.28.11-gke.1260000",
"kubernetes_labels": {},
"kubernetes_taints": [],
"machine_type": "e2-medium",
"name": "default-pool",
"node_count": 1,
"node_pool_zones": [
"a"
],
"preemptible": false,
"spot": false
}
]
no
private_connect_services List of services to create with their respective details
list(object({
name = string
service_attachment_uri = string
}))
[] no
private_connection_to_services GCP private connection configurations.
list(object({
cidrs : list(object({
name : string,
cidr : string
}))
service : string
}))
[
{
"cidrs": [
{
"cidr": "10.0.128.0/19",
"name": "gcp-services-network-primary"
},
{
"cidr": "10.1.128.0/19",
"name": "gcp-services-network-another"
}
],
"service": "servicenetworking.googleapis.com"
}
]
no
project_id project id to deploy the cluster in string n/a yes
region region to deploy the cluster in string "us-central1" no
zonal Enable if you want this to be a zonal cluster. If true, this will be set to zone a for the region specified. bool n/a yes

Outputs

No outputs.