-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from YugaByte/development
Terraform module for GCP
- Loading branch information
Showing
6 changed files
with
293 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "utilities"] | ||
path = utilities | ||
url = https://github.com/YugaByte/utilities.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,83 @@ | ||
# terraform-gcp-yugabyte | ||
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 | ||
``` | ||
module "yugabyte-db-cluster" { | ||
source = "github.com/YugaByte/terraform-gcp-yugabyte.git" | ||
# 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" | ||
ssh_user = "SSH_USER_NAME_HERE" | ||
# The region name where the nodes should be spawned. | ||
region_name = "YOUR VPC REGION" | ||
# Replication factor. | ||
replication_factor = "3" | ||
# The number of nodes in the cluster, this cannot be lower than the replication factor. | ||
node_count = "3" | ||
} | ||
``` | ||
|
||
|
||
## Usage | ||
|
||
Init terraform first if you have not already done so. | ||
|
||
``` | ||
$ terraform init | ||
``` | ||
|
||
To check what changes are going to happen in the environment run the following | ||
|
||
``` | ||
$ terraform plan | ||
``` | ||
|
||
|
||
Now run the following to create the instances and bring up the cluster. | ||
|
||
``` | ||
$ terraform apply | ||
``` | ||
|
||
Once the cluster is created, you can go to the URL `http://<node ip or dns name>:7000` to view the UI. You can find the node's ip or dns by running the following: | ||
|
||
``` | ||
terraform state show google_compute_instance.yugabyte_node[0] | ||
``` | ||
|
||
You can access the cluster UI by going to any of the following URLs. | ||
|
||
You can check the state of the nodes at any point by running the following command. | ||
|
||
``` | ||
$ terraform show | ||
``` | ||
|
||
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.` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
|
||
data "google_compute_image" "YugaByte_DB_Image" { | ||
family = "centos-6" | ||
project = "centos-cloud" | ||
} | ||
data "google_compute_zones" "available" { | ||
region = "${var.region_name}" | ||
} | ||
|
||
resource "google_compute_firewall" "YugaByte-Firewall" { | ||
name = "${var.vpc_firewall}-${var.prefix}${var.cluster_name}-firewall" | ||
network = "${var.vpc_network}" | ||
allow { | ||
protocol = "tcp" | ||
ports = ["9000","7000","6379","9042","5433","22"] | ||
} | ||
target_tags = ["${var.prefix}${var.cluster_name}"] | ||
} | ||
resource "google_compute_firewall" "YugaByte-Intra-Firewall" { | ||
name = "${var.vpc_firewall}-${var.prefix}${var.cluster_name}-intra-firewall" | ||
network = "${var.vpc_network}" | ||
allow { | ||
protocol = "tcp" | ||
ports = ["7100", "9100"] | ||
} | ||
target_tags = ["${var.prefix}${var.cluster_name}"] | ||
} | ||
|
||
resource "google_compute_instance" "yugabyte_node" { | ||
count = "${var.node_count}" | ||
name = "${var.prefix}${var.cluster_name}-n${format("%d", count.index + 1)}" | ||
machine_type = "${var.node_type}" | ||
zone = "${element(data.google_compute_zones.available.names, count.index)}" | ||
tags=["${var.prefix}${var.cluster_name}"] | ||
|
||
boot_disk{ | ||
initialize_params { | ||
image = "${data.google_compute_image.YugaByte_DB_Image.self_link}" | ||
size = "${var.disk_size}" | ||
} | ||
} | ||
metadata { | ||
sshKeys = "${var.ssh_user}:${file(var.ssh_public_key)}" | ||
} | ||
|
||
network_interface{ | ||
network = "${var.vpc_network}" | ||
access_config { | ||
// external ip to instance | ||
} | ||
} | ||
|
||
provisioner "file" { | ||
source = "${path.module}/utilities/scripts/install_software.sh" | ||
destination = "/home/${var.ssh_user}/install_software.sh" | ||
connection { | ||
type = "ssh" | ||
user = "${var.ssh_user}" | ||
private_key = "${file(var.ssh_private_key)}" | ||
} | ||
} | ||
|
||
provisioner "file" { | ||
source = "${path.module}/utilities/scripts/create_universe.sh" | ||
destination ="/home/${var.ssh_user}/create_universe.sh" | ||
connection { | ||
type = "ssh" | ||
user = "${var.ssh_user}" | ||
private_key = "${file(var.ssh_private_key)}" | ||
} | ||
} | ||
provisioner "file" { | ||
source = "${path.module}/utilities/scripts/start_master.sh" | ||
destination ="/home/${var.ssh_user}/start_master.sh" | ||
connection { | ||
type = "ssh" | ||
user = "${var.ssh_user}" | ||
private_key = "${file(var.ssh_private_key)}" | ||
} | ||
} | ||
provisioner "file" { | ||
source = "${path.module}/utilities/scripts/start_tserver.sh" | ||
destination ="/home/${var.ssh_user}/start_tserver.sh" | ||
connection { | ||
type = "ssh" | ||
user = "${var.ssh_user}" | ||
private_key = "${file(var.ssh_private_key)}" | ||
} | ||
} | ||
provisioner "remote-exec" { | ||
inline = [ | ||
"chmod +x /home/${var.ssh_user}/install_software.sh", | ||
"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}'" | ||
] | ||
connection { | ||
type = "ssh" | ||
user = "${var.ssh_user}" | ||
private_key = "${file(var.ssh_private_key)}" | ||
} | ||
} | ||
} | ||
|
||
locals { | ||
depends_on = ["google_compute_instance.yugabyte_node"] | ||
ssh_ip_list = "${var.use_public_ip_for_ssh == "true" ? join(" ",google_compute_instance.yugabyte_node.*.network_interface.0.access_config.0.nat_ip) : join(" ",google_compute_instance.yugabyte_node.*.network_interface.0.network_ip)}" | ||
config_ip_list = "${join(" ",google_compute_instance.yugabyte_node.*.network_interface.0.network_ip)}" | ||
zone = "${join(" ", google_compute_instance.yugabyte_node.*.zone)}" | ||
} | ||
|
||
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}" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
output "ui" { | ||
sensitive = false | ||
value = "http://${google_compute_instance.yugabyte_node.0.network_interface.0.access_config.0.nat_ip}:7000" | ||
} | ||
output "ssh_key" { | ||
sensitive = false | ||
value = "${var.ssh_private_key}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
variable "cluster_name" { | ||
description = "The name for the cluster (universe) being created." | ||
type = "string" | ||
} | ||
variable "use_public_ip_for_ssh" { | ||
description = "Flag to control use of public or private ips for ssh." | ||
default = "true" | ||
type = "string" | ||
} | ||
variable "replication_factor" { | ||
description = "The replication factor for the universe." | ||
default = 3 | ||
type = "string" | ||
} | ||
variable "node_count" { | ||
description = "The number of nodes to create YugaByte Db Cluter" | ||
default = 3 | ||
type = "string" | ||
} | ||
variable "vpc_network" { | ||
description = "VPC network to deploy YugaByte DB" | ||
default = "default" | ||
type = "string" | ||
} | ||
variable "vpc_firewall" { | ||
description = "Firewall used by the YugaByte Node" | ||
default = "default" | ||
type = "string" | ||
} | ||
variable "ssh_private_key" { | ||
description = "The private key to use when connecting to the instances." | ||
type = "string" | ||
} | ||
variable "ssh_public_key" { | ||
description = "SSH public key to be use when creating the instances." | ||
type = "string" | ||
} | ||
variable "ssh_user" { | ||
description = "User name to ssh YugaByte Node to configure cluster" | ||
type = "string" | ||
} | ||
variable "node_type" { | ||
description = "Type of Node to be used for YugaByte DB node " | ||
default = "n1-standard-4" | ||
type = "string" | ||
} | ||
variable "yb_edition" { | ||
description = "The edition of YugaByteDB to install" | ||
default = "ce" | ||
type = "string" | ||
} | ||
|
||
variable "yb_download_url" { | ||
description = "The download location of the YugaByteDB edition" | ||
default = "https://downloads.yugabyte.com" | ||
type = "string" | ||
} | ||
|
||
variable "yb_version" { | ||
description = "The version number of YugaByteDB to install" | ||
default = "1.2.8.0" | ||
type = "string" | ||
} | ||
|
||
variable "region_name" { | ||
description = "Region name for GCP" | ||
default = "us-west1" | ||
type = "string" | ||
} | ||
variable "disk_size" { | ||
description = "Disk size for YugaByte DB nodes" | ||
default = "50" | ||
type = "string" | ||
} | ||
variable "prefix" { | ||
description = "Prefix prepended to all resources created." | ||
default = "yugabyte-" | ||
type = "string" | ||
} |