tree: 3dd6564935476904ad14272d801d0f9526c22d08 [path history] [tgz]
  1. arch/
  2. modules/
  3. main.tf
  4. outputs.tf
  5. README.md
terraform/amazon/README.md

Terraform Module for Apache ShardingSphere-Proxy Cluster

A terraform module to create an Apache ShardingSphere Proxy Cluster on AWS.

Terraform will create a cluster with the following architecture:

Prerequisites

  • 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

Usage

Step1: Edit main.tf

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "4.37.0"
    }
  }
}

provider "aws" {
  region     = "ap-southeast-1"
}

module "zk" {
  source              = "./modules/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                 = "./modules/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

terrafrom init

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.

Modules

Requirements

NameVersion
aws4.37.0

Modules

NameSourceVersion
zk./zkn/a
shardingsphere./shardingspheren/a

Outputs

NameDescription
shardingsphere_domainThe domain name of the ShardingSphere Proxy Cluster for use by other services
zk_node_domainThe domain of zookeeper instances

ZK

Resources

NameType
aws_instance.zkresource
aws_network_interface.zkresource
aws_route53_record.zkresource
aws_ami.basedata source
aws_availability_zones.availabledata source
aws_route53_zone.zonedata source

Inputs

NameDescriptionTypeDefaultRequired
cluster_sizeThe cluster size that same size as available_zonesnumbern/ayes
hosted_zone_nameThe name of the hosted private zonestring"shardingsphere.org"no
instance_typeThe EC2 instance typestringn/ayes
key_nameThe ssh keypair for remote connectionstringn/ayes
security_groupsList of the Security Group, it must be allow access 2181, 2888, 3888 portlist(string)[]no
subnet_idsList of subnets sorted by availability zone in your VPClist(string)n/ayes
tagsA map of zk instance resource, the default tag is Name=zk-${count.idx}map(any){}no
vpc_idThe id of VPCstringn/ayes
zk_configThe default config of zookeeper servermap{
“client_port”: 2181,
“zk_heap”: 1024
}
no
zk_versionThe zookeeper versionstring"3.7.1"no

Outputs

NameDescription
zk_node_domainn/a
zk_node_private_ipn/a

shardingsphere

Resources

NameType
aws_autoscaling_attachment.asg_attachment_lbresource
aws_autoscaling_group.ssresource
aws_launch_template.ssresource
aws_lb.ssresource
aws_lb_listener.ssresource
aws_lb_target_group.ss_tgresource
aws_network_interface.ssresource
aws_route53_record.ssresource
aws_availability_zones.availabledata source
aws_route53_zone.zonedata source
aws_vpc.vpcdata source

Inputs

NameDescriptionTypeDefaultRequired
cluster_sizeThe cluster size that same size as available_zonesnumbern/ayes
hosted_zone_nameThe name of the hosted private zonestring"shardingsphere.org"no
image_idThe AMI idstringn/ayes
instance_typeThe EC2 instance typestringn/ayes
key_namethe ssh keypair for remote connectionstringn/ayes
lb_listener_portlb listener portstringn/ayes
security_groupsList of The Security groupslist(string)[]no
shardingsphere_versionThe shardingsphere versionstringn/ayes
subnet_idsList of subnets sorted by availability zone in your VPClist(string)n/ayes
vpc_idThe id of your VPCstringn/ayes
zk_serversThe Zookeeper serverslist(string)n/ayes

Outputs

NameDescription
shardingsphere_domainThe domain name of the ShardingSphere Proxy Cluster for use by other services