Skip to content

Commit 6d5c60e

Browse files
authored
Move clamav on ECS (#4190)
1 parent 5277de4 commit 6d5c60e

File tree

6 files changed

+87
-18
lines changed

6 files changed

+87
-18
lines changed

infrastructure/applications/.terraform.lock.hcl

Lines changed: 0 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

infrastructure/applications/applications.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ module "pycon_backend" {
3434
}
3535
}
3636

37+
module "clamav" {
38+
source = "./clamav"
39+
cluster_id = module.cluster.cluster_id
40+
logs_group_name = module.cluster.logs_group_name
41+
42+
providers = {
43+
aws = aws
44+
aws.us = aws.us
45+
}
46+
}
47+
3748
# Other resources
3849

3950
module "database" {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
resource "aws_ecs_task_definition" "clamav" {
2+
family = "pythonit-${terraform.workspace}-clamav"
3+
4+
container_definitions = jsonencode([
5+
{
6+
name = "clamav"
7+
image = "clamav/clamav-debian:1.4.1"
8+
memoryReservation = 1000
9+
essential = true
10+
11+
portMappings = [
12+
{
13+
containerPort = 3310
14+
hostPort = 3310
15+
},
16+
]
17+
18+
mountPoints = []
19+
20+
logConfiguration = {
21+
logDriver = "awslogs"
22+
options = {
23+
"awslogs-group" = var.logs_group_name
24+
"awslogs-region" = "eu-central-1"
25+
"awslogs-stream-prefix" = "clamav"
26+
}
27+
}
28+
29+
healthCheck = {
30+
retries = 3
31+
command = [
32+
"CMD-SHELL",
33+
"echo 1"
34+
]
35+
timeout = 3
36+
interval = 10
37+
}
38+
39+
stopTimeout = 300
40+
}
41+
])
42+
43+
requires_compatibilities = []
44+
tags = {}
45+
}
46+
47+
resource "aws_ecs_service" "clamav" {
48+
name = "clamav"
49+
cluster = var.cluster_id
50+
task_definition = aws_ecs_task_definition.clamav.arn
51+
desired_count = 1
52+
deployment_minimum_healthy_percent = 0
53+
deployment_maximum_percent = 100
54+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
variable "cluster_id" {}
2+
variable "logs_group_name" {}

infrastructure/applications/cluster/security.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,25 @@ resource "aws_security_group_rule" "out_redis" {
4141
security_group_id = aws_security_group.server.id
4242
}
4343

44+
resource "aws_security_group_rule" "in_clamav" {
45+
type = "egress"
46+
from_port = 3310
47+
to_port = 3310
48+
protocol = "tcp"
49+
source_security_group_id = aws_security_group.server.id
50+
security_group_id = aws_security_group.server.id
51+
}
52+
53+
resource "aws_security_group_rule" "out_clamav" {
54+
# needed by fargate to connect to the server with clamav
55+
type = "ingress"
56+
from_port = 3310
57+
to_port = 3310
58+
protocol = "tcp"
59+
source_security_group_id = aws_security_group.server.id
60+
security_group_id = aws_security_group.server.id
61+
}
62+
4463
resource "aws_security_group_rule" "web_http" {
4564
type = "ingress"
4665
from_port = 80

infrastructure/applications/pycon_backend/worker.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ locals {
162162
},
163163
{
164164
name = "CLAMAV_HOST",
165-
value = module.secrets.value.clamav_host
165+
value = var.server_ip
166166
},
167167
{
168168
name = "ECS_NETWORK_CONFIG",

0 commit comments

Comments
 (0)