Fix chain map and counts

This commit is contained in:
Andrew Cravenho 2018-09-27 05:30:34 -04:00
parent bdab91c6a8
commit 3427aa0a76
7 changed files with 80 additions and 51 deletions

View File

@ -33,9 +33,11 @@ variable "root_block_size" {
default = 8 default = 8
} }
variable "chain" { variable "chains" {
description = "A map of chain names to urls" description = "A map of chain names to urls"
default = "sokol" default = {
"sokol" = "https://sokol.poa.network"
}
} }
variable "chain_jsonrpc_variant" { variable "chain_jsonrpc_variant" {
@ -43,11 +45,6 @@ variable "chain_jsonrpc_variant" {
default = "parity" default = "parity"
} }
variable "chain_ethereum_url" {
description = "The base RPC endpoint for the chain"
default = "https://sokol.poa.network"
}
variable "chain_trace_endpoint" { variable "chain_trace_endpoint" {
description = "A RPC tracing RPC endpoint" description = "A RPC tracing RPC endpoint"
default = "https://sokol-trace.poa.network" default = "https://sokol-trace.poa.network"

View File

@ -1,169 +1,198 @@
resource "aws_ssm_parameter" "new_relic_app_name" { resource "aws_ssm_parameter" "new_relic_app_name" {
name = "/${var.prefix}/${var.chain}/new_relic_app_name" count = "${var.new_relic_app_name == "" ? 0 : length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/new_relic_app_name"
value = "${var.new_relic_app_name}" value = "${var.new_relic_app_name}"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "new_relic_license_key" { resource "aws_ssm_parameter" "new_relic_license_key" {
name = "/${var.prefix}/${var.chain}/new_relic_license_key" count = "${var.new_relic_license_key == "" ? 0 : length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/new_relic_license_key"
value = "${var.new_relic_license_key}" value = "${var.new_relic_license_key}"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "pool_size" { resource "aws_ssm_parameter" "pool_size" {
name = "/${var.prefix}/${var.chain}/pool_size" count = "${length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/pool_size"
value = "10" value = "10"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "ecto_use_ssl" { resource "aws_ssm_parameter" "ecto_use_ssl" {
name = "/${var.prefix}/${var.chain}/ecto_use_ssl" count = "${length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/ecto_use_ssl"
value = "false" value = "false"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "ethereum_jsonrpc_variant" { resource "aws_ssm_parameter" "ethereum_jsonrpc_variant" {
name = "/${var.prefix}/${var.chain}/ethereum_jsonrpc_variant" count = "${length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/ethereum_jsonrpc_variant"
value = "${var.chain_jsonrpc_variant}" value = "${var.chain_jsonrpc_variant}"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "ethereum_url" { resource "aws_ssm_parameter" "ethereum_url" {
name = "/${var.prefix}/${var.chain}/ethereum_url" count = "${length(var.chains)}"
value = "${var.chain_ethereum_url}" name = "/${var.prefix}/${element(keys(var.chains),count.index)}/ethereum_url"
value = "${element(values(var.chains),count.index)}"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "trace_url" { resource "aws_ssm_parameter" "trace_url" {
name = "/${var.prefix}/${var.chain}/trace_url" count = "${length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/trace_url"
value = "${var.chain_trace_endpoint}" value = "${var.chain_trace_endpoint}"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "ws_url" { resource "aws_ssm_parameter" "ws_url" {
name = "/${var.prefix}/${var.chain}/ws_url" count = "${length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/ws_url"
value = "${var.chain_ws_endpoint}" value = "${var.chain_ws_endpoint}"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "logo" { resource "aws_ssm_parameter" "logo" {
name = "/${var.prefix}/${var.chain}/logo" count = "${length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/logo"
value = "${var.chain_logo}" value = "${var.chain_logo}"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "check_origin" { resource "aws_ssm_parameter" "check_origin" {
name = "/${var.prefix}/${var.chain}/check_origin" count = "${length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/check_origin"
value = "${var.chain_check_origin}" value = "${var.chain_check_origin}"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "coin" { resource "aws_ssm_parameter" "coin" {
name = "/${var.prefix}/${var.chain}/coin" count = "${length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/coin"
value = "${var.chain_coin}" value = "${var.chain_coin}"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "network" { resource "aws_ssm_parameter" "network" {
name = "/${var.prefix}/${var.chain}/network" count = "${length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/network"
value = "${var.chain_network}" value = "${var.chain_network}"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "subnetwork" { resource "aws_ssm_parameter" "subnetwork" {
name = "/${var.prefix}/${var.chain}/subnetwork" count = "${length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/subnetwork"
value = "${var.chain_subnetwork}" value = "${var.chain_subnetwork}"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "network_path" { resource "aws_ssm_parameter" "network_path" {
name = "/${var.prefix}/${var.chain}/network_path" count = "${length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/network_path"
value = "${var.chain_network_path}" value = "${var.chain_network_path}"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "subnetwork_path" { resource "aws_ssm_parameter" "subnetwork_path" {
name = "/${var.prefix}/${var.chain}/subnetwork_path" count = "${length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/subnetwork_path"
value = "${var.chain_subnetwork_path}" value = "${var.chain_subnetwork_path}"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "network_icon" { resource "aws_ssm_parameter" "network_icon" {
name = "/${var.prefix}/${var.chain}/network_icon" count = "${length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/network_icon"
value = "${var.chain_network_icon}" value = "${var.chain_network_icon}"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "exq_blocks_concurrency" { resource "aws_ssm_parameter" "exq_blocks_concurrency" {
name = "/${var.prefix}/${var.chain}/exq_blocks_concurrency" count = "${length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/exq_blocks_concurrency"
value = "1" value = "1"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "exq_concurrency" { resource "aws_ssm_parameter" "exq_concurrency" {
name = "/${var.prefix}/${var.chain}/exq_concurrency" count = "${length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/exq_concurrency"
value = "1" value = "1"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "exq_internal_transactions_concurrency" { resource "aws_ssm_parameter" "exq_internal_transactions_concurrency" {
name = "/${var.prefix}/${var.chain}/exq_internal_transactions_concurrency" count = "${length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/exq_internal_transactions_concurrency"
value = "1" value = "1"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "exq_receipts_concurrency" { resource "aws_ssm_parameter" "exq_receipts_concurrency" {
name = "/${var.prefix}/${var.chain}/exq_receipts_concurrency" count = "${length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/exq_receipts_concurrency"
value = "1" value = "1"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "exq_transactions_concurrency" { resource "aws_ssm_parameter" "exq_transactions_concurrency" {
name = "/${var.prefix}/${var.chain}/exq_transactions_concurrency" count = "${length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/exq_transactions_concurrency"
value = "1" value = "1"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "secret_key_base" { resource "aws_ssm_parameter" "secret_key_base" {
name = "/${var.prefix}/${var.chain}/secret_key_base" count = "${length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/secret_key_base"
value = "${var.secret_key_base}" value = "${var.secret_key_base}"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "port" { resource "aws_ssm_parameter" "port" {
name = "/${var.prefix}/${var.chain}/port" count = "${length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/port"
value = "4000" value = "4000"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "db_username" { resource "aws_ssm_parameter" "db_username" {
name = "/${var.prefix}/${var.chain}/db_username" count = "${length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/db_username"
value = "${var.db_username}" value = "${var.db_username}"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "db_password" { resource "aws_ssm_parameter" "db_password" {
name = "/${var.prefix}/${var.chain}/db_password" count = "${length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/db_password"
value = "${var.db_password}" value = "${var.db_password}"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "db_host" { resource "aws_ssm_parameter" "db_host" {
name = "/${var.prefix}/${var.chain}/db_host" count = "${length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/db_host"
value = "${aws_route53_record.db.fqdn}" value = "${aws_route53_record.db.fqdn}"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "db_port" { resource "aws_ssm_parameter" "db_port" {
name = "/${var.prefix}/${var.chain}/db_port" count = "${length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/db_port"
value = "${aws_db_instance.default.port}" value = "${aws_db_instance.default.port}"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "alb_ssl_policy" { resource "aws_ssm_parameter" "alb_ssl_policy" {
name = "/${var.prefix}/${var.chain}/alb_ssl_policy" count = "${length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/alb_ssl_policy"
value = "${var.alb_ssl_policy}" value = "${var.alb_ssl_policy}"
type = "String" type = "String"
} }
resource "aws_ssm_parameter" "alb_certificate_arn" { resource "aws_ssm_parameter" "alb_certificate_arn" {
name = "/${var.prefix}/${var.chain}/alb_certificate_arn" count = "${length(var.chains)}"
name = "/${var.prefix}/${element(keys(var.chains),count.index)}/alb_certificate_arn"
value = "${var.alb_certificate_arn}" value = "${var.alb_certificate_arn}"
type = "String" type = "String"
} }

View File

@ -12,7 +12,7 @@ resource "aws_codedeploy_app" "explorer" {
} }
resource "aws_codedeploy_deployment_group" "explorer" { resource "aws_codedeploy_deployment_group" "explorer" {
count = 1 count = "${length(var.chains)}"
app_name = "${aws_codedeploy_app.explorer.name}" app_name = "${aws_codedeploy_app.explorer.name}"
deployment_group_name = "${var.prefix}-explorer-dg${count.index}" deployment_group_name = "${var.prefix}-explorer-dg${count.index}"
service_role_arn = "${aws_iam_role.deployer.arn}" service_role_arn = "${aws_iam_role.deployer.arn}"

View File

@ -40,17 +40,17 @@ resource "aws_launch_configuration" "explorer" {
} }
resource "aws_placement_group" "explorer" { resource "aws_placement_group" "explorer" {
count = 1 count = "${length(var.chains)}"
name = "${var.prefix}-explorer-placement-group${count.index}" name = "${var.prefix}-explorer-placement-group${count.index}"
strategy = "cluster" strategy = "cluster"
} }
resource "aws_autoscaling_group" "explorer" { resource "aws_autoscaling_group" "explorer" {
count = 1 count = "${length(var.chains)}"
name = "${aws_launch_configuration.explorer.name}-asg${count.index}" name = "${aws_launch_configuration.explorer.name}-asg${count.index}"
max_size = 4 max_size = "${length(var.chains) * 4}"
min_size = 1 min_size = "${length(var.chains)}"
desired_capacity = 1 desired_capacity = "${length(var.chains)}"
placement_group = "${aws_placement_group.explorer.*.id[count.index]}" placement_group = "${aws_placement_group.explorer.*.id[count.index]}"
launch_configuration = "${aws_launch_configuration.explorer.name}" launch_configuration = "${aws_launch_configuration.explorer.name}"
vpc_zone_identifier = ["${aws_subnet.default.id}"] vpc_zone_identifier = ["${aws_subnet.default.id}"]
@ -100,14 +100,14 @@ resource "aws_autoscaling_group" "explorer" {
tag { tag {
key = "chain" key = "chain"
value = "${var.chain}" value = "${element(keys(var.chains),count.index)}"
propagate_at_launch = true propagate_at_launch = true
} }
} }
# TODO: These autoscaling policies are not currently wired up to any triggers # TODO: These autoscaling policies are not currently wired up to any triggers
resource "aws_autoscaling_policy" "explorer-up" { resource "aws_autoscaling_policy" "explorer-up" {
count = 1 count = "${length(var.chains)}"
name = "${var.prefix}-explorer-autoscaling-policy-up${count.index}" name = "${var.prefix}-explorer-autoscaling-policy-up${count.index}"
autoscaling_group_name = "${element(aws_autoscaling_group.explorer.*.name, count.index)}" autoscaling_group_name = "${element(aws_autoscaling_group.explorer.*.name, count.index)}"
adjustment_type = "ChangeInCapacity" adjustment_type = "ChangeInCapacity"
@ -116,7 +116,7 @@ resource "aws_autoscaling_policy" "explorer-up" {
} }
resource "aws_autoscaling_policy" "explorer-down" { resource "aws_autoscaling_policy" "explorer-down" {
count = 1 count = "${length(var.chains)}"
name = "${var.prefix}-explorer-autoscaling-policy-down${count.index}" name = "${var.prefix}-explorer-autoscaling-policy-down${count.index}"
autoscaling_group_name = "${element(aws_autoscaling_group.explorer.*.name, count.index)}" autoscaling_group_name = "${element(aws_autoscaling_group.explorer.*.name, count.index)}"
adjustment_type = "ChangeInCapacity" adjustment_type = "ChangeInCapacity"

View File

@ -20,7 +20,7 @@ output "codedeploy_bucket_path" {
output "explorer_urls" { output "explorer_urls" {
description = "A map of each chain to the DNS name of its corresponding Explorer instance" description = "A map of each chain to the DNS name of its corresponding Explorer instance"
value = "${aws_lb.explorer.*.dns_name}" value = "${zipmap(keys(var.chains), aws_lb.explorer.*.dns_name)}"
} }
output "db_instance_address" { output "db_instance_address" {

View File

@ -17,7 +17,8 @@ resource "aws_route" "internet_access" {
# The ALB for the app server # The ALB for the app server
resource "aws_lb" "explorer" { resource "aws_lb" "explorer" {
name = "${var.prefix}-explorer-${var.chain}-alb" count = "${length(var.chains)}"
name = "${var.prefix}-explorer-${element(keys(var.chains),count.index)}-alb"
internal = false internal = false
load_balancer_type = "application" load_balancer_type = "application"
security_groups = ["${aws_security_group.alb.id}"] security_groups = ["${aws_security_group.alb.id}"]
@ -33,7 +34,8 @@ resource "aws_lb" "explorer" {
# The Target Group for the ALB # The Target Group for the ALB
resource "aws_lb_target_group" "explorer" { resource "aws_lb_target_group" "explorer" {
name = "${var.prefix}-explorer-${var.chain}-alb-target" count = "${length(var.chains)}"
name = "${var.prefix}-explorer-${element(keys(var.chains),count.index)}-alb-target"
port = 4000 port = 4000
protocol = "HTTP" protocol = "HTTP"
vpc_id = "${aws_vpc.vpc.id}" vpc_id = "${aws_vpc.vpc.id}"

View File

@ -9,8 +9,9 @@ variable "instance_type" {}
variable "root_block_size" {} variable "root_block_size" {}
variable "chain_jsonrpc_variant" {} variable "chain_jsonrpc_variant" {}
variable "chain" {} variable "chains" {
variable "chain_ethereum_url" {} default = {}
}
variable "chain_trace_endpoint" {} variable "chain_trace_endpoint" {}
variable "chain_ws_endpoint" {} variable "chain_ws_endpoint" {}
variable "chain_logo" {} variable "chain_logo" {}