diff --git a/infrastructure/terraform/install/gcp-gke/README.md b/infrastructure/terraform/install/gcp-gke/README.md new file mode 100644 index 0000000000..61cdad72b0 --- /dev/null +++ b/infrastructure/terraform/install/gcp-gke/README.md @@ -0,0 +1,13 @@ +# airy.co GKS terraform installation source + +### Title + +The current referenced project link is ; + + +https://github.com/hashicorp/learn-terraform-provision-gke-cluster + +``` +$ some code +``` + diff --git a/infrastructure/terraform/install/gcp-gke/main.tf b/infrastructure/terraform/install/gcp-gke/main.tf new file mode 100644 index 0000000000..afcb6e2688 --- /dev/null +++ b/infrastructure/terraform/install/gcp-gke/main.tf @@ -0,0 +1,11 @@ +module "gcp-gke" { + #source = "github.com/airyhq/airy.git/infrastructure/terraform/modules/gcp-gke" + source = "/Users/bilge/Documents/AiryProjects/airy/infrastructure/terraform/modules/gcp-gke" + + + project_id = var.project_id + region = var.region + + + #kubeconfig_output_path = "../kube.conf" +} diff --git a/infrastructure/terraform/install/gcp-gke/outputs.tf b/infrastructure/terraform/install/gcp-gke/outputs.tf new file mode 100644 index 0000000000..e69de29bb2 diff --git a/infrastructure/terraform/install/gcp-gke/state.tf b/infrastructure/terraform/install/gcp-gke/state.tf new file mode 100644 index 0000000000..e69de29bb2 diff --git a/infrastructure/terraform/install/gcp-gke/variables.tf b/infrastructure/terraform/install/gcp-gke/variables.tf new file mode 100644 index 0000000000..f7d0acc54e --- /dev/null +++ b/infrastructure/terraform/install/gcp-gke/variables.tf @@ -0,0 +1,7 @@ +variable "project_id" { + description = "The project is airy-core-gke" +} + +variable "region" { + description = "The region is us-central1" +} \ No newline at end of file diff --git a/infrastructure/terraform/install/google/README.md b/infrastructure/terraform/install/google/README.md deleted file mode 100644 index 5634db9c8a..0000000000 --- a/infrastructure/terraform/install/google/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# airy.co GKS terraform installation source - -### Title - -description needed here. - -``` -$ some code -``` - diff --git a/infrastructure/terraform/install/google/main.tf b/infrastructure/terraform/install/google/main.tf deleted file mode 100644 index 13035fec73..0000000000 --- a/infrastructure/terraform/install/google/main.tf +++ /dev/null @@ -1,111 +0,0 @@ -module "google" { - source = "github.com/airyhq/airy.git/infrastructure/terraform/modules/google" - - #aws_profile = var.aws_profile - #aws_region = var.aws_region - - project_id = "airy-development-staging" - name = "airy-development-staging" - - - kubeconfig_output_path = "../kube.conf" - fargate_profiles = var.fargate_profiles -} - -##-----------### - -# google_client_config and kubernetes provider must be explicitly specified like the following. -data "google_client_config" "default" {} - -provider "kubernetes" { - host = "https://${module.gke.endpoint}" - token = data.google_client_config.default.access_token - cluster_ca_certificate = base64decode(module.gke.ca_certificate) -} - -module "gke" { - source = "terraform-google-modules/kubernetes-engine/google" - project_id = "airy-development-staging" - name = "airy-development-staging" - region = "us-central1" - zones = ["us-central1-a", "us-central1-b", "us-central1-f"] - network = "vpc-01" - subnetwork = "us-central1-01" - ip_range_pods = "us-central1-01-gke-01-pods" - ip_range_services = "us-central1-01-gke-01-services" - http_load_balancing = false - network_policy = false - horizontal_pod_autoscaling = true - filestore_csi_driver = false - - node_pools = [ - { - name = "default-node-pool" - machine_type = "e2-medium" - node_locations = "us-central1-b,us-central1-c" - min_count = 1 - max_count = 100 - local_ssd_count = 0 - spot = false - disk_size_gb = 100 - disk_type = "pd-standard" - image_type = "COS_CONTAINERD" - enable_gcfs = false - enable_gvnic = false - auto_repair = true - auto_upgrade = true - service_account = "project-service-account@.iam.gserviceaccount.com" - preemptible = false - initial_node_count = 80 - }, - ] - - node_pools_oauth_scopes = { - all = [] - - default-node-pool = [ - "https://www.googleapis.com/auth/cloud-platform", - ] - } - - - - - - -} - - -resource "google_service_account" "default" { - account_id = "service-account-id" - display_name = "Service Account" -} - -resource "google_container_cluster" "primary" { - name = "my-gke-cluster" - location = "us-central1" - - # We can't create a cluster with no node pool defined, but we want to only use - # separately managed node pools. So we create the smallest possible default - # node pool and immediately delete it. - remove_default_node_pool = true - initial_node_count = 1 -} - -resource "google_container_node_pool" "primary_preemptible_nodes" { - name = "my-node-pool" - location = "us-central1" - cluster = google_container_cluster.primary.name - node_count = 1 - - node_config { - preemptible = true - machine_type = "e2-medium" - - # Google recommends custom service accounts that have cloud-platform scope and permissions granted via IAM Roles. - service_account = google_service_account.default.email - oauth_scopes = [ - "https://www.googleapis.com/auth/cloud-platform" - ] - } -} \ No newline at end of file diff --git a/infrastructure/terraform/modules/gcp-gke/main.tf b/infrastructure/terraform/modules/gcp-gke/main.tf new file mode 100644 index 0000000000..b1f0fcc46f --- /dev/null +++ b/infrastructure/terraform/modules/gcp-gke/main.tf @@ -0,0 +1,61 @@ +provider "google" { + project = var.project_id + region = var.region +} + +# VPC +resource "google_compute_network" "vpc" { + name = "${var.project_id}-vpc" + auto_create_subnetworks = "false" +} + +# Subnet +resource "google_compute_subnetwork" "subnet" { + name = "${var.project_id}-subnet" + region = var.region + network = google_compute_network.vpc.name + ip_cidr_range = "10.10.0.0/24" +} + + +# GKE cluster +resource "google_container_cluster" "primary" { + name = "${var.project_id}-gke" + location = var.region + + # We can't create a cluster with no node pool defined, but we want to only use + # separately managed node pools. So we create the smallest possible default + # node pool and immediately delete it. + remove_default_node_pool = true + initial_node_count = 1 + + network = google_compute_network.vpc.name + subnetwork = google_compute_subnetwork.subnet.name +} + +# Separately Managed Node Pool +resource "google_container_node_pool" "primary_nodes" { + name = "${google_container_cluster.primary.name}-node-pool" + location = var.region + cluster = google_container_cluster.primary.name + node_count = var.gke_num_nodes + + node_config { + oauth_scopes = [ + "https://www.googleapis.com/auth/logging.write", + "https://www.googleapis.com/auth/monitoring", + ] + + labels = { + env = var.project_id + } + + # preemptible = true + machine_type = "n1-standard-1" + tags = ["gke-node", "${var.project_id}-gke"] + metadata = { + disable-legacy-endpoints = "true" + } + } +} + diff --git a/infrastructure/terraform/modules/gcp-gke/outputs.tf b/infrastructure/terraform/modules/gcp-gke/outputs.tf new file mode 100644 index 0000000000..c32493b89d --- /dev/null +++ b/infrastructure/terraform/modules/gcp-gke/outputs.tf @@ -0,0 +1,22 @@ +output "kubernetes_endpoint" { + sensitive = true + value = module.gke_auth.host +} + +output "client_token" { + sensitive = true + value = module.gke_auth.token +} + +output "ca_certificate" { + value = module.gke_auth.cluster_ca_certificate +} + +output "kubeconfig_raw" { + value = module.gke_auth.kubeconfig_raw +} + +output "service_account" { + description = "The default service account used for running nodes." + value = module.gke.service_account +} \ No newline at end of file diff --git a/infrastructure/terraform/modules/gcp-gke/variables.tf b/infrastructure/terraform/modules/gcp-gke/variables.tf new file mode 100644 index 0000000000..e3be893cd8 --- /dev/null +++ b/infrastructure/terraform/modules/gcp-gke/variables.tf @@ -0,0 +1,22 @@ +variable "project_id" { + description = "The project is airy-core-gke" +} + +variable "region" { + description = "The region is us-central1" +} + +variable "gke_username" { + default = "" + description = "gke username" +} + +variable "gke_password" { + default = "" + description = "gke password" +} + +variable "gke_num_nodes" { + default = 2 + description = "number of gke nodes" +}