Skip to content

Commit

Permalink
Move all terraform setup to test/terraform
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Aug 20, 2018
1 parent 90ce7e6 commit 36e8afc
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 293 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
.terraform/
.terraform.tfstate*
terraform.tfstate*
terraform.tfvars
values.dev.yaml
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ be properly cleaned up. We recommend recycling the Kubernetes cluster to
start from a clean slate.

**Note:** There is a Terraform configuration in the
[terraform/ directory](https://github.com/hashicorp/consul-k8s/tree/master/terraform)
[test/terraform/ directory](https://github.com/hashicorp/consul-helm/tree/master/test/terraform)
that can be used to quickly bring up a GKE cluster and configure
`kubectl` and `helm` locally. This can be used to quickly spin up a test
cluster.
23 changes: 0 additions & 23 deletions terraform/README.md

This file was deleted.

9 changes: 0 additions & 9 deletions terraform/main.tf

This file was deleted.

9 changes: 0 additions & 9 deletions terraform/modules/README.md

This file was deleted.

22 changes: 0 additions & 22 deletions terraform/modules/gke/README.md

This file was deleted.

45 changes: 0 additions & 45 deletions terraform/modules/gke/main.tf

This file was deleted.

4 changes: 0 additions & 4 deletions terraform/modules/gke/outputs.tf

This file was deleted.

16 changes: 0 additions & 16 deletions terraform/modules/gke/variables.tf

This file was deleted.

16 changes: 0 additions & 16 deletions terraform/modules/helm/main.tf

This file was deleted.

3 changes: 0 additions & 3 deletions terraform/modules/helm/variables.tf

This file was deleted.

6 changes: 0 additions & 6 deletions terraform/variables.tf

This file was deleted.

88 changes: 0 additions & 88 deletions test/scripts/cli-init.sh

This file was deleted.

51 changes: 0 additions & 51 deletions test/scripts/docker-init.sh

This file was deleted.

48 changes: 48 additions & 0 deletions test/terraform/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
locals {
service_account_path = "${path.module}/service-account.yaml"
}

provider "google" {
project = "${var.project}"
}
Expand All @@ -16,3 +20,47 @@ resource "google_container_cluster" "cluster" {
node_version = "${var.k8s_version}"
}

resource "null_resource" "kubectl" {
count = "${var.init_cli ? 1 : 0 }"

triggers {
cluster = "${google_container_cluster.cluster.id}"
}

# On creation, we want to setup the kubectl credentials. The easiest way
# to do this is to shell out to gcloud.
provisioner "local-exec" {
command = "gcloud container clusters get-credentials --zone=${var.zone} ${google_container_cluster.cluster.name}"
}

# On destroy we want to try to clean up the kubectl credentials. This
# might fail if the credentials are already cleaned up or something so we
# want this to continue on failure. Generally, this works just fine since
# it only operates on local data.
provisioner "local-exec" {
when = "destroy"
on_failure = "continue"
command = "kubectl config get-clusters | grep ${google_container_cluster.cluster.name} | xargs -n1 kubectl config delete-cluster"
}

provisioner "local-exec" {
when = "destroy"
on_failure = "continue"
command = "kubectl config get-contexts | grep ${google_container_cluster.cluster.name} | xargs -n1 kubectl config delete-context"
}
}

resource "null_resource" "helm" {
count = "${var.init_cli ? 1 : 0 }"

triggers {
cluster = "${google_container_cluster.cluster.id}"
}

provisioner "local-exec" {
command = <<EOF
kubectl apply -f '${local.service_account_path}'
helm init --service-account helm
EOF
}
}
File renamed without changes.
5 changes: 5 additions & 0 deletions test/terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ variable "zone" {
default = "us-central1-a"
description = "The zone to launch all the GKE nodes in."
}

variable "init_cli" {
default = false
description = "Whether to init the CLI tools kubectl, helm, etc. or not."
}

0 comments on commit 36e8afc

Please sign in to comment.