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

Fixed terraform module to use Almalinux #42

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
45 changes: 23 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,36 @@ A Terraform module to deploy and run YugabyteDB on Amazon Web Services (AWS).
to it,
```hcl
module "yugabyte-db-cluster" {
# The source module used for creating clusters on AWS.
source = "github.com/yugabyte/terraform-aws-yugabyte"
# The source module used for creating clusters on AWS.
source = "github.com/yugabyte/terraform-aws-yugabyte"

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

# Specify an existing AWS key pair
# Both the name and the path to the corresponding private key file
ssh_keypair = "SSH_KEYPAIR_NAME"
ssh_private_key = "PATH_TO_SSH_PRIVATE_KEY_FILE"
# Specify an existing AWS key pair
# Both the name and the path to the corresponding private key file
ssh_keypair = "SSH_KEYPAIR_NAME"
ssh_private_key = "PATH_TO_SSH_PRIVATE_KEY_FILE"

# The existing vpc and subnet ids where the nodes should be spawned.
region_name = "AWS REGION"
vpc_id = "VPC_ID_HERE"
# The existing vpc and subnet ids where the nodes should be spawned.
region_name = "AWS REGION"
vpc_id = "VPC_ID_HERE"

# Cluster data and metadata will be placed in separate AZs to ensure availability during single AZ failure if 3 AZs are specified.
# To tolerate single AZ failure, the AZ count should be equal to RF.
availability_zones = ["AZ1", "AZ2", "AZ3"]
subnet_ids = ["SUBNET_AZ1", SUBNET_AZ2", "SUBNET_AZ3"]
# Cluster data and metadata will be placed in separate AZs to ensure availability during single AZ failure if 3 AZs are specified.
region_name = "REGION"
# To tolerate single AZ failure, the AZ count should be equal to RF.
availability_zones = ["AZ1", "AZ2", "AZ3"]
subnet_ids = ["SUBNET_AZ1", "SUBNET_AZ2", "SUBNET_AZ3"]

# Replication factor.
replication_factor = "3"
# Replication factor.
replication_factor = "3"

# The number of nodes in the cluster, this cannot be lower than the replication factor.
num_instances = "3"
# The number of nodes in the cluster, this cannot be lower than the replication factor.
num_instances = "3"
}

output "outputs" {
value = module.yugabyte-db-cluster
value = module.yugabyte-db-cluster
}
```

Expand Down Expand Up @@ -102,7 +103,7 @@ $ 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
## Test

### Configurations

Expand All @@ -115,7 +116,7 @@ $ terraform destroy

* Sign Up for AWS.

* Configure your AWS credentials using one of the supported methods for AWS CLI tools, such as setting the `AWS_ACCESS_KEY_ID` and
* Configure your AWS credentials using one of the supported methods for AWS CLI tools, such as setting the `AWS_ACCESS_KEY_ID` and
`AWS_SECRET_ACCESS_KEY` environment variables.

* Set the following environment variables.
Expand Down
41 changes: 23 additions & 18 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# associate_public_ip_address [default: "true"]
# custom_security_group_id
# num_instances [default: 3]
#
#
#

#########################################################
Expand All @@ -30,30 +30,32 @@ terraform {
}

provider "aws" {
version = "~> 3.0"
# version = "~> 3.0"
region = var.region_name
default_tags {
tags = var.tags
}
}

data "aws_ami" "yugabyte_ami" {
count = length(var.aws-ami) == 0 ? 1 : 0
most_recent = true
owners = ["aws-marketplace"]

filter {
name = "name"
name = "name"
values = ["AlmaLinux OS 8.8.*"]
}

values = [
"CentOS Linux 7 x86_64 HVM EBS *",
]
filter {
name = "virtualization-type"
values = ["hvm"]
}
filter {
name = "architecture"
name = "architecture"
values = ["x86_64"]
}

filter {
name = "root-device-type"
values = ["ebs"]
}
owners = ["aws-marketplace"]
}

#########################################################
Expand Down Expand Up @@ -156,7 +158,7 @@ resource "aws_security_group" "yugabyte_intra" {

resource "aws_instance" "yugabyte_nodes" {
count = var.num_instances
ami = data.aws_ami.yugabyte_ami.id
ami = length(var.aws-ami) == 0 ? data.aws_ami.yugabyte_ami[0].id : var.aws-ami
associate_public_ip_address = var.associate_public_ip_address
instance_type = var.instance_type
key_name = var.ssh_keypair
Expand All @@ -181,7 +183,7 @@ resource "aws_instance" "yugabyte_nodes" {
source = "${path.module}/utilities/scripts/install_software.sh"
destination = "/home/${var.ssh_user}/install_software.sh"
connection {
host = self.public_ip
host = var.associate_public_ip_address ? self.public_ip : self.private_ip
type = "ssh"
user = var.ssh_user
private_key = file(var.ssh_private_key)
Expand All @@ -192,7 +194,7 @@ resource "aws_instance" "yugabyte_nodes" {
source = "${path.module}/utilities/scripts/create_universe.sh"
destination = "/home/${var.ssh_user}/create_universe.sh"
connection {
host = self.public_ip
host = var.associate_public_ip_address ? self.public_ip : self.private_ip
type = "ssh"
user = var.ssh_user
private_key = file(var.ssh_private_key)
Expand All @@ -203,7 +205,7 @@ resource "aws_instance" "yugabyte_nodes" {
source = "${path.module}/utilities/scripts/start_tserver.sh"
destination = "/home/${var.ssh_user}/start_tserver.sh"
connection {
host = self.public_ip
host = var.associate_public_ip_address ? self.public_ip : self.private_ip
type = "ssh"
user = var.ssh_user
private_key = file(var.ssh_private_key)
Expand All @@ -215,7 +217,7 @@ resource "aws_instance" "yugabyte_nodes" {
destination = "/home/${var.ssh_user}/start_master.sh"

connection {
host = self.public_ip
host = var.associate_public_ip_address ? self.public_ip : self.private_ip
type = "ssh"
user = var.ssh_user
private_key = file(var.ssh_private_key)
Expand All @@ -232,7 +234,7 @@ resource "aws_instance" "yugabyte_nodes" {
"/home/${var.ssh_user}/install_software.sh '${var.yb_version}'",
]
connection {
host = self.public_ip
host = var.associate_public_ip_address ? self.public_ip : self.private_ip
type = "ssh"
user = var.ssh_user
private_key = file(var.ssh_private_key)
Expand All @@ -243,6 +245,9 @@ resource "aws_instance" "yugabyte_nodes" {
create_before_destroy = true
}
}
locals {
yugabyte_node_1_ip = var.associate_public_ip_address ? aws_instance.yugabyte_nodes[0].public_ip : aws_instance.yugabyte_nodes[0].private_ip
}

#########################################################
#
Expand Down
12 changes: 6 additions & 6 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

output "master-ui" {
sensitive = false
value = "http://${aws_instance.yugabyte_nodes[0].public_ip}:7000"
value = "http://${local.yugabyte_node_1_ip}:7000"
}

output "tserver-ui" {
sensitive = false
value = "http://${aws_instance.yugabyte_nodes[0].public_ip}:9000"
value = "http://${local.yugabyte_node_1_ip}:9000"
}

output "public_ips" {
Expand Down Expand Up @@ -46,21 +46,21 @@ output "ssh_key" {

output "JDBC" {
sensitive = false
value = "postgresql://yugabyte@${aws_instance.yugabyte_nodes[0].public_ip}:5433"
value = "postgresql://yugabyte@${local.yugabyte_node_1_ip}:5433"
}

output "YSQL" {
sensitive = false
value = "ysqlsh -U yugabyte -h ${aws_instance.yugabyte_nodes[0].public_ip} -p 5433"
value = "ysqlsh -U yugabyte -h ${local.yugabyte_node_1_ip} -p 5433"
}

output "YCQL" {
sensitive = false
value = "ycqlsh ${aws_instance.yugabyte_nodes[0].public_ip} 9042"
value = "ycqlsh ${local.yugabyte_node_1_ip} 9042"
}

output "YEDIS" {
sensitive = false
value = "redis-cli -h ${aws_instance.yugabyte_nodes[0].public_ip} -p 6379"
value = "redis-cli -h ${local.yugabyte_node_1_ip} -p 6379"
}

4 changes: 4 additions & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sshkey.pem
*.tfstate
*.tfstate.backup

82 changes: 82 additions & 0 deletions test/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading