Skip to content

Commit

Permalink
add initial gke terraform
Browse files Browse the repository at this point in the history
  • Loading branch information
ciaranRoche committed Mar 20, 2019
0 parents commit f0871c8
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions .gtf-var
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# RubiX GKE Terraform

gcloud container clusters get-credentials
39 changes: 39 additions & 0 deletions gke/cluster.tf
Original file line number Diff line number Diff line change
@@ -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
}
}
8 changes: 8 additions & 0 deletions gke/gcp.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#####################################################################
# Google Cloud Platform
#####################################################################
provider "google" {
credentials = "${file("${var.credentials}")}"
project = "${var.project}"
region = "${var.region}"
}
49 changes: 49 additions & 0 deletions gke/variables.tf
Original file line number Diff line number Diff line change
@@ -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}"
}
61 changes: 61 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -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}"
}

0 comments on commit f0871c8

Please sign in to comment.