diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..14a8d26 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.tfstate* +.terraform/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..c600524 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# terraform-gke + +Launch and manage a GKE cluster using Terraform. + +## Launch GKE Cluster + +``` +$ terraform init +$ terraform plan +$ terraform apply +``` + +## Questions? + +Open an issue. diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..0d8f186 --- /dev/null +++ b/main.tf @@ -0,0 +1,40 @@ +resource "google_container_cluster" "default" { + name = "${var.name}" + project = "${var.project}" + description = "Demo GKE Cluster" + location = "${var.location}" + + remove_default_node_pool = true + initial_node_count = "${var.initial_node_count}" + + master_auth { + username = "" + password = "" + + client_certificate_config { + issue_client_certificate = false + } + } +} + +resource "google_container_node_pool" "default" { + name = "${var.name}-node-pool" + project = "${var.project}" + location = "${var.location}" + cluster = "${google_container_cluster.default.name}" + node_count = 1 + + node_config { + preemptible = true + machine_type = "${var.machine_type}" + + metadata = { + disable-legacy-endpoints = "true" + } + + oauth_scopes = [ + "https://www.googleapis.com/auth/logging.write", + "https://www.googleapis.com/auth/monitoring", + ] + } +} diff --git a/outputs.tf b/outputs.tf new file mode 100644 index 0000000..c6a7a81 --- /dev/null +++ b/outputs.tf @@ -0,0 +1,7 @@ +output "endpoint" { + value = "${google_container_cluster.default.endpoint}" +} + +output "master_version" { + value = "${google_container_cluster.default.master_version}" +} diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..af09f50 --- /dev/null +++ b/variables.tf @@ -0,0 +1,18 @@ +variable "name" { + default = "demo-cluster" +} +variable "project" { + default = "optimum-spring-238818" +} + +variable "location" { + default = "us-central1" +} + +variable "initial_node_count" { + default = 1 +} + +variable "machine_type" { + default = "n1-standard-1" +}