-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5336fa
commit 93bac7a
Showing
8 changed files
with
255 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 |
---|---|---|
@@ -1,2 +1,15 @@ | ||
# terraform-aws-sui-node | ||
Terraform module for deploy sui node on AWS | ||
|
||
|
||
```bash | ||
# Configure AWS credentional | ||
aws configure | ||
|
||
# Search Linux image if need | ||
aws ec2 describe-images --owners amazon --filters "Name=name,Values=debian-11-amd64*" --query "Images | [0].ImageId" --output text\n | ||
|
||
# Create SSH keypair | ||
aws ec2 create-key-pair --key-name sui-node-key --query 'KeyMaterial' --output text > aws-sui-node-key.pem | ||
|
||
``` |
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,78 @@ | ||
#cloud-config | ||
#users: | ||
# - name: devops | ||
# groups: users, admin | ||
# sudo: ALL=(ALL) NOPASSWD:ALL | ||
# shell: /bin/bash | ||
# ssh_authorized_keys: | ||
# - ssh-rsa <key> | ||
package_update: true | ||
package_upgrade: true | ||
packages: | ||
- vim | ||
- ca-certificates | ||
- curl | ||
- gnupg | ||
- wget | ||
write_files: | ||
- path: /bin/docker-up | ||
content: | | ||
#!/usr/bin/bash | ||
docker-compose up -d | ||
- path: /etc/systemd/system/docker-up.service | ||
content: | | ||
[Unit] | ||
Description=SUI NODE Startup | ||
|
||
[Service] | ||
Type=simple | ||
ExecStart=/bin/docker-up | ||
WorkingDirectory=/opt/service | ||
|
||
[Install] | ||
WantedBy=default.target | ||
- path: /etc/profile.d/service-env.sh | ||
content: | | ||
export APP_VERSION=${version} | ||
- path: /opt/service/docker-compose.yml | ||
content: | | ||
version: '3.9' | ||
services: | ||
sui-node: | ||
container_name: sui-node | ||
image: mysten/sui-node:${version} | ||
command: ["sui-node", "--config-path", "/opt/sui/config/fullnode.yaml"] | ||
restart: always | ||
#environment: | ||
ports: | ||
- "8084:8084/udp" | ||
- "9000:9000" | ||
- "9184:9184" | ||
volumes: | ||
- ./volumes/root:/root | ||
- ./volumes/fullnode.yaml:/opt/sui/config/fullnode.yaml:ro | ||
- ./volumes/genesis.blob:/opt/sui/config/genesis.blob:ro | ||
- ./volumes/suidb:/opt/sui/db:rw | ||
logging: | ||
driver: "json-file" | ||
options: | ||
max-size: 10m | ||
max-file: "3" | ||
runcmd: | ||
- echo '${opt} /opt/service/volumes xfs discard,nofail,defaults 0 0' >> /etc/fstab | ||
- mkdir -p /opt/service/volumes && mount /opt/service/volumes | ||
- install -m 0755 -d /etc/apt/keyrings | ||
- curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg | ||
- chmod a+r /etc/apt/keyrings/docker.gpg | ||
- echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null | ||
- apt update && apt -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin | ||
- wget https://github.com/docker/compose/releases/download/v2.22.0/docker-compose-linux-x86_64 | ||
- mv docker-compose-linux-x86_64 /bin/docker-compose && chmod a+x /bin/docker-compose | ||
- echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf | ||
- chmod u+x /bin/docker-up | ||
- systemctl enable docker | ||
- systemctl daemon-reload && systemctl enable docker-up.service | ||
- wget https://github.com/MystenLabs/sui/raw/main/crates/sui-config/data/fullnode-template.yaml -O /opt/service/volumes/fullnode.yaml | ||
- wget https://github.com/MystenLabs/sui-genesis/raw/main/${sui_network}/genesis.blob -O /opt/service/volumes/genesis.blob | ||
- sed -i 's/127.0.0.1/0.0.0.0/' /opt/service/volumes/fullnode.yaml | ||
- shutdown -r now |
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 @@ | ||
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,6 @@ | ||
terraform { | ||
required_providers { | ||
} | ||
|
||
required_version = ">= 1.0.2" | ||
} |
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,104 @@ | ||
# Create a VPC | ||
resource "aws_vpc" "my_vpc" { | ||
cidr_block = "10.0.0.0/16" | ||
enable_dns_support = true | ||
enable_dns_hostnames = true | ||
|
||
tags = { | ||
Name = var.vpc_name | ||
} | ||
} | ||
|
||
resource "aws_eip" "ip_ip_env" { | ||
instance = aws_instance.my_instance.id | ||
domain = "vpc" | ||
} | ||
|
||
resource "aws_internet_gateway" "vpc_gw" { | ||
vpc_id = aws_vpc.my_vpc.id | ||
|
||
} | ||
|
||
resource "aws_route_table" "route_table" { | ||
vpc_id = aws_vpc.my_vpc.id | ||
route { | ||
cidr_block = "0.0.0.0/0" | ||
gateway_id = "${aws_internet_gateway.vpc_gw.id}" | ||
} | ||
|
||
} | ||
resource "aws_route_table_association" "subnet_association" { | ||
subnet_id = aws_subnet.public_subnet.id | ||
route_table_id = aws_route_table.route_table.id | ||
} | ||
|
||
# Create a public subnet | ||
resource "aws_subnet" "public_subnet" { | ||
vpc_id = aws_vpc.my_vpc.id | ||
cidr_block = "10.0.1.0/24" | ||
availability_zone = var.aws_availability_zone # Set your desired availability zone | ||
|
||
tags = { | ||
Name = var.vpc_name | ||
} | ||
} | ||
|
||
resource "aws_security_group" "allow_all" { | ||
name = "${var.vpc_name}-allow-all-sg" | ||
vpc_id = "${aws_vpc.my_vpc.id}" | ||
ingress { | ||
cidr_blocks = [ | ||
"0.0.0.0/0" | ||
] | ||
from_port = 22 | ||
to_port = 22 | ||
protocol = "tcp" | ||
} | ||
// Terraform removes the default rule | ||
egress { | ||
from_port = 0 | ||
to_port = 0 | ||
protocol = "-1" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
} | ||
|
||
data "aws_ami" "latest_debian_linux" { | ||
most_recent = true | ||
owners = ["amazon"] | ||
|
||
filter { | ||
name = "name" | ||
values = [ var.aws_image_name ] | ||
} | ||
} | ||
|
||
# Create an EC2 instance in the public subnet | ||
resource "aws_instance" "my_instance" { | ||
ami = data.aws_ami.latest_debian_linux.id | ||
instance_type = var.aws_instance_type | ||
subnet_id = aws_subnet.public_subnet.id | ||
user_data = templatefile("${path.module}/cloud_init.yml.tftpl", { | ||
opt = "" | ||
version = var.app_version | ||
sui_network = var.sui_network | ||
}) | ||
key_name = var.ssh_key_name # Update with your key pair name | ||
|
||
vpc_security_group_ids = [aws_security_group.allow_all.id] | ||
|
||
# lifecycle { | ||
# replace_triggered_by = [ | ||
# user_data, | ||
# key_name | ||
# ] | ||
# } | ||
|
||
tags = { | ||
Name = "${var.vpc_name}" | ||
} | ||
} | ||
|
||
output "host_ip" { | ||
value = aws_eip.ip_ip_env.public_ip | ||
} |
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 @@ | ||
provider "aws" { | ||
region = var.aws_region # Set your desired AWS region | ||
} |
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,40 @@ | ||
variable "aws_region" { | ||
default = "us-west-2" | ||
description = "AWS region" | ||
} | ||
|
||
variable "aws_availability_zone" { | ||
default = "us-west-2a" | ||
description = "AWS region" | ||
} | ||
|
||
variable "aws_image_name" { | ||
description = "The AMI IMAGE NAME for the EC2 instance" | ||
default = "debian-11-amd64*" # Update with the desired AMI | ||
} | ||
|
||
variable "ssh_key_name" { | ||
description = "The name of the key pair for the EC2 instance" | ||
default = "" # Update with your key pair name | ||
} | ||
|
||
variable "vpc_name" { | ||
default = "sui-node" | ||
description = "vpc name prefix" | ||
} | ||
|
||
variable "aws_instance_type" { | ||
default = "t2.micro" | ||
description = "AWS instance type" | ||
} | ||
|
||
# Version docker containers | ||
variable "app_version" { | ||
default = "testnet" | ||
description = "Docker app version" | ||
} | ||
|
||
variable "sui_network" { | ||
default = "testnet" | ||
description = "SUI network mainnet / testnet / devnet " | ||
} |
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,10 @@ | ||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 5.0" | ||
} | ||
} | ||
|
||
required_version = ">= 1.0.2" | ||
} |