Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dwilkie committed Sep 11, 2024
1 parent 0441f39 commit c4f7ff7
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gateway_commons.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
[
{
"identifier": "gateway-commons-staging",
"branch": "modularize_infrastructure",
"branch": "develop",
"image_tag": "staging"
},
{
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/public_gateway.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
[
{
"identifier": "public-gateway-staging",
"branch": "modularize_infrastructure",
"branch": "develop",
"image_tag": "staging",
"ecs_service": "public-gateway-staging",
"ecs_cluster": "somleng-switch-staging",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
{
"identifier": "switch-services-staging",
"environment": "staging",
"branch": "modularize_infrastructure",
"branch": "develop",
"image_tag": "staging"
},
{
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/switch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
{
"identifier": "switch-staging",
"environment": "staging",
"branch": "modularize_infrastructure",
"branch": "develop",
"image_tag": "staging",
"ecs_service": "switch-staging",
"ecs_cluster": "somleng-switch-staging"
Expand Down
24 changes: 0 additions & 24 deletions infrastructure/modules/services/lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,6 @@ resource "aws_lambda_function" "this" {
}
}

resource "aws_lambda_permission" "this" {
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.this.arn
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.this.arn
}

resource "aws_cloudwatch_event_rule" "this" {
name = var.identifier

event_pattern = jsonencode({
source = ["aws.ecs"],
detail-type = ["ECS Task State Change"],
detail = {
clusterArn = [var.ecs_cluster.arn]
}
})
}

resource "aws_cloudwatch_event_target" "this" {
arn = aws_lambda_function.this.arn
rule = aws_cloudwatch_event_rule.this.id
}

resource "aws_lambda_event_source_mapping" "sqs" {
event_source_arn = aws_sqs_queue.this.arn
function_name = aws_lambda_function.this.arn
Expand Down
1 change: 0 additions & 1 deletion infrastructure/modules/services/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ variable "sip_alternative_port" {}
variable "public_gateway_db_name" {}
variable "client_gateway_db_name" {}
variable "media_proxy_ng_port" {}
variable "ecs_cluster" {}
4 changes: 4 additions & 0 deletions infrastructure/modules/switch/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,7 @@ output "target_group" {
output "target_event_bus" {
value = var.target_event_bus == null ? var.region.event_bus : var.target_event_bus
}

output "lb_rule_index" {
value = var.lb_rule_index
}
18 changes: 17 additions & 1 deletion infrastructure/production/ecs.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "aws_ecs_cluster" "this" {
name = "somleng-switch"
name = var.ecs_cluster_name
}

resource "aws_ecs_cluster_capacity_providers" "this" {
Expand All @@ -12,3 +12,19 @@ resource "aws_ecs_cluster_capacity_providers" "this" {
module.media_proxy.capacity_provider.name
]
}

resource "aws_ecs_cluster" "helium" {
name = var.ecs_cluster_name

provider = aws.helium
}

resource "aws_ecs_cluster_capacity_providers" "helium" {
cluster_name = aws_ecs_cluster.helium.name

capacity_providers = [
module.switch_helium.capacity_provider.name
]

provider = aws.helium
}
1 change: 0 additions & 1 deletion infrastructure/production/services.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ module "services" {
sip_alternative_port = var.sip_alternative_port
freeswitch_event_socket_port = var.freeswitch_event_socket_port
media_proxy_ng_port = module.media_proxy.ng_port
ecs_cluster = aws_ecs_cluster.this
}
41 changes: 41 additions & 0 deletions infrastructure/production/switch.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,47 @@ module "switch" {
alternative_rtp_ip = data.terraform_remote_state.core_infrastructure.outputs.hydrogen_region.nat_instance.public_ip
}

module "switch_helium" {
source = "../modules/switch"

region = data.terraform_remote_state.core_infrastructure.outputs.helium_region
ecs_cluster = aws_ecs_cluster.helium
external_rtp_ip = data.terraform_remote_state.core_infrastructure.outputs.helium_region.vpc.nat_public_ips[0]
alternative_sip_outbound_ip = data.terraform_remote_state.core_infrastructure.outputs.helium_region.vpc.nat_public_ips[0]
alternative_rtp_ip = data.terraform_remote_state.core_infrastructure.outputs.helium_region.vpc.nat_public_ips[0]
identifier = module.switch.identifier
lb_rule_index = module.switch.lb_rule_index
app_environment = module.switch.app_environment
json_cdr_url = module.switch.json_cdr_url
cache_name = module.switch.cache_name
recordings_bucket = module.switch.recordings_bucket
recordings_bucket_access_key_id_parameter = module.switch.recordings_bucket_access_key_id_parameter
recordings_bucket_secret_access_key_parameter = module.switch.recordings_bucket_secret_access_key_parameter
application_master_key_parameter = module.switch.application_master_key_parameter
rayo_password_parameter = module.switch.rayo_password_parameter
freeswitch_event_socket_password_parameter = module.switch.freeswitch_event_socket_password_parameter
container_instance_profile = module.switch.container_instances.iam_instance_profile
iam_task_role = module.switch.iam_task_role
iam_task_execution_role = module.switch.iam_task_execution_role
min_tasks = module.switch.min_tasks
max_tasks = module.switch.max_tasks
sip_port = module.switch.sip_port
sip_alternative_port = module.switch.sip_alternative_port
freeswitch_event_socket_port = module.switch.freeswitch_event_socket_port
json_cdr_password_parameter = module.switch.json_cdr_password_parameter
services_function = module.switch.services_function
app_image = module.switch.app_image
nginx_image = module.switch.nginx_image
freeswitch_image = module.switch.freeswitch_image
freeswitch_event_logger_image = module.switch.freeswitch_event_logger_image
internal_route53_zone = module.switch.internal_route53_zone
target_event_bus = module.switch.target_event_bus

providers = {
aws = aws.helium
}
}

resource "aws_route53_record" "switch_legacy" {
zone_id = data.terraform_remote_state.core_infrastructure.outputs.route53_zone_internal_somleng_org_old.zone_id
name = "switch"
Expand Down
4 changes: 4 additions & 0 deletions infrastructure/production/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ variable "app_environment" {
default = "production"
}

variable "ecs_cluster_name" {
default = "somleng-switch"
}

variable "switch_identifier" {
default = "switch"
}
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/staging/ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ resource "aws_ecs_cluster" "helium" {
}

resource "aws_ecs_cluster_capacity_providers" "helium" {
cluster_name = aws_ecs_cluster.this.name
cluster_name = aws_ecs_cluster.helium.name

capacity_providers = [
module.switch_helium.capacity_provider.name
Expand Down
1 change: 0 additions & 1 deletion infrastructure/staging/services.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ module "services" {
sip_alternative_port = var.sip_alternative_port
freeswitch_event_socket_port = var.freeswitch_event_socket_port
media_proxy_ng_port = module.media_proxy.ng_port
ecs_cluster = aws_ecs_cluster.this
}
2 changes: 1 addition & 1 deletion infrastructure/staging/switch.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ module "switch" {
module "switch_helium" {
source = "../modules/switch"

lb_rule_index = 121
region = data.terraform_remote_state.core_infrastructure.outputs.helium_region
ecs_cluster = aws_ecs_cluster.helium
external_rtp_ip = data.terraform_remote_state.core_infrastructure.outputs.helium_region.vpc.nat_public_ips[0]
alternative_sip_outbound_ip = data.terraform_remote_state.core_infrastructure.outputs.helium_region.vpc.nat_public_ips[0]
alternative_rtp_ip = data.terraform_remote_state.core_infrastructure.outputs.helium_region.vpc.nat_public_ips[0]
identifier = module.switch.identifier
lb_rule_index = module.switch.lb_rule_index
app_environment = module.switch.app_environment
json_cdr_url = module.switch.json_cdr_url
cache_name = module.switch.cache_name
Expand Down

0 comments on commit c4f7ff7

Please sign in to comment.