diff --git a/packer/web.pkr.hcl b/packer/web.pkr.hcl index f83e151..d176395 100644 --- a/packer/web.pkr.hcl +++ b/packer/web.pkr.hcl @@ -8,6 +8,11 @@ variable "aws_region" { default = "${env("AWS_REGION")}" } +variable "fathom_site_id" { + type = string + default = "${env("FATHOM_SITE_ID")}" +} + variable "s3_bucket" { type = string default = "${env("S3_BUCKET")}" @@ -81,6 +86,7 @@ build { environment_vars = [ "ADMIN_PASSWORD=${var.admin_password}", "AWS_REGION=${var.aws_region}", + "FATHOM_SITE_ID=${var.fathom_site_id}", "S3_BUCKET=${var.s3_bucket}", "SUPERVISOR_ACCESS_TOKEN=${var.supervisor_access_token}", ] diff --git a/tf/asg.tf b/tf/asg.tf index 9b2fa7e..4372705 100644 --- a/tf/asg.tf +++ b/tf/asg.tf @@ -78,12 +78,10 @@ resource "aws_launch_template" "server" { resource "aws_autoscaling_group" "server" { name = "riju-server" - availability_zones = [ - for subnet in data.aws_subnet.default : subnet.availability_zone - ] - desired_capacity = 1 - min_size = 1 - max_size = 3 + availability_zones = [local.primary_az] + desired_capacity = 1 + min_size = 1 + max_size = 3 launch_template { id = aws_launch_template.server.id diff --git a/tf/cloudwatch.tf b/tf/cloudwatch.tf index d37a845..e789878 100644 --- a/tf/cloudwatch.tf +++ b/tf/cloudwatch.tf @@ -60,7 +60,7 @@ resource "aws_cloudwatch_metric_alarm" "server_data_volume_disk_space" { insufficient_data_actions = [aws_sns_topic.riju.arn] dimensions = { AutoScalingGroupName = aws_autoscaling_group.server.name - path = "/mnt/riju/data" + path = "/mnt/riju" } tags = { diff --git a/tf/main.tf b/tf/main.tf index 6047721..5f002a7 100644 --- a/tf/main.tf +++ b/tf/main.tf @@ -55,3 +55,7 @@ data "aws_subnet" "default" { for_each = data.aws_subnet_ids.default.ids id = each.value } + +locals { + primary_az = sort([for subnet in data.aws_subnet.default : subnet.availability_zone])[0] +} diff --git a/tf/ssm.tf b/tf/ssm.tf index f03c6f1..7aa5675 100644 --- a/tf/ssm.tf +++ b/tf/ssm.tf @@ -1,3 +1,10 @@ +resource "aws_ssm_parameter" "web_ami_id" { + name = "riju-web-ami-id" + type = "String" + value = data.aws_ami.server.id + data_type = "aws:ec2:image" +} + resource "aws_ssm_parameter" "ci_ami_id" { name = "riju-ci-ami-id" type = "String" @@ -22,3 +29,9 @@ resource "aws_ssm_parameter" "s3_bucket" { type = "String" value = aws_s3_bucket.riju.bucket } + +resource "aws_ssm_parameter" "asg_desired_capacity" { + name = "riju-asg-desired-capacity" + type = "String" + value = aws_autoscaling_group.server.desired_capacity +}