Apache ShardingSphere Terraform Module
A terraform module to create an Apache ShardingSphere Proxy Cluster on AWS.
Terraform will create a cluster with the following architecture:
![](./arch/arch.jpg)
- Terraform CLI
- AWS Resource
- AK/SK for accessing AWS API
- A internal domain name, default is
shardingsphere.org
- A list of Subnet IDs to launch the instance(s)
- A SecurityGroup which allow ports 2888, 3888, and 2181 of the zookeeper server to pass through.
- A ssh keypair
Step1: Edit main.tf
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "4.37.0"
}
}
}
provider "aws" {
region = "ap-southeast-1"
}
module "zk" {
source = "./zk"
cluster_size = 3
key_name = "test-tf"
instance_type = "t2.nano"
vpc_id = "vpc-0ef2b7440d3ade8d5"
subnet_ids = ["subnet-0f388a6f23063b8c9", "subnet-0bc2cd85facb5ca06", "subnet-009077567350ef1b7"]
security_groups = ["sg-008e74936b3f9de19"]
}
module "shardingsphere" {
depends_on = [module.zk]
source = "./shardingsphere"
cluster_size = 3
shardingsphere_version = "5.2.1"
key_name = "test-tf"
image_id = "ami-094bbd9e922dc515d"
instance_type = "t3.medium"
lb_listener_port = 3307
vpc_id = "vpc-0ef2b7440d3ade8d5"
subnet_ids = ["subnet-0f388a6f23063b8c9", "subnet-0bc2cd85facb5ca06", "subnet-009077567350ef1b7"]
security_groups = ["sg-008e74936b3f9de19"]
zk_servers = module.zk.zk_node_domain
}
Step2: Set environments for AK/SK
export AWS_ACCESS_KEY_ID="accesskey"
export AWS_SECRET_ACCESS_KEY="secretkey"
Step3: Initial Terraform working directory
Step4: Run the command terraform plan
to generates a execution plan.
Step5: Run the command terraform apply
to crates your defined infrastructure.
By default, Terraform will create a domain proxy.[ZONE NAME]
is used by other services.
If you want to delete, you can run the command terraform destroy
, Terraform will destroy your defined infrastructure.
Name |
Description |
Type |
Default |
Required |
cluster_size |
The cluster size that same size as available_zones |
number |
n/a |
yes |
hosted_zone_name |
The name of the hosted private zone |
string |
"shardingsphere.org" |
no |
instance_type |
The EC2 instance type |
string |
n/a |
yes |
key_name |
The ssh keypair for remote connection |
string |
n/a |
yes |
security_groups |
List of the Security Group, it must be allow access 2181, 2888, 3888 port |
list(string) |
[] |
no |
subnet_ids |
List of subnets sorted by availability zone in your VPC |
list(string) |
n/a |
yes |
tags |
A map of zk instance resource, the default tag is Name=zk-${count.idx} |
map(any) |
{} |
no |
vpc_id |
The id of VPC |
string |
n/a |
yes |
zk_config |
The default config of zookeeper server |
map |
{ "client_port": 2181, "zk_heap": 1024 } |
no |
zk_version |
The zookeeper version |
string |
"3.7.1" |
no |
Name |
Description |
Type |
Default |
Required |
cluster_size |
The cluster size that same size as available_zones |
number |
n/a |
yes |
hosted_zone_name |
The name of the hosted private zone |
string |
"shardingsphere.org" |
no |
image_id |
The AMI id |
string |
n/a |
yes |
instance_type |
The EC2 instance type |
string |
n/a |
yes |
key_name |
the ssh keypair for remote connection |
string |
n/a |
yes |
lb_listener_port |
lb listener port |
string |
n/a |
yes |
security_groups |
List of The Security groups |
list(string) |
[] |
no |
shardingsphere_version |
The shardingsphere version |
string |
n/a |
yes |
subnet_ids |
List of subnets sorted by availability zone in your VPC |
list(string) |
n/a |
yes |
vpc_id |
The id of your VPC |
string |
n/a |
yes |
zk_servers |
The Zookeeper servers |
list(string) |
n/a |
yes |
Name |
Description |
shardingsphere_domain |
The domain name of the ShardingSphere Proxy Cluster for use by other services |