From f0871c8d5f435d9671b96bca887b8d074074f516 Mon Sep 17 00:00:00 2001 From: ciaranRoche Date: Wed, 20 Mar 2019 17:31:06 +0000 Subject: [PATCH] add initial gke terraform --- .gitignore | 22 +++++++++++++++++ .gtf-var | 10 ++++++++ README.md | 3 +++ gke/cluster.tf | 39 +++++++++++++++++++++++++++++++ gke/gcp.tf | 8 +++++++ gke/variables.tf | 49 ++++++++++++++++++++++++++++++++++++++ main.tf | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 192 insertions(+) create mode 100644 .gitignore create mode 100644 .gtf-var create mode 100644 README.md create mode 100644 gke/cluster.tf create mode 100644 gke/gcp.tf create mode 100644 gke/variables.tf create mode 100644 main.tf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..52ceb3a --- /dev/null +++ b/.gitignore @@ -0,0 +1,22 @@ +# Local .terraform directories +**/.terraform/* + +# .tfstate files +*.tfstate +*.tfstate.* + +# Crash log files +crash.log + +# Ignore any .tfvars files that are generated automatically for each Terraform run. Most +# .tfvars files are managed as part of configuration and so should be included in +# version control. +# +# example.tfvars + +# Ignore override files as they are usually used to override resources locally and so +# are not checked in +override.tf +override.tf.json +*_override.tf +*_override.tf.json diff --git a/.gtf-var b/.gtf-var new file mode 100644 index 0000000..7554b00 --- /dev/null +++ b/.gtf-var @@ -0,0 +1,10 @@ +export TF_VAR_project=r3x-showcase-42 +export PROJECT=r3x-showcase-42 +export TF_VAR_region=europe-west2 +export TF_VAR_credentials=/Users/ciaranroche/.gcd/rubix.json +export TF_VAR_cluster_name=rubix-cluster +export CLUSTER_NAME=rubix-cluster +export TF_VAR_cluster_zone=europe-west2-a +export CLUSTER_ZONE=europe-west2-a +export TF_VAR_node_pool_name=rubix-node-pool +export TF_VAR_node_pool_zone=europe-west2-a \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..6ae438f --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# RubiX GKE Terraform + +gcloud container clusters get-credentials \ No newline at end of file diff --git a/gke/cluster.tf b/gke/cluster.tf new file mode 100644 index 0000000..26f306a --- /dev/null +++ b/gke/cluster.tf @@ -0,0 +1,39 @@ +##################################################################### +# GKE Cluster +##################################################################### +resource "google_container_cluster" "rubix" { + name = "${var.cluster_name}" + zone = "${var.cluster_zone}" + initial_node_count = "${var.gcp_cluster_count}" + + node_config { + oauth_scopes = [ + "service-control", + "service-management", + "compute-rw", + "storage-ro", + "cloud-platform", + "logging-write", + "monitoring-write", + "pubsub", + "datastore" + ] + labels { + this-is-for = "dev-cluster" + } + tags = ["dev"] + machine_type = "n1-standard-4" + } +} +resource "google_container_node_pool" "rubix" { + name = "${var.node_pool_name}" + zone = "${var.node_pool_zone}" + cluster = "${google_container_cluster.rubix.name}" + autoscaling { + min_node_count = 1 + max_node_count = 10 + } + management { + auto_repair = true + } +} \ No newline at end of file diff --git a/gke/gcp.tf b/gke/gcp.tf new file mode 100644 index 0000000..03bf73c --- /dev/null +++ b/gke/gcp.tf @@ -0,0 +1,8 @@ +##################################################################### +# Google Cloud Platform +##################################################################### +provider "google" { + credentials = "${file("${var.credentials}")}" + project = "${var.project}" + region = "${var.region}" +} \ No newline at end of file diff --git a/gke/variables.tf b/gke/variables.tf new file mode 100644 index 0000000..e335fed --- /dev/null +++ b/gke/variables.tf @@ -0,0 +1,49 @@ +##################################################################### +# General Variables +##################################################################### +variable "project" { + type = "string" + description = "Project name." +} +variable "region" { + type = "string" + description = "Region name." +} +variable "credentials" { + type = "string" + description = "Location of GCP credentials." +} + +##################################################################### +# GCP Variables +##################################################################### +variable "gcp_cluster_count" { + type = "string" + description = "Count of cluster instances to start." +} +variable "cluster_name" { + type = "string" + description = "Cluster name for the GCP Cluster." +} +variable "cluster_zone" { + type = "string" + description = "Cluster zone for the GCP Cluster." +} +variable "node_pool_name" { + type = "string" + description = "Node pool name for the GCP Cluster." +} +variable "node_pool_zone" { + type = "string" + description = "Node pool zone for the GCP Cluster." +} + +##################################################################### +# GCP Outputs +##################################################################### +output "gcp_cluster_name" { + value = "${google_container_cluster.rubix.name}" +} +output "host" { + value = "${google_container_cluster.rubix.endpoint}" +} \ No newline at end of file diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..15e83d4 --- /dev/null +++ b/main.tf @@ -0,0 +1,61 @@ +##################################################################### +# Variables +##################################################################### +variable "project" { + type = "string" + description = "Project name." +} +variable "region" { + type = "string" + description = "Region name." +} +variable "credentials" { + type = "string" + description = "Location of GCP credentials." +} +variable "gcp_cluster_count" { + type = "string" + description = "Count of cluster instances to start." + default = 1 +} +variable "cluster_name" { + type = "string" + description = "Cluster name for the GCP Cluster." +} +variable "cluster_zone" { + type = "string" + description = "Cluster zone for the GCP Cluster." +} +variable "node_pool_name" { + type = "string" + description = "Node pool name for the GCP Cluster." +} +variable "node_pool_zone" { + type = "string" + description = "Node pool zone for the GCP Cluster." +} + +##################################################################### +# Outputs +##################################################################### +output "gcp_cluster_endpoint" { + value = "${module.gke.host}" +} +output "gcp_cluster_name" { + value = "${module.gke.gcp_cluster_name}" +} + +##################################################################### +# Modules +##################################################################### +module "gke" { + source = "./gke" + project = "${var.project}" + region = "${var.region}" + credentials = "${var.credentials}" + gcp_cluster_count = "${var.gcp_cluster_count}" + cluster_name = "${var.cluster_name}" + cluster_zone = "${var.cluster_zone}" + node_pool_name = "${var.node_pool_name}" + node_pool_zone = "${var.node_pool_zone}" +} \ No newline at end of file