Skip to content

Commit 65e2b09

Browse files
authored
fix: duplicate values, validations, examples (#5)
1 parent 1dec43b commit 65e2b09

File tree

6 files changed

+73
-53
lines changed

6 files changed

+73
-53
lines changed

README.md

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
11
## <p align="center">terraform-aws-eth-node</p>
2-
### <p align="center">Spin up an ETH client on AWS</p>
2+
### <p align="center">Spin up ETH clients. On AWS. In a minute.</p>
33

4-
- The deployment takes no more than two minutes
5-
- The default OS the nodes get configured on is debian12
6-
- All clients are managed by systemd
4+
- The deployment takes no more than a minute
5+
- The default OS is `debian12`
6+
- All clients are managed through systemd
77

88
- The module takes care of the:
9-
- EC2's configuration
10-
- creation & management of the volumes that'll hold the chains' data
11-
- mounting of the volumes
12-
- the installation & configuration of the specified ethereum node(s)
13-
- EC2's security group
9+
- EC2's setup, configuration & lifecycle
10+
- Creation & management of the volumes that'll hold the chains' data
1411

1512
- Full examples can be found in the [examples](./examples/) directory.
16-
> :warning: Be mindful with the security group's configuration. All the examples are simplified to allow all external traffic, which in most cases environments shouldn't happen.
13+
> :warning: Be mindful with the security group's configuration. All the examples are simplified to allow all external traffic, which in most cases isn't recommended.
1714
18-
## Example with both Besu & Nimbus client
15+
## Example with Reth & Lighthouse running sepolia
1916
```hcl
2017
module "nodes" {
2118
source = "../../"
2219
23-
name = "besu-nimbus-mainnet"
24-
subnet_id = "/subnet-id/"
20+
name = "[reth-lighthouse]-sepolia"
21+
subnet_id = data.aws_subnets.this.ids[0]
2522
2623
ec2 = {
27-
instance_type = "m4.xlarge"
28-
associate_public_ip_address = true
24+
instance_type = "c4.xlarge"
25+
associate_public_ip_address = true # required if you ever intend to access the nodes from outside the vpc
26+
key_name = module.key_pair.key_pair_name # # required to access the ec2
2927
}
3028
3129
security_group = [
@@ -56,34 +54,32 @@ module "nodes" {
5654
to = 8546
5755
protocol = "tcp"
5856
cidr_blocks = ["0.0.0.0/0"]
59-
},
57+
}
6058
]
6159
6260
clients = [
6361
{
64-
name = "besu"
65-
package_url = "https://hyperledger.jfrog.io/artifactory/besu-binaries/besu/23.7.2/besu-23.7.2.tar.gz"
66-
cmd = "besu --data-path=/besu"
62+
name = "reth"
63+
package_url = "https://github.com/paradigmxyz/reth/releases/download/v0.1.0-alpha.8/reth-v0.1.0-alpha.8-x86_64-unknown-linux-gnu.tar.gz"
64+
cmd = "reth node --chain=sepolia --full --datadir=/reth --authrpc.addr=127.0.0.1 --authrpc.port 8551 --authrpc.jwtsecret=/root/jwt.hex --http --http.addr=0.0.0.0 --http.port=8545 --ws --ws.addr=0.0.0.0 --ws.port=8546 --ws.origins '*' --ws.api eth,net,web3,debug,txpool --bootnodes enode://9246d00bc8fd1742e5ad2428b80fc4dc45d786283e05ef6edbd9002cbc335d40998444732fbe921cb88e1d2c73d1b1de53bae6a2237996e9bfe14f871baf7066@18.168.182.86:30303,enode://ec66ddcf1a974950bd4c782789a7e04f8aa7110a72569b6e65fcd51e937e74eed303b1ea734e4d19cfaec9fbff9b6ee65bf31dcb50ba79acce9dd63a6aca61c7@52.14.151.177:30303"
6765
68-
create_ebs = true
6966
ebs = {
7067
device_name = "xvdb"
71-
type = "gp3"
72-
size = 1000 // GB
73-
mountpoint = "/besu"
68+
type = "gp2"
69+
size = 100 # GB
70+
mountpoint = "/reth"
7471
}
7572
},
7673
{
77-
name = "nimbus"
78-
package_url = "https://github.com/status-im/nimbus-eth2/releases/download/v23.8.0/nimbus-eth2_Linux_amd64_23.8.0_d014d0a5.tar.gz"
79-
cmd = "nimbus --data-dir=/nimbus"
74+
name = "lighthouse"
75+
package_url = "https://github.com/sigp/lighthouse/releases/download/v4.4.1/lighthouse-v4.4.1-x86_64-unknown-linux-gnu-portable.tar.gz"
76+
cmd = "lighthouse bn --network=sepolia --datadir=/lighthouse --execution-jwt=/root/jwt.hex --execution-endpoint=http://127.0.0.1:8551 --disable-deposit-contract-sync --checkpoint-sync-url https://sepolia.checkpoint-sync.ethpandaops.io"
8077
81-
create_ebs = true
8278
ebs = {
8379
device_name = "xvdc"
84-
type = "gp3"
85-
size = 1000 // GB
86-
mountpoint = "/nimbus"
80+
type = "gp2"
81+
size = 2 # GB
82+
mountpoint = "/lighthouse"
8783
}
8884
}
8985
]

examples/besu-nimbus-mainnet/main.tf

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ module "nodes" {
6060
package_url = "https://hyperledger.jfrog.io/artifactory/besu-binaries/besu/23.7.2/besu-23.7.2.tar.gz"
6161
cmd = "besu --data-path=/besu"
6262

63-
create_ebs = true
6463
ebs = {
6564
device_name = "xvdb"
6665
type = "gp3"
@@ -73,11 +72,10 @@ module "nodes" {
7372
package_url = "https://github.com/status-im/nimbus-eth2/releases/download/v23.8.0/nimbus-eth2_Linux_amd64_23.8.0_d014d0a5.tar.gz"
7473
cmd = "nimbus --data-dir=/nimbus"
7574

76-
create_ebs = true
7775
ebs = {
7876
device_name = "xvdc"
7977
type = "gp3"
80-
size = 1000 # GB
78+
size = 100 # GB
8179
mountpoint = "/nimbus"
8280
}
8381
}

examples/geth-teku-mainnet/main.tf

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module "nodes" {
1818
subnet_id = data.aws_subnets.this.ids[0]
1919

2020
ec2 = {
21-
instance_type = "m4.xlarge"
21+
type = "m4.xlarge"
2222
associate_public_ip_address = true
2323
key_name = module.key_pair.key_pair_name
2424
}
@@ -60,11 +60,10 @@ module "nodes" {
6060
package_url = "https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.12.2-bed84606.tar.gz"
6161
cmd = "geth --datadir=/geth --http --http.addr=0.0.0.0 --http.port=8545 --ws --ws.addr=0.0.0.0 --ws.port=8546 --ws.origins '*' --ws.api eth,net,web3,debug,txpool --authrpc.addr=127.0.0.1 --authrpc.port 8551 --authrpc.jwtsecret=/geth/jwt.hex --bootnodes enode://9246d00bc8fd1742e5ad2428b80fc4dc45d786283e05ef6edbd9002cbc335d40998444732fbe921cb88e1d2c73d1b1de53bae6a2237996e9bfe14f871baf7066@18.168.182.86:30303,enode://ec66ddcf1a974950bd4c782789a7e04f8aa7110a72569b6e65fcd51e937e74eed303b1ea734e4d19cfaec9fbff9b6ee65bf31dcb50ba79acce9dd63a6aca61c7@52.14.151.177:30303"
6262

63-
create_ebs = true
6463
ebs = {
6564
device_name = "xvdb"
6665
type = "gp3"
67-
size = 1000
66+
size = 1500
6867
mountpoint = "/geth"
6968
}
7069
},
@@ -73,11 +72,10 @@ module "nodes" {
7372
package_url = "https://artifacts.consensys.net/public/teku/raw/names/teku.tar.gz/versions/23.9.0/teku-23.9.0.tar.gz"
7473
cmd = "teku --data-beacon-path=/teku --data-path=/teku --ee-endpoint=http://localhost:8551"
7574

76-
create_ebs = true
7775
ebs = {
7876
device_name = "xvdc"
7977
type = "gp2"
80-
size = 1000
78+
size = 100
8179
mountpoint = "/teku"
8280
}
8381
}

examples/reth-lighthouse-sepolia/main.tf

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ module "nodes" {
5858
{
5959
name = "reth"
6060
package_url = "https://github.com/paradigmxyz/reth/releases/download/v0.1.0-alpha.8/reth-v0.1.0-alpha.8-x86_64-unknown-linux-gnu.tar.gz"
61-
cmd = "reth node --chain=sepolia --full --datadir=/reth"
61+
cmd = "reth node --chain=sepolia --full --datadir=/reth --authrpc.addr=127.0.0.1 --authrpc.port 8551 --authrpc.jwtsecret=/root/jwt.hex --http --http.addr=0.0.0.0 --http.port=8545 --ws --ws.addr=0.0.0.0 --ws.port=8546 --ws.origins '*' --ws.api eth,net,web3,debug,txpool --bootnodes enode://9246d00bc8fd1742e5ad2428b80fc4dc45d786283e05ef6edbd9002cbc335d40998444732fbe921cb88e1d2c73d1b1de53bae6a2237996e9bfe14f871baf7066@18.168.182.86:30303,enode://ec66ddcf1a974950bd4c782789a7e04f8aa7110a72569b6e65fcd51e937e74eed303b1ea734e4d19cfaec9fbff9b6ee65bf31dcb50ba79acce9dd63a6aca61c7@52.14.151.177:30303"
6262

63-
create_ebs = true
6463
ebs = {
6564
device_name = "xvdb"
6665
type = "gp2"
@@ -70,14 +69,13 @@ module "nodes" {
7069
},
7170
{
7271
name = "lighthouse"
73-
package_url = "https://github.com/sigp/lighthouse/releases/download/v4.4.1/lighthouse-v4.4.1-x86_64-unknown-linux-gnu.tar.gz"
74-
cmd = "lighthouse bn --network sepolia --datadir=/lighthouse --disable-deposit-contract-sync --checkpoint-sync-url https://sepolia.checkpoint-sync.ethpandaops.io"
72+
package_url = "https://github.com/sigp/lighthouse/releases/download/v4.4.1/lighthouse-v4.4.1-x86_64-unknown-linux-gnu-portable.tar.gz"
73+
cmd = "lighthouse bn --network=sepolia --datadir=/lighthouse --execution-jwt=/root/jwt.hex --execution-endpoint=http://127.0.0.1:8551 --disable-deposit-contract-sync --checkpoint-sync-url https://sepolia.checkpoint-sync.ethpandaops.io"
7574

76-
create_ebs = true
7775
ebs = {
7876
device_name = "xvdc"
7977
type = "gp2"
80-
size = 70 # GB
78+
size = 2 # GB
8179
mountpoint = "/lighthouse"
8280
}
8381
}

main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,10 @@ resource "aws_volume_attachment" "this" {
9090
volume_id = each.value.external_volume_id == null ? aws_ebs_volume.this[each.key].id : each.value.external_volume_id
9191
instance_id = aws_instance.this.id
9292
}
93+
94+
resource "aws_ec2_instance_state" "this" {
95+
count = var.ec2.state == null ? 0 : 1
96+
97+
instance_id = aws_instance.this.id
98+
state = var.ec2.state
99+
}

variables.tf

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
variable "name" {
22
type = string
3-
description = "The generic name to apply across the different resources"
3+
description = "The generic name to apply across the different resources created in AWS"
44
}
55

66
variable "subnet_id" {
@@ -33,10 +33,10 @@ variable "ami" {
3333

3434
variable "ec2" {
3535
type = object({
36-
type = optional(string)
36+
type = optional(string, "t2.micro")
37+
state = optional(string, "running")
3738
associate_public_ip_address = bool
38-
key_name = string
39-
security_group_ids = optional(list(string)) # optional external SGs; ones created outside of this module.
39+
security_group_ids = optional(list(string)) # external SGs;
4040
disable_api_stop = optional(bool)
4141
disable_api_termination = optional(bool)
4242
ebs_optimized = optional(bool)
@@ -45,14 +45,29 @@ variable "ec2" {
4545
key_name = optional(string)
4646
})
4747
description = "The EC2 configuration"
48+
default = {
49+
type = "t2.micro",
50+
state = "running",
51+
associate_public_ip_address = true
52+
}
53+
54+
validation {
55+
condition = can(regex("^((a1|c1|c3|c4|c5|c5a|c5ad|c5d|c5n|c6a|c6g|c6gd|c6gn|c6i|c6id|c7g|cc2|d2|d3|d3en|dl1|f1|g2|g3|g3s|g4ad|g4dn|g5|g5g|h1|i2|i3|i3en|i4i|im4gn|inf1|is4gen|m1|m2|m3|m4|m5|m5a|m5ad|m5d|m5dn|m5n|m5zn|m6a|m6g|m6gd|m6i|m6id|mac1|mac2|p2|p3|p3dn|p4d|r3|r4|r5|r5a|r5ad|r5b|r5d|r5dn|r5n|r6a|r6g|r6gd|r6i|r6id|t1|t2|t3|t3a|t4g|trn1|u-12tb1|u-3tb1|u-6tb1|u-9tb1|vt1|x1|x1e|x2gd|x2idn|x2iedn|x2iezn|z1d)\\.(10xlarge|112xlarge|12xlarge|16xlarge|18xlarge|24xlarge|2xlarge|32xlarge|3xlarge|48xlarge|4xlarge|56xlarge|6xlarge|8xlarge|9xlarge|large|medium|metal|micro|nano|small|xlarge))$", var.ec2.type))
56+
error_message = "value must be a valid EC2 instance type"
57+
}
58+
59+
validation {
60+
condition = contains(["running", "stopped"], var.ec2.state)
61+
error_message = "Invalid EC2 state. Valid states are: running, stopped"
62+
}
4863
}
4964

5065
variable "clients" {
5166
type = list(
5267
object({
53-
name = string
54-
package_url = string
55-
cmd = string
68+
name = string # name of the ethereum client
69+
package_url = string # link to the url of the binary to download
70+
cmd = string # the startup command of the client
5671

5772
ebs = optional(object({
5873
device_name = string
@@ -68,10 +83,18 @@ variable "clients" {
6883
size = optional(number)
6984
}))
7085
}))
71-
description = "The ETH clients to deploy on the EC2"
86+
description = "The nodes to deploy on the EC2"
87+
88+
validation {
89+
condition = length(var.clients) > 0
90+
error_message = "You must provide at least one client"
91+
}
7292

7393
validation {
74-
condition = alltrue([for client in var.clients : true if contains(["geth", "nethermind", "besu", "erigon", "reth", "lighthouse", "nimbus", "prysm", "teku"], client.name)])
94+
condition = length([
95+
for c in var.clients :
96+
true if contains(["geth", "nethermind", "besu", "erigon", "reth", "lighthouse", "nimbus", "prysm", "teku"], c.name)
97+
]) == length(var.clients)
7598
error_message = "Invalid client name. Valid names are: geth, nethermind, besu, erigon, reth, lighthouse, nimbus, prysm, teku"
7699
}
77100
}

0 commit comments

Comments
 (0)