diff --git a/infrastructure/terraform/install/gcp-gke/main.tf b/infrastructure/terraform/install/gcp-gke/main.tf index 357f9ff848..f899cc0037 100644 --- a/infrastructure/terraform/install/gcp-gke/main.tf +++ b/infrastructure/terraform/install/gcp-gke/main.tf @@ -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 } diff --git a/infrastructure/terraform/install/gcp-gke/variables.tf b/infrastructure/terraform/install/gcp-gke/variables.tf index ebb401025c..45c07cba57 100644 --- a/infrastructure/terraform/install/gcp-gke/variables.tf +++ b/infrastructure/terraform/install/gcp-gke/variables.tf @@ -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" } \ No newline at end of file diff --git a/infrastructure/terraform/modules/gcp-gke/main.tf b/infrastructure/terraform/modules/gcp-gke/main.tf index c0257224bd..7fec0c2d7f 100644 --- a/infrastructure/terraform/modules/gcp-gke/main.tf +++ b/infrastructure/terraform/modules/gcp-gke/main.tf @@ -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" { @@ -74,4 +60,4 @@ module "gke_auth" { resource "local_file" "kubeconfig" { content = module.gke_auth.kubeconfig_raw filename = var.kubeconfig_output_path -} +} \ No newline at end of file diff --git a/infrastructure/terraform/modules/gcp-gke/variables.tf b/infrastructure/terraform/modules/gcp-gke/variables.tf index 19b66ffdfc..98ebca3b59 100644 --- a/infrastructure/terraform/modules/gcp-gke/variables.tf +++ b/infrastructure/terraform/modules/gcp-gke/variables.tf @@ -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 } \ No newline at end of file