mirror of
https://github.com/jambonz/jambonz-infrastructure.git
synced 2026-01-25 02:08:27 +00:00
major changes to support autoscaling feature servers
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,4 +3,4 @@
|
||||
*.tfstate
|
||||
*.tfstate.backup
|
||||
gcp.json
|
||||
|
||||
jambonz-mini/
|
||||
|
||||
30
README.md
30
README.md
@@ -2,9 +2,31 @@
|
||||
|
||||
This repository contains [packer](packer.io) and [terraform](terraform.io) scripts for deploying jambonz on AWS hosted infrastructure. Packer scripts build the necessary AMIs, and terraform scripts create the full AWS infrastructure using those AMIs.
|
||||
|
||||
There are 3 different deployment alternatives:
|
||||
A jambonz deployment provides both Session Border Controller (SBC) and feature server functionality. If you have an existing SBC that you want to use, you can place that in front of the jambonz servers if you wish (though it is not necessary) however you must in all cases deploy both the jambonz SBC and feature server components.
|
||||
|
||||
- a ["jambonz mini"](./terraform/jambonz-mini) deployment, consisting of a [single server](./packer/jambonz-mini)
|
||||
- a ["jambonz small"](./terraform/jambonz-small) deployment, consisting of one server for [SBC functionality](./packer/jambonz-sbc-sip-rtp) and a second server for [feature server functionality](./packer/jambonz-feature-server).
|
||||
- a ["jambonz standard"](./terraform/jambonz-standard) deployment, which provides redundancy and scalability and a fully-exploded functional architecture consisting instances for [SBC SIP signaling](./packer/jambonz-sbc-sip), a second set of instance for [SBC media handling](./packer/jambonz-sbc-rtp), and a third set of instances for [feature server](./packer/jambonz-feature-server).
|
||||
There are two supported deployment configurations:
|
||||
|
||||
- a [devtest](./terraform/jambonz-small) deployment suitable for development and testing purposes; this configuration consists of one jambonz [SBC server](./packer/jambonz-sbc-sip-rtp) and one [feature server](./packer/jambonz-feature-server).
|
||||
- a [production](./terraform/jambonz-standard) deployment; this configuration consists of two SBCs with [SIP](./packer/jambonz-sbc-sip) and [RTP](./packer/jambonz-sbc-rtp) handling separated onto different servers (i.e. 4 servers in total for SBC processing), and [feature servers](./packer/jambonz-feature-server) in an autoscale group.
|
||||
|
||||
#### autoscaling feature servers
|
||||
Both the devtest and production deployments create a single feature server in an autoscale group.
|
||||
|
||||
There is initially no scaling policy applied, but after running the terraform script and creating the infrastructure you can use the AWS console to apply a scaling policy (e.g. scale up when cpu > 60%) or a schedule (e.g. run 3 feature servers during the day and only one overnight) if you wish.
|
||||
|
||||
#### graceful scale-in
|
||||
The feature servers make use of AWS SNS lifecycle notifications to scale-in gracefully, allowing calls in progress to complete before shutting down. A maximum of 15 minutes is given for calls to complete; after that period any remaining calls will be torn down. This duration interval can be edited in the autoscale group configuration via the AWS console or cli if desired.
|
||||
|
||||
#### temporarily taking a feature server out of service
|
||||
If you want to temporarily take a feature server out of rotation (not receiving any calls from the SBCs), there is a two step process to do so:
|
||||
|
||||
1. Using the AWS console or cli, select the instance of the autoscale group and put it into Standby state.
|
||||
2. Once the instance is in standby state, ssh into the instance and send a SIGHUP signal to the node.js process running the feature server application. This will cause the feature server to send an OPTIONS request to the SBC indicating that it is out of service.
|
||||
|
||||
At that point, you need to wait for any calls in progress on the feature to dry up. Once they do, you can then perform your maintenance or troubleshooting as needed.
|
||||
|
||||
To bring the feature back into service once the maintenance is complete, do the following:
|
||||
|
||||
1. Using the AWS console or cli, select the instance of the autoscale group and put it back into the InService state.
|
||||
2. Once the instance is in the InService state, ssh into the instance and send a SIGHUP signal to the node.js process running the feature server application. This will cause the feature server to send an OPTIONS request to the SBC indicating that it is back in service.
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
<param name="sip-trace" value="no"/>
|
||||
<param name="rfc2833-pt" value="101"/>
|
||||
|
||||
<!-- should be able to be removed in v1.6.8 or later (ref: https://freeswitch.org/jira/browse/FS-9051) -->
|
||||
<param name="dtmf-type" value="rfc2833"/>
|
||||
|
||||
<param name="inbound-late-negotiation" value="true"/>
|
||||
|
||||
@@ -20,10 +20,9 @@ resource "aws_rds_cluster" "jambonz" {
|
||||
preferred_backup_window = "07:00-09:00"
|
||||
|
||||
scaling_configuration {
|
||||
auto_pause = true
|
||||
auto_pause = false
|
||||
min_capacity = 1
|
||||
max_capacity = 2
|
||||
seconds_until_auto_pause = 300
|
||||
}
|
||||
}
|
||||
|
||||
131
terraform/jambonz-devtest/feature-server.tf
Normal file
131
terraform/jambonz-devtest/feature-server.tf
Normal file
@@ -0,0 +1,131 @@
|
||||
# create an SNS notification topic
|
||||
resource "aws_sns_topic" "jambonz-sns-topic" {
|
||||
name = var.sns_topic
|
||||
}
|
||||
|
||||
# create an IAM role that allows publishing to the SNS topic
|
||||
#data "aws_iam_policy_document" "jambonz_sns_publish" {
|
||||
# statement {
|
||||
# actions = [
|
||||
# "sns:Publish"
|
||||
# ]
|
||||
|
||||
# resources = [
|
||||
# aws_sns_topic.jambonz-sns-topic.arn
|
||||
# ]
|
||||
# }
|
||||
#}
|
||||
|
||||
resource "aws_iam_role" "jambonz_sns_publish" {
|
||||
name = "jambonz_sns_publish"
|
||||
|
||||
assume_role_policy = <<EOF
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Principal": {
|
||||
"Service": [
|
||||
"autoscaling.amazonaws.com"
|
||||
]
|
||||
},
|
||||
"Action": "sts:AssumeRole"
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
resource "aws_iam_policy" "allow_jambonz_sns_publish" {
|
||||
policy = <<EOF
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Action": [
|
||||
"sns:Publish"
|
||||
],
|
||||
"Effect": "Allow",
|
||||
"Resource": "*"
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
resource "aws_iam_role_policy_attachment" "sns-publish-policy-attachment" {
|
||||
role = aws_iam_role.jambonz_sns_publish.name
|
||||
policy_arn = aws_iam_policy.allow_jambonz_sns_publish.arn
|
||||
}
|
||||
|
||||
# select the most recent jambonz AMIs
|
||||
data "aws_ami" "jambonz-feature-server" {
|
||||
most_recent = true
|
||||
name_regex = "^jambonz-feature-server"
|
||||
owners = ["376029039784"]
|
||||
}
|
||||
|
||||
# create a launch configuration
|
||||
resource "aws_launch_configuration" "jambonz-feature-server" {
|
||||
image_id = data.aws_ami.jambonz-feature-server.id
|
||||
instance_type = var.ec2_instance_type
|
||||
associate_public_ip_address = true
|
||||
security_groups = [aws_security_group.allow_jambonz_feature_server.id]
|
||||
key_name = var.key_name
|
||||
user_data = templatefile("${path.module}/feature-server.ecosystem.config.js.tmpl", {
|
||||
VPC_CIDR = var.vpc_cidr_block
|
||||
JAMBONES_SBC_SIP_IPS = join(",", var.jambonz_sbc_sip_rtp_private_ips)
|
||||
JAMBONES_MYSQL_HOST = aws_rds_cluster.jambonz.endpoint
|
||||
JAMBONES_MYSQL_USER = aws_rds_cluster.jambonz.master_username
|
||||
JAMBONES_MYSQL_PASSWORD = aws_rds_cluster.jambonz.master_password
|
||||
JAMBONES_REDIS_HOST = aws_elasticache_cluster.jambonz.cache_nodes.0.address
|
||||
AWS_ACCESS_KEY_ID = var.aws_access_key_id_runtime
|
||||
AWS_SECRET_ACCESS_KEY = var.aws_secret_access_key_runtime
|
||||
AWS_REGION = var.region
|
||||
AWS_SNS_TOPIC_ARN = aws_sns_topic.jambonz-sns-topic.arn
|
||||
})
|
||||
|
||||
lifecycle {
|
||||
create_before_destroy = true
|
||||
}
|
||||
}
|
||||
|
||||
# create a placement group to spread feature server instances
|
||||
resource "aws_placement_group" "jambonz-feature-server" {
|
||||
name = "jambonz-feature-server"
|
||||
strategy = "spread"
|
||||
}
|
||||
|
||||
# create an autoscaling group
|
||||
resource "aws_autoscaling_group" "jambonz-feature-server" {
|
||||
min_size = 1
|
||||
max_size = 2
|
||||
desired_capacity = 1
|
||||
force_delete = true
|
||||
placement_group = aws_placement_group.jambonz-feature-server.id
|
||||
launch_configuration = aws_launch_configuration.jambonz-feature-server.name
|
||||
termination_policies = ["OldestInstance"]
|
||||
vpc_zone_identifier = local.my_subnet_ids
|
||||
|
||||
tag {
|
||||
key = "Name"
|
||||
value = "jambonz-feature-server"
|
||||
propagate_at_launch = true
|
||||
}
|
||||
|
||||
lifecycle {
|
||||
create_before_destroy = true
|
||||
}
|
||||
}
|
||||
|
||||
# create lifecycle hooks
|
||||
resource "aws_autoscaling_lifecycle_hook" "jambonz-scale-in" {
|
||||
name = "jambonz-scale-in"
|
||||
autoscaling_group_name = aws_autoscaling_group.jambonz-feature-server.name
|
||||
default_result = "CONTINUE"
|
||||
heartbeat_timeout = 900
|
||||
lifecycle_transition = "autoscaling:EC2_INSTANCE_TERMINATING"
|
||||
notification_target_arn = aws_sns_topic.jambonz-sns-topic.arn
|
||||
role_arn = aws_iam_role.jambonz_sns_publish.arn
|
||||
}
|
||||
@@ -36,7 +36,7 @@ resource "aws_default_route_table" "jambonz" {
|
||||
}
|
||||
}
|
||||
|
||||
# create a public subnet
|
||||
# create public subnets
|
||||
resource "aws_subnet" "jambonz" {
|
||||
for_each = var.public_subnets
|
||||
|
||||
@@ -26,7 +26,6 @@ module.exports = {
|
||||
JAMBONES_REDIS_PORT: 6379,
|
||||
JAMBONES_LOGLEVEL: 'info',
|
||||
JAMBONE_API_VERSION: 'v1',
|
||||
JAMBONES_CREATE_CALL_URL: 'http://${JAMBONES_FEATURE_SERVER_FOR_API_CALLS}:3000/v1/createCall',
|
||||
HTTP_PORT: 3000
|
||||
},
|
||||
},
|
||||
@@ -106,6 +105,7 @@ module.exports = {
|
||||
JAMBONES_MYSQL_CONNECTION_LIMIT: 10,
|
||||
JAMBONES_REDIS_HOST: '${JAMBONES_REDIS_HOST}',
|
||||
JAMBONES_REDIS_PORT: 6379,
|
||||
MS_TEAMS_FQDN: '${MS_TEAMS_FQDN}'
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -127,7 +127,6 @@ module.exports = {
|
||||
DRACHTIO_HOST: '127.0.0.1',
|
||||
DRACHTIO_PORT: 9022,
|
||||
DRACHTIO_SECRET: 'cymru',
|
||||
JAMBONES_FEATURE_SERVERS: '${JAMBONES_FEATURE_SERVER_IPS}',
|
||||
JAMBONES_RTPENGINES: '${JAMBONES_RTPENGINE_IPS}',
|
||||
JAMBONES_MYSQL_HOST: '${JAMBONES_MYSQL_HOST}',
|
||||
JAMBONES_MYSQL_USER: '${JAMBONES_MYSQL_USER}',
|
||||
@@ -136,6 +135,8 @@ module.exports = {
|
||||
JAMBONES_MYSQL_CONNECTION_LIMIT: 10,
|
||||
JAMBONES_REDIS_HOST: '${JAMBONES_REDIS_HOST}',
|
||||
JAMBONES_REDIS_PORT: 6379,
|
||||
JAMBONES_CLUSTER_ID: '${JAMBONES_CLUSTER_ID}',
|
||||
MS_TEAMS_SIP_PROXY_IPS: '52.114.148.0, 52.114.132.46, 52.114.75.24, 52.114.76.76, 52.114.7.24, 52.114.14.70'
|
||||
}
|
||||
}]
|
||||
};
|
||||
63
terraform/jambonz-devtest/sbc.tf
Normal file
63
terraform/jambonz-devtest/sbc.tf
Normal file
@@ -0,0 +1,63 @@
|
||||
# Create SBC SIP+RTP instance
|
||||
data "aws_ami" "jambonz-sbc-sip-rtp" {
|
||||
most_recent = true
|
||||
name_regex = "^jambonz-sbc-sip-rtp"
|
||||
owners = ["376029039784"]
|
||||
}
|
||||
resource "aws_eip" "jambonz-sbc-sip-rtp" {
|
||||
count = length(var.jambonz_sbc_sip_rtp_private_ips)
|
||||
|
||||
instance = aws_instance.jambonz-sbc-sip-rtp-server[count.index].id
|
||||
vpc = true
|
||||
}
|
||||
resource "aws_instance" "jambonz-sbc-sip-rtp-server" {
|
||||
count = length(var.jambonz_sbc_sip_rtp_private_ips)
|
||||
|
||||
ami = data.aws_ami.jambonz-sbc-sip-rtp.id
|
||||
instance_type = var.ec2_instance_type
|
||||
private_ip = var.jambonz_sbc_sip_rtp_private_ips[count.index]
|
||||
subnet_id = local.my_subnet_ids[count.index]
|
||||
vpc_security_group_ids = [aws_security_group.allow_jambonz_sbc_sip_rtp.id]
|
||||
user_data = templatefile("${path.module}/sbc-sip-rtp-server.ecosystem.config.js.tmpl", {
|
||||
VPC_CIDR = var.vpc_cidr_block
|
||||
JAMBONES_SBC_SIP_IPS = join(",", var.jambonz_sbc_sip_rtp_private_ips)
|
||||
JAMBONES_RTPENGINE_IPS = join(",", local.rtpengine_hostports)
|
||||
JAMBONES_MYSQL_HOST = aws_rds_cluster.jambonz.endpoint
|
||||
JAMBONES_MYSQL_USER = aws_rds_cluster.jambonz.master_username
|
||||
JAMBONES_MYSQL_PASSWORD = aws_rds_cluster.jambonz.master_password
|
||||
JAMBONES_REDIS_HOST = aws_elasticache_cluster.jambonz.cache_nodes.0.address
|
||||
MS_TEAMS_FQDN = var.ms_teams_fqdn
|
||||
JAMBONES_CLUSTER_ID = var.cluster_id
|
||||
})
|
||||
key_name = var.key_name
|
||||
monitoring = true
|
||||
|
||||
depends_on = [aws_internet_gateway.jambonz, aws_elasticache_cluster.jambonz, aws_rds_cluster.jambonz]
|
||||
|
||||
tags = {
|
||||
Name = "jambonz-sbc-sip-rtp-server"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# seed the database, from the SBC server
|
||||
resource "null_resource" "seed" {
|
||||
|
||||
# Bootstrap script can run on any instance of the cluster
|
||||
# So we just choose the first in this case
|
||||
connection {
|
||||
type = "ssh"
|
||||
user = "admin"
|
||||
host = element(aws_eip.jambonz-sbc-sip-rtp.*.public_ip, 0)
|
||||
}
|
||||
|
||||
provisioner "remote-exec" {
|
||||
inline = [
|
||||
"mysql -h ${aws_rds_cluster.jambonz.endpoint} -u admin -D jambones -pJambonzR0ck$ < /home/admin/apps/jambonz-api-server/db/jambones-sql.sql",
|
||||
"mysql -h ${aws_rds_cluster.jambonz.endpoint} -u admin -D jambones -pJambonzR0ck$ < /home/admin/apps/jambonz-api-server/db/create-admin-token.sql",
|
||||
"mysql -h ${aws_rds_cluster.jambonz.endpoint} -u admin -D jambones -pJambonzR0ck$ < /home/admin/apps/jambonz-api-server/db/create-default-account.sql"
|
||||
]
|
||||
}
|
||||
|
||||
depends_on = [aws_rds_cluster.jambonz, aws_instance.jambonz-sbc-sip-rtp-server, aws_eip.jambonz-sbc-sip-rtp]
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
variable "region" {
|
||||
description = "the aws region in which to create the VPC"
|
||||
default = "us-east-1"
|
||||
default = "us-west-2"
|
||||
}
|
||||
variable "vpc_cidr_block" {
|
||||
description = "the CIDR block for the whole VPC"
|
||||
@@ -9,18 +9,14 @@ variable "vpc_cidr_block" {
|
||||
variable "public_subnets" {
|
||||
type = map(string)
|
||||
default = {
|
||||
"us-east-1a" = "172.31.32.0/24"
|
||||
"us-east-1b" = "172.31.33.0/24"
|
||||
"us-west-2a" = "172.31.32.0/24"
|
||||
"us-west-2b" = "172.31.33.0/24"
|
||||
}
|
||||
}
|
||||
variable "jambonz_sbc_sip_rtp_private_ips" {
|
||||
type = list(string)
|
||||
default = ["172.31.32.10"]
|
||||
}
|
||||
variable "jambonz_feature_server_private_ips" {
|
||||
type = list(string)
|
||||
default = ["172.31.32.100"]
|
||||
}
|
||||
variable "ec2_instance_type" {
|
||||
description = "the EC2 instance type to use for the jambonz server"
|
||||
default = "t2.medium"
|
||||
@@ -37,3 +33,15 @@ variable "aws_secret_access_key_runtime" {
|
||||
description = "AWS secret access key jambonz will use to access AWS Polly TTS"
|
||||
default = "your-aws-secret_access-key"
|
||||
}
|
||||
variable "sns_topic" {
|
||||
description = "AWS SNS topic for autoscale events"
|
||||
default = "jambonz-fs-lifecycle-events"
|
||||
}
|
||||
variable "ms_teams_fqdn" {
|
||||
description = "Microsoft Teams FQDN"
|
||||
default = ""
|
||||
}
|
||||
variable "cluster_id" {
|
||||
description = "short cluster identifier"
|
||||
default = "jb"
|
||||
}
|
||||
@@ -144,6 +144,7 @@ module.exports = {
|
||||
JAMBONES_MYSQL_CONNECTION_LIMIT: 10,
|
||||
JAMBONES_REDIS_HOST: '${JAMBONES_REDIS_HOST}',
|
||||
JAMBONES_REDIS_PORT: 6379,
|
||||
MS_TEAMS_FQDN: ${MS_TEAMS_FQDN}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -174,6 +175,7 @@ module.exports = {
|
||||
JAMBONES_MYSQL_CONNECTION_LIMIT: 10,
|
||||
JAMBONES_REDIS_HOST: '${JAMBONES_REDIS_HOST}',
|
||||
JAMBONES_REDIS_PORT: 6379,
|
||||
MS_TEAMS_SIP_PROXY_IPS: [52.114.148.0, 52.114.132.46, 52.114.75.24, 52.114.76.76, 52.114.7.24, 52.114.14.70]
|
||||
}
|
||||
}]
|
||||
};
|
||||
|
||||
@@ -20,6 +20,7 @@ module.exports = {
|
||||
AWS_ACCESS_KEY_ID: '${AWS_ACCESS_KEY_ID}',
|
||||
AWS_SECRET_ACCESS_KEY: '${AWS_SECRET_ACCESS_KEY}',
|
||||
AWS_REGION: '${AWS_REGION}',
|
||||
AWS_SNS_TOPIC_ARM: '${AWS_SNS_TOPIC_ARN}',
|
||||
ENABLE_DATADOG_METRICS: 0,
|
||||
ENABLE_DATADOG_METRICS: 0,
|
||||
JAMBONES_NETWORK_CIDR: '${VPC_CIDR}',
|
||||
@@ -38,7 +39,7 @@ module.exports = {
|
||||
JAMBONES_SBCS: '${JAMBONES_SBC_SIP_IPS}',
|
||||
JAMBONES_FEATURE_SERVERS: '127.0.0.1:9022:cymru',
|
||||
JAMBONES_FREESWITCH: '127.0.0.1:8021:JambonzR0ck$'
|
||||
}
|
||||
}
|
||||
}]
|
||||
};
|
||||
EOF
|
||||
@@ -135,6 +135,7 @@ module.exports = {
|
||||
JAMBONES_MYSQL_CONNECTION_LIMIT: 10,
|
||||
JAMBONES_REDIS_HOST: '${JAMBONES_REDIS_HOST}',
|
||||
JAMBONES_REDIS_PORT: 6379,
|
||||
JAMBONES_CLUSTER_ID: '${JAMBONES_CLUSTER_ID}',
|
||||
MS_TEAMS_SIP_PROXY_IPS: '52.114.148.0, 52.114.132.46, 52.114.75.24, 52.114.76.76, 52.114.7.24, 52.114.14.70'
|
||||
}
|
||||
}]
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
# Create SBC SIP instances
|
||||
data "aws_ami" "jambonz-sbc-sip" {
|
||||
most_recent = true
|
||||
@@ -21,8 +20,6 @@ resource "aws_instance" "jambonz-sbc-sip-server" {
|
||||
vpc_security_group_ids = [aws_security_group.allow_jambonz_sbc_sip.id]
|
||||
user_data = templatefile("${path.module}/sbc-sip-server.ecosystem.config.js.tmpl", {
|
||||
VPC_CIDR = var.vpc_cidr_block
|
||||
JAMBONES_FEATURE_SERVER_FOR_API_CALLS = var.jambonz_feature_server_private_ips[0]
|
||||
JAMBONES_FEATURE_SERVER_IPS = join(",", var.jambonz_feature_server_private_ips)
|
||||
JAMBONES_SBC_SIP_IPS = join(",", var.jambonz_sbc_sip_private_ips)
|
||||
JAMBONES_RTPENGINE_IPS = join(",", local.rtpengine_hostports)
|
||||
JAMBONES_MYSQL_HOST = aws_rds_cluster.jambonz.endpoint
|
||||
@@ -30,6 +27,7 @@ resource "aws_instance" "jambonz-sbc-sip-server" {
|
||||
JAMBONES_MYSQL_PASSWORD = aws_rds_cluster.jambonz.master_password
|
||||
JAMBONES_REDIS_HOST = aws_elasticache_cluster.jambonz.cache_nodes.0.address
|
||||
MS_TEAMS_FQDN = var.ms_teams_fqdn
|
||||
JAMBONES_CLUSTER_ID = var.cluster_id
|
||||
})
|
||||
key_name = var.key_name
|
||||
monitoring = true
|
||||
@@ -86,7 +84,8 @@ resource "null_resource" "seed" {
|
||||
inline = [
|
||||
"mysql -h ${aws_rds_cluster.jambonz.endpoint} -u admin -D jambones -pJambonzR0ck$ < /home/admin/apps/jambonz-api-server/db/jambones-sql.sql",
|
||||
"mysql -h ${aws_rds_cluster.jambonz.endpoint} -u admin -D jambones -pJambonzR0ck$ < /home/admin/apps/jambonz-api-server/db/create-admin-token.sql",
|
||||
]
|
||||
"mysql -h ${aws_rds_cluster.jambonz.endpoint} -u admin -D jambones -pJambonzR0ck$ < /home/admin/apps/jambonz-api-server/db/create-default-account.sql"
|
||||
]
|
||||
}
|
||||
|
||||
depends_on = [aws_rds_cluster.jambonz, aws_instance.jambonz-sbc-sip-server]
|
||||
@@ -21,10 +21,6 @@ variable "jambonz_sbc_rtp_private_ips" {
|
||||
type = list(string)
|
||||
default = ["172.31.32.20", "172.31.33.20"]
|
||||
}
|
||||
variable "jambonz_feature_server_private_ips" {
|
||||
type = list(string)
|
||||
default = ["172.31.32.100", "172.31.33.100"]
|
||||
}
|
||||
variable "ec2_instance_type" {
|
||||
description = "the EC2 instance type to use for the jambonz server"
|
||||
default = "t2.micro"
|
||||
@@ -48,4 +44,8 @@ variable "sns_topic" {
|
||||
variable "ms_teams_fqdn" {
|
||||
description = "Microsoft Teams FQDN"
|
||||
default = ""
|
||||
}
|
||||
variable "cluster_id" {
|
||||
description = "short cluster identifier"
|
||||
default = "jb"
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
# Create feature server instance
|
||||
# select the most recent jambonz AMIs
|
||||
data "aws_ami" "jambonz-feature-server" {
|
||||
most_recent = true
|
||||
name_regex = "^jambonz-feature-server"
|
||||
owners = ["376029039784"]
|
||||
}
|
||||
|
||||
# create an elastic IP and copy google credentials into place
|
||||
resource "aws_eip" "jambonz-feature-server" {
|
||||
count = length(var.jambonz_feature_server_private_ips)
|
||||
|
||||
instance = aws_instance.jambonz-feature-server[count.index].id
|
||||
vpc = true
|
||||
|
||||
# copy user-provided google application credentials file
|
||||
provisioner "file" {
|
||||
source = "credentials/"
|
||||
destination = "/home/admin/credentials"
|
||||
|
||||
connection {
|
||||
type = "ssh"
|
||||
user = "admin"
|
||||
host = self.public_ip
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# create the jambonz feature server instance
|
||||
resource "aws_instance" "jambonz-feature-server" {
|
||||
count = length(var.jambonz_feature_server_private_ips)
|
||||
|
||||
ami = data.aws_ami.jambonz-feature-server.id
|
||||
instance_type = var.ec2_instance_type
|
||||
private_ip = var.jambonz_feature_server_private_ips[count.index]
|
||||
subnet_id = local.my_subnet_ids[count.index]
|
||||
vpc_security_group_ids = [aws_security_group.allow_jambonz_feature_server.id]
|
||||
user_data = templatefile("${path.module}/feature-server.ecosystem.config.js.tmpl", {
|
||||
VPC_CIDR = var.vpc_cidr_block
|
||||
JAMBONES_SBC_SIP_IPS = join(",", var.jambonz_sbc_sip_rtp_private_ips)
|
||||
JAMBONES_MYSQL_HOST = aws_rds_cluster.jambonz.endpoint
|
||||
JAMBONES_MYSQL_USER = aws_rds_cluster.jambonz.master_username
|
||||
JAMBONES_MYSQL_PASSWORD = aws_rds_cluster.jambonz.master_password
|
||||
JAMBONES_REDIS_HOST = aws_elasticache_cluster.jambonz.cache_nodes.0.address
|
||||
AWS_ACCESS_KEY_ID = var.aws_access_key_id_runtime
|
||||
AWS_SECRET_ACCESS_KEY = var.aws_secret_access_key_runtime
|
||||
AWS_REGION = var.region
|
||||
})
|
||||
key_name = var.key_name
|
||||
monitoring = true
|
||||
|
||||
depends_on = [aws_internet_gateway.jambonz, aws_elasticache_cluster.jambonz, aws_rds_cluster.jambonz]
|
||||
|
||||
tags = {
|
||||
Name = "jambonz-feature-server"
|
||||
}
|
||||
}
|
||||
|
||||
# Create SBC SIP+RTP instance
|
||||
data "aws_ami" "jambonz-sbc-sip-rtp" {
|
||||
most_recent = true
|
||||
name_regex = "^jambonz-sbc-sip-rtp"
|
||||
owners = ["376029039784"]
|
||||
}
|
||||
resource "aws_eip" "jambonz-sbc-sip-rtp" {
|
||||
count = length(var.jambonz_sbc_sip_rtp_private_ips)
|
||||
|
||||
instance = aws_instance.jambonz-sbc-sip-rtp-server[count.index].id
|
||||
vpc = true
|
||||
}
|
||||
resource "aws_instance" "jambonz-sbc-sip-rtp-server" {
|
||||
count = length(var.jambonz_sbc_sip_rtp_private_ips)
|
||||
|
||||
ami = data.aws_ami.jambonz-sbc-sip-rtp.id
|
||||
instance_type = var.ec2_instance_type
|
||||
private_ip = var.jambonz_sbc_sip_rtp_private_ips[count.index]
|
||||
subnet_id = local.my_subnet_ids[count.index]
|
||||
vpc_security_group_ids = [aws_security_group.allow_jambonz_sbc_sip_rtp.id]
|
||||
user_data = templatefile("${path.module}/sbc-sip-rtp-server.ecosystem.config.js.tmpl", {
|
||||
VPC_CIDR = var.vpc_cidr_block
|
||||
JAMBONES_FEATURE_SERVER_FOR_API_CALLS = var.jambonz_feature_server_private_ips[0]
|
||||
JAMBONES_FEATURE_SERVER_IPS = join(",", var.jambonz_feature_server_private_ips)
|
||||
JAMBONES_SBC_SIP_IPS = join(",", var.jambonz_sbc_sip_rtp_private_ips)
|
||||
JAMBONES_RTPENGINE_IPS = join(",", local.rtpengine_hostports)
|
||||
JAMBONES_MYSQL_HOST = aws_rds_cluster.jambonz.endpoint
|
||||
JAMBONES_MYSQL_USER = aws_rds_cluster.jambonz.master_username
|
||||
JAMBONES_MYSQL_PASSWORD = aws_rds_cluster.jambonz.master_password
|
||||
JAMBONES_REDIS_HOST = aws_elasticache_cluster.jambonz.cache_nodes.0.address
|
||||
})
|
||||
key_name = var.key_name
|
||||
monitoring = true
|
||||
|
||||
depends_on = [aws_internet_gateway.jambonz, aws_elasticache_cluster.jambonz, aws_rds_cluster.jambonz]
|
||||
|
||||
tags = {
|
||||
Name = "jambonz-sbc-sip-rtp-server"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# seed the database, from one of the feature servers
|
||||
resource "null_resource" "seed" {
|
||||
|
||||
# Bootstrap script can run on any instance of the cluster
|
||||
# So we just choose the first in this case
|
||||
connection {
|
||||
type = "ssh"
|
||||
user = "admin"
|
||||
host = element(aws_eip.jambonz-sbc-sip-rtp.*.public_ip, 0)
|
||||
}
|
||||
|
||||
provisioner "remote-exec" {
|
||||
inline = [
|
||||
"mysql -h ${aws_rds_cluster.jambonz.endpoint} -u admin -D jambones -pJambonzR0ck$ < /home/admin/apps/jambonz-api-server/db/jambones-sql.sql",
|
||||
"mysql -h ${aws_rds_cluster.jambonz.endpoint} -u admin -D jambones -pJambonzR0ck$ < /home/admin/apps/jambonz-api-server/db/create-admin-token.sql",
|
||||
]
|
||||
}
|
||||
|
||||
depends_on = [aws_rds_cluster.jambonz, aws_instance.jambonz-sbc-sip-rtp-server]
|
||||
}
|
||||
Reference in New Issue
Block a user