Skip to content

Commit

Permalink
[#2556] Cleaning up the GCP-GKE after the review (#3717)
Browse files Browse the repository at this point in the history
  • Loading branch information
bilge-cakmak committed Sep 16, 2022
1 parent 41a9f11 commit a0ee92e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 44 deletions.
2 changes: 0 additions & 2 deletions infrastructure/terraform/install/gcp-gke/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module "gcp-gke" {
#source = "github.com/airyhq/airy.git/infrastructure/terraform/modules/gcp-gke"
source = "../../modules/gcp-gke"


project_id = var.project_id
region = var.region
zone = var.zone
}
4 changes: 0 additions & 4 deletions infrastructure/terraform/install/gcp-gke/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,4 @@ variable "project_id" {
variable "region" {
default = "us-central1"
description = "The region is us-central1"
}
variable "zone" {
default = "us-central1-a"
description = "The zone defined in gcloud config is us-central1-a"
}
42 changes: 14 additions & 28 deletions infrastructure/terraform/modules/gcp-gke/main.tf
Original file line number Diff line number Diff line change
@@ -1,62 +1,48 @@
provider "google" {
project = var.project_id
region = var.region
region = var.region
}

# VPC
resource "google_compute_network" "vpc" {
name = var.vpc_name
auto_create_subnetworks = "false"
}

# Subnet
resource "google_compute_subnetwork" "subnet" {
name = "${var.project_id}-subnet-public-0"
region = var.region
network = google_compute_network.vpc.name
ip_cidr_range = var.public_subnets[0]
}

# GKE cluster
resource "google_container_cluster" "gke_core" {
name = "${var.project_id}-gke"
location = var.zone
location = var.region

remove_default_node_pool = true
initial_node_count = 1
initial_node_count = var.gke_initial_node_count

network = google_compute_network.vpc.name
subnetwork = google_compute_subnetwork.subnet.name
}

# Separately Managed Node Pool
resource "google_container_node_pool" "gke_core_nodes" {
name = "${google_container_cluster.gke_core.name}-node-pool"
location = var.zone
location = var.region
cluster = google_container_cluster.gke_core.name
node_count = var.gke_num_nodes

node_config {
preemptible = true
machine_type = var.gke_instance_type

oauth_scopes = [
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring",
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/ndev.clouddns.readwrite",
"https://www.googleapis.com/auth/service.management.readonly",
"https://www.googleapis.com/auth/servicecontrol",
"https://www.googleapis.com/auth/trace.append",
]

labels = {
env = var.project_id
}

machine_type = "n1-standard-1"
tags = ["gke-node", "${var.project_id}-gke"]
metadata = {
disable-legacy-endpoints = "true"
}
labels = {
env = var.project_id
}

}

depends_on = [resource.google_container_cluster.gke_core]
}

module "gke_auth" {
Expand All @@ -74,4 +60,4 @@ module "gke_auth" {
resource "local_file" "kubeconfig" {
content = module.gke_auth.kubeconfig_raw
filename = var.kubeconfig_output_path
}
}
18 changes: 8 additions & 10 deletions infrastructure/terraform/modules/gcp-gke/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,22 @@ variable "region" {
default = "us-central1"
description = "The region defined in gcloud config is us-central1"
}
variable "zone" {
type = string
default = "us-central1-a"
description = "The zone defined in gcloud config is us-central1-a"
}
variable "gke_num_nodes" {
default = 2
description = "number of gke nodes"
}
variable "vpc_name" {
default = "airy-core-vpc"
}
variable "public_subnets" {
type = list(string)
default = ["10.0.4.0/24", "10.0.5.0/24", "10.0.6.0/24"]
default = "airy-core-vpc"
}
variable "kubeconfig_output_path" {
type = string
default = "./kube.conf"
description = "The location of the kubeconfig file"
}
variable "gke_instance_type" {
type = string
default = "n1-standard-2"
}
variable "gke_initial_node_count" {
default = 1
}

0 comments on commit a0ee92e

Please sign in to comment.