Skip to content

Commit

Permalink
fix test bug, add document
Browse files Browse the repository at this point in the history
  • Loading branch information
smalltown committed Mar 27, 2019
1 parent b1dd596 commit b1a3056
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
76 changes: 76 additions & 0 deletions examples/elastikube-cluster/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Elastikube Cluster Example

This folder contains a simple Terraform module that deploys resources in [AWS](https://aws.amazon.com/) to demonstrate
how you can use Terratest to write automated tests for your AWS Terraform code. This module deploys AWS VPC with bastion hot, self-hosted Kubernetes with two worker group (spot and on demand instance) [EC2
Instances](https://aws.amazon.com/ec2/) in the AWS region specified in
the `aws_region` variable.

Check out [test/elastikube_cluster_test.go](/test/elastikube_cluster_test.go) to see how you can write
automated tests for this module.

**WARNING**: This module and the automated tests for it deploy real resources into your AWS account which can cost you
money.





## Running this module manually

1. Sign up for [AWS](https://aws.amazon.com/).
2. Configure your AWS credentials using one of the [supported methods for AWS CLI
tools](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html), such as setting the
`AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables. If you're using the `~/.aws/config` file for profiles then export `AWS_SDK_LOAD_CONFIG` as "True".
3. Install [Terraform](https://www.terraform.io/) and make sure it's on your `PATH`.

4. Execute below command to setup
```
# initial for sync terraform module and install provider plugins
~$ terraform init
# create the network infrastructure
~$ terraform apply -target=module.network
# create the kubernetes master compoment
~$ terraform apply -target=module.kubernetes
# create the general and spot k8s worker group
~$ terraform apply
```
5. When you're done, execute below command to destroy
```
$ terraform destroy -target=module.worker_spot
$ terraform destroy -target=module.worker_general
$ terraform destroy -target=module.kubernetes
$ terraform destroy -target=module.network
```
## Running automated tests against this module
0. Perform the testing in the AWS EC2, instead of desktop, due to this module create many AWS resource, it takes time to destroy. Executing in the AWS EC2 decrease the risk to fail to teardown
1. Sign up for [AWS](https://aws.amazon.com/).
2. Configure your AWS credentials using one of the [supported methods for AWS CLI
tools](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html), such as setting the
`AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables. If you're using the `~/.aws/config` file for profiles then export `AWS_SDK_LOAD_CONFIG` as "True".
3. Install [Terraform](https://www.terraform.io/) and make sure it's on your `PATH`.
4. Install [Golang](https://golang.org/) and make sure this code is checked out into your `GOPATH`.
5. Install [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) and make sure it's on your `PATH`.
6. `cd test`
7. `dep ensure`
8. `go test -timeout 60m -v -run TestElastikubeCluster`
9. if execution without error, the output like below
```
...
agent.go:114: Generating SSH Agent with given KeyPair(s)
agent.go:68: could not serve ssh agent read unix /tmp/ssh-agent-589722746/ssh_auth.sock->@: use of closed network connection
PASS
ok github.com/vishwakarma/test 1223.186s
```
2 changes: 1 addition & 1 deletion examples/elastikube-cluster/variables.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
variable "aws_region" {
type = "string"
default = "us-east-1"
default = "us-west-2"
description = "(Optional) The AWS region"
}

Expand Down
3 changes: 2 additions & 1 deletion test/elastikube_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ func TestElastikubeCluster(t *testing.T) {

keyPair := test_structure.LoadEc2KeyPair(t, exampleFolder)
aws.DeleteEC2KeyPair(t, keyPair)
test_structure.CleanupTestData(t, exampleFolder)
testData := fmt.Sprintf("%s/.test-data", exampleFolder)
os.Remove(testData)
})

// Deploy the example
Expand Down

0 comments on commit b1a3056

Please sign in to comment.