Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ WIP ]Added Terratest Plan #6

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
08d1ea9
Update the output and updated the script to support the latest versio…
Sep 24, 2019
4378548
Added Terratest cases
Sep 26, 2019
8bd1f45
Updated the new test cases and restructure code
Oct 9, 2019
3c36d01
Updated the README.md file with instruction to run the test
Oct 18, 2019
4f9a07c
Create go.yml
vaibhavp Jan 15, 2020
5b52519
Create ci.yml
vaibhavp Jan 15, 2020
e31563b
Update go.yml
vaibhavp Jan 15, 2020
c19a9ba
Merge branch 'master' of https://github.com/vp15591/terraform-gcp-yug…
Jan 15, 2020
5cfbb22
Merge branch 'ci' of https://github.com/vp15591/terraform-gcp-yugabyt…
Jan 15, 2020
537f205
Updated the workflow
Jan 15, 2020
a457321
Updated working directory in workflow
vaibhavp Jan 15, 2020
3585593
Update go.yml
vaibhavp Jan 15, 2020
e2e5986
Update go.yml
vaibhavp Jan 15, 2020
89f09f5
Update go.yml
vaibhavp Jan 15, 2020
3368f6f
Gopack related file removed
Jan 15, 2020
45968a3
Merge branch 'test-plan' of https://github.com/vp15591/terraform-gcp-…
Jan 15, 2020
93888ab
Update go.yml
vaibhavp Jan 15, 2020
1902515
Update go.yml
vaibhavp Jan 15, 2020
06cba3c
Update go.yml
vaibhavp Jan 15, 2020
56b5936
Update go.yml
vaibhavp Jan 15, 2020
3898d86
Update go.yml
vaibhavp Jan 16, 2020
792761b
Update go.yml
vaibhavp Jan 16, 2020
f976be2
Update go.yml
vaibhavp Jan 16, 2020
990481d
Update go.yml
vaibhavp Jan 16, 2020
d81a12b
Update go.yml
vaibhavp Jan 16, 2020
96d79c3
Update go.yml
vaibhavp Jan 16, 2020
70748e3
Update go.yml
vaibhavp Jan 16, 2020
b679d82
Update go.yml
vaibhavp Jan 16, 2020
cca6653
Update go.yml
vaibhavp Jan 16, 2020
c0293ff
Update go.yml
vaibhavp Jan 16, 2020
2b0f211
Update go.yml
vaibhavp Jan 16, 2020
025098d
Update go.yml
vaibhavp Jan 16, 2020
fcf392d
Update go.yml
vaibhavp Jan 16, 2020
b0acc61
Updated test code to user env variable
Jan 16, 2020
269364b
Updated env variable
Jan 16, 2020
ff1f55c
Update go.yml
vaibhavp Jan 16, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: continuous-integration
on: [push]
jobs:

build:
name: Build
runs-on: ubuntu-latest
env:
GCP_KEY: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
GOOGLE_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}

steps:
- name: Google Cloud Platform (GCP) CLI - gcloud
uses: actions-hub/[email protected]
env:
# Project id
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
# GCP authorization credentials
APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
with:
args: auth list

- name: Set up Go 1.13
uses: actions/setup-go@v1
with:
go-version: 1.13.5
id: go

- name: Setup Terraform environment
uses: marocchino/[email protected]
with:
# The terraform version to download (if necessary) and use. Example: 0.12.13
version: 0.12.13

- name: Check out code into the Go module directory
uses: actions/checkout@v1
with:
submodules: true

- name: Get dependencies
run: |
cd ./test
go mod download

- name: Build
run: |
echo "$GCP_KEY" | base64 -d > /tmp/account.json
export GOOGLE_APPLICATION_CREDENTIALS="/tmp/account.json"
cd ./test
go test -v -timeout 90m yugabyte_test.go
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "utilities"]
path = utilities
url = https://github.com/YugaByte/utilities.git
branch = master
59 changes: 42 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,21 @@
A Terraform module to deploy and run YugaByte on Google Cloud.

## Config
* First create a terraform file with provider details
```
provider "google"
{
# Provide your GCP Creadentilals
credentials = "${file("yugabyte-pcf-bc8114281026.json")}"

# The name of your GCP project
project = "yugabyte-pcf"
}
```
Note :- You can get credentials file by following steps given [here](https://cloud.google.com/docs/authentication/getting-started)

* Now add the yugabyte terraform module to your file
* First create a terraform file and add the yugabyte terraform module to your file
```
module "yugabyte-db-cluster" {
source = "github.com/YugaByte/terraform-gcp-yugabyte.git"

# Your GCP project id
project_id = "<YOUR-GCP-PROJECT-ID>"

# Your GCP credentials file path
credentials = "<PATH-OF-YOUR-GCP-CREDENTIAL-FILE>"

# The name of the cluster to be created.
cluster_name = "test-yugabyte"

# key pair.
ssh_private_key = "SSH_PRIVATE_KEY_HERE"
ssh_public_key = "SSH_PUBLIC_KEY_HERE"
# User name for ssh connection
ssh_user = "SSH_USER_NAME_HERE"

# The region name where the nodes should be spawned.
Expand All @@ -38,6 +29,7 @@ A Terraform module to deploy and run YugaByte on Google Cloud.
node_count = "3"
}
```
Note:- You can get credentials file by following steps given [here](https://cloud.google.com/docs/authentication/getting-started)


## Usage
Expand Down Expand Up @@ -81,3 +73,36 @@ To destroy what we just created, you can run the following command.
$ terraform destroy
```
`Note:- To make any changes in the created cluster you will need the terraform state files. So don't delete state files of Terraform.`

## Test

### Configurations

#### Prerequisites

- [Terraform **(~> 0.12.5)**](https://www.terraform.io/downloads.html)
- [Golang **(~> 1.12.10)**](https://golang.org/dl/)
- [dep **(~> 0.5.4)**](https://github.com/golang/dep)

#### Environment setup

* First install `dep` dependency management tool for Go.
```sh
$ curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
```
* Change your working directory to the `test` folder.
* Run `dep` command to get required modules
```sh
$ dep ensure
```

#### Run test

Then simply run it in the local shell:

```sh
$ go test -v -timeout 15m yugabyte_test.go
```
* Note that go has a default test timeout of 10 minutes. With infrastructure testing, your tests will surpass the 10 minutes very easily. To extend the timeout, you can pass in the -timeout option, which takes a go duration string (e.g 10m for 10 minutes or 1h for 1 hour). In the above command, we use the -timeout option to override to a 90 minute timeout.
* When you hit the timeout, Go automatically exits the test, skipping all cleanup routines. This is problematic for infrastructure testing because it will skip your deferred infrastructure cleanup steps (i.e terraform destroy), leaving behind the infrastructure that was spun up. So it is important to use a longer timeout every time you run the tests.

41 changes: 32 additions & 9 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@

terraform {
required_version = ">= 0.12"
}

provider "google" {
credentials = "${file(var.credentials)}"
project = var.project_id
}

data "google_compute_image" "YugaByte_DB_Image" {
family = "centos-6"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should do this test on a few OS's - such as ad Ubuntu and others. We can not assume the end-user will always use Ubuntu. I think Github action allows you to run the same workflow for a combination of OS - I would suggest exploring that.

project = "centos-cloud"
Expand All @@ -7,6 +16,15 @@ data "google_compute_zones" "available" {
region = "${var.region_name}"
}

resource "tls_private_key" "example" {
algorithm = "RSA"
}

resource "local_file" "foo" {
content = "${tls_private_key.example.private_key_pem}"
filename = "${path.module}/foo"
file_permission = "0600"
}
resource "google_compute_firewall" "YugaByte-Firewall" {
name = "${var.vpc_firewall}-${var.prefix}${var.cluster_name}-firewall"
network = "${var.vpc_network}"
Expand Down Expand Up @@ -39,8 +57,8 @@ resource "google_compute_instance" "yugabyte_node" {
size = "${var.disk_size}"
}
}
metadata {
sshKeys = "${var.ssh_user}:${file(var.ssh_public_key)}"
metadata = {
sshKeys = "${var.ssh_user}:${tls_private_key.example.public_key_openssh}"
}

network_interface{
Expand All @@ -54,37 +72,41 @@ resource "google_compute_instance" "yugabyte_node" {
source = "${path.module}/utilities/scripts/install_software.sh"
destination = "/home/${var.ssh_user}/install_software.sh"
connection {
host = "${self.network_interface.0.access_config.0.nat_ip}"
type = "ssh"
user = "${var.ssh_user}"
private_key = "${file(var.ssh_private_key)}"
private_key = "${tls_private_key.example.private_key_pem}"
}
}

provisioner "file" {
source = "${path.module}/utilities/scripts/create_universe.sh"
destination ="/home/${var.ssh_user}/create_universe.sh"
connection {
host = "${self.network_interface.0.access_config.0.nat_ip}"
type = "ssh"
user = "${var.ssh_user}"
private_key = "${file(var.ssh_private_key)}"
private_key = "${tls_private_key.example.private_key_pem}"
}
}
provisioner "file" {
source = "${path.module}/utilities/scripts/start_master.sh"
destination ="/home/${var.ssh_user}/start_master.sh"
connection {
host = "${self.network_interface.0.access_config.0.nat_ip}"
type = "ssh"
user = "${var.ssh_user}"
private_key = "${file(var.ssh_private_key)}"
private_key = "${tls_private_key.example.private_key_pem}"
}
}
provisioner "file" {
source = "${path.module}/utilities/scripts/start_tserver.sh"
destination ="/home/${var.ssh_user}/start_tserver.sh"
connection {
host = "${self.network_interface.0.access_config.0.nat_ip}"
type = "ssh"
user = "${var.ssh_user}"
private_key = "${file(var.ssh_private_key)}"
private_key = "${tls_private_key.example.private_key_pem}"
}
}
provisioner "remote-exec" {
Expand All @@ -93,12 +115,13 @@ resource "google_compute_instance" "yugabyte_node" {
"chmod +x /home/${var.ssh_user}/create_universe.sh",
"chmod +x /home/${var.ssh_user}/start_tserver.sh",
"chmod +x /home/${var.ssh_user}/start_master.sh",
"/home/${var.ssh_user}/install_software.sh '${var.yb_edition}' '${var.yb_version}' '${var.yb_download_url}'"
"/home/${var.ssh_user}/install_software.sh '${var.yb_version}'"
]
connection {
host = "${self.network_interface.0.access_config.0.nat_ip}"
type = "ssh"
user = "${var.ssh_user}"
private_key = "${file(var.ssh_private_key)}"
private_key = "${tls_private_key.example.private_key_pem}"
}
}
}
Expand All @@ -114,7 +137,7 @@ resource "null_resource" "create_yugabyte_universe" {
depends_on = ["google_compute_instance.yugabyte_node"]

provisioner "local-exec" {
command = "${path.module}/utilities/scripts/create_universe.sh 'GCP' '${var.region_name}' ${var.replication_factor} '${local.config_ip_list}' '${local.ssh_ip_list}' '${local.zone}' '${var.ssh_user}' ${var.ssh_private_key}"
command = "${path.module}/utilities/scripts/create_universe.sh 'GCP' '${var.region_name}' ${var.replication_factor} '${local.config_ip_list}' '${local.ssh_ip_list}' '${local.zone}' '${var.ssh_user}' ${local_file.foo.filename}"
}
}

36 changes: 34 additions & 2 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,39 @@ output "ui" {
sensitive = false
value = "http://${google_compute_instance.yugabyte_node.0.network_interface.0.access_config.0.nat_ip}:7000"
}
output "ssh_key" {
#output "ssh_user" {
# sensitive = false
# value = "${var.ssh_user}"
#}
#output "ssh_key" {
# sensitive = false
# value = "${var.ssh_private_key}"
#}

output "JDBC" {
sensitive =false
value = "postgresql://postgres@${google_compute_instance.yugabyte_node.0.network_interface.0.access_config.0.nat_ip}:5433"
}

output "YSQL"{
sensitive = false
value = "psql -U postgres -h ${google_compute_instance.yugabyte_node.0.network_interface.0.access_config.0.nat_ip} -p 5433"
}

output "YCQL"{
sensitive = false
value = "${var.ssh_private_key}"
value = "cqlsh ${google_compute_instance.yugabyte_node.0.network_interface.0.access_config.0.nat_ip} 9042"
}

output "YEDIS"{
sensitive = false
value = "redis-cli -h ${google_compute_instance.yugabyte_node.0.network_interface.0.access_config.0.nat_ip} -p 6379"
}

output "instance-ip"{
value = "${google_compute_instance.yugabyte_node.*.network_interface.0.access_config.0.nat_ip}"
}

output "hosts"{
value = "${google_compute_instance.yugabyte_node.*.name}"
}
5 changes: 5 additions & 0 deletions test/DirectoryList
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
create_universe.sh
install_software.sh
start_master.sh
start_tserver.sh
yugabyte-db
9 changes: 9 additions & 0 deletions test/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module terraform-gcp-yugabyte/test

go 1.13

require (
github.com/Pallinder/go-randomdata v1.2.0
github.com/gruntwork-io/terratest v0.23.4
github.com/stretchr/testify v1.4.0
)
Loading