Skip to content

Commit

Permalink
[CLOB-976] Add mainnet indexer related config. (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentwschau authored Oct 27, 2023
1 parent f285ffb commit 6bdc030
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 17 deletions.
22 changes: 19 additions & 3 deletions indexer/ecr.tf
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,29 @@ resource "aws_ecr_lifecycle_policy" "lambda_services" {
# -----------------------------------------------------------------------------
# Full Node
# -----------------------------------------------------------------------------
# Data pointing to the validator ECR repository
data "aws_ecr_repository" "validator" {
# Data pointing to the node ECR repository
# For test-nets ECR repositories are in us-east-2
# For main-net ECR repositories are in ap-northeast-1
# Provider can't be provided dynamitcally, so create separate data blocks for each region

data "aws_ecr_repository" "full_node_us_east_2" {
count = var.environment == "mainnet" ? 0 : 1
provider = aws.us-east-2
name = var.full_node_ecr_repository_name
}

data "aws_ecr_repository" "snapshot_validator" {
data "aws_ecr_repository" "snapshot_full_node_us_east_2" {
count = var.environment == "mainnet" ? 0 : 1
provider = aws.us-east-2
name = var.snapshot_full_node_ecr_repository_name
}

data "aws_ecr_repository" "full_node_ap_northeast_1" {
count = var.environment == "mainnet" ? 1 : 0
name = var.full_node_ecr_repository_name
}

data "aws_ecr_repository" "snapshot_full_node_ap_northeast_1" {
count = var.environment == "mainnet" ? 1 : 0
name = var.snapshot_full_node_ecr_repository_name
}
2 changes: 1 addition & 1 deletion indexer/full_node_ap_northeast_1.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module "full_node_ap_northeast_1" {
datadog_api_key = var.datadog_api_key
dd_site = var.dd_site

ecr_repository_url = data.aws_ecr_repository.validator.repository_url
ecr_repository_url = local.node_ecr_repository_url

ec2_instance_type = var.full_node_ec2_instance_type

Expand Down
5 changes: 5 additions & 0 deletions indexer/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,8 @@ locals {
}
]
}

locals {
node_ecr_repository_url = var.environment == "mainnet" ? data.aws_ecr_repository.full_node_ap_northeast_1[0].repository_url : data.aws_ecr_repository.full_node_us_east_2[0].repository_url
snapshot_node_ecr_repository_url = var.environment == "mainnet" ? data.aws_ecr_repository.snapshot_full_node_ap_northeast_1[0].repository_url : data.aws_ecr_repository.snapshot_full_node_us_east_2[0].repository_url
}
4 changes: 3 additions & 1 deletion indexer/s3_bucket.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ resource "aws_s3_bucket" "load_balancer" {
# TODO: refactor snapshotting full node into a separate module
# AWS S3 bucket to store all Indexer full node snapshots
resource "aws_s3_bucket" "indexer_full_node_snapshots" {
bucket = var.s3_snapshot_bucket
# Use account id for mainnet to avoid name collisions
# TODO(IND-457): Migrate files in other envs and update bucket name
bucket = var.environment == "mainnet" ? "${local.account_id}-${var.s3_snapshot_bucket}" : var.s3_snapshot_bucket

tags = {
Name = "${local.account_id}-${var.environment}-full-node-snapshots"
Expand Down
22 changes: 13 additions & 9 deletions indexer/security_group.tf
Original file line number Diff line number Diff line change
Expand Up @@ -246,22 +246,26 @@ resource "aws_security_group" "load_balancer_public" {
name = "${var.environment}-${var.indexers[var.region].name}-lb-public-sg"
vpc_id = aws_vpc.main.id

# Allow all outbound ipv4 traffic.
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}

tags = {
Name = "${var.environment}-${var.indexers[var.region].name}-lb-public-sg"
Environment = "${var.environment}"
}
}

resource "aws_security_group_rule" "outbound_traffic_from_load_balancer" {
count = var.public_access ? 1 : 0
security_group_id = aws_security_group.load_balancer_public.id
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}

# Ingress rule for HTTP traffic for the load balancer
resource "aws_security_group_rule" "inbound_http_to_load_balancer" {
count = var.public_access ? 1 : 0
security_group_id = aws_security_group.load_balancer_public.id
type = "ingress"
from_port = 80
Expand All @@ -273,7 +277,7 @@ resource "aws_security_group_rule" "inbound_http_to_load_balancer" {

# Ingress rule for HTTP traffic for the load balancer - - only created if `var.enable_https` is true
resource "aws_security_group_rule" "inbound_https_to_load_balancer" {
count = var.enable_https ? 1 : 0
count = var.public_access && var.enable_https ? 1 : 0
security_group_id = aws_security_group.load_balancer_public.id
type = "ingress"
from_port = 443
Expand Down
5 changes: 3 additions & 2 deletions indexer/snapshot_full_node_ap_northeast_1.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ module "full_node_snapshot_ap_northeast_1" {
datadog_api_key = var.datadog_api_key
dd_site = var.dd_site

# in public testnet, use the validator image which contains the snapshot script.
# in public testnet, use the node image which contains the snapshot script.
# in dev environments, we build separate images.
ecr_repository_url = contains(["testnet", "testnet1", "testnet2"], var.environment) ? data.aws_ecr_repository.validator.repository_url : data.aws_ecr_repository.snapshot_validator.repository_url
# TODO(CLOB-976): Determine if mainnet configuration uses a separate image.
ecr_repository_url = contains(["testnet", "testnet1", "testnet2"], var.environment) ? local.node_ecr_repository_url : local.snapshot_node_ecr_repository_url

ec2_instance_type = var.full_node_ec2_instance_type

Expand Down
6 changes: 6 additions & 0 deletions indexer/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -433,3 +433,9 @@ variable "vulcan_ecs_environment_variables" {
description = "Environment variables to set for the Indexer Vulcan ECS task, in addition to the default values."
default = []
}

variable "public_access" {
type = bool
description = "Enables public access of the indexer endpoints."
default = true
}
2 changes: 1 addition & 1 deletion modules/datadog_agent/variables.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
variable "env" {
default = "dev"
description = "dev/dev2/dev3/dev4/dev5/staging/testnet/public-testnet/testnet1/testnet2"
description = "dev/dev2/dev3/dev4/dev5/staging/testnet/public-testnet/testnet1/testnet2/mainnet"
}

variable "name" {
Expand Down

0 comments on commit 6bdc030

Please sign in to comment.