Skip to content

Commit 064029f

Browse files
committed
Fixed format and docs.
1 parent 40edf2a commit 064029f

File tree

6 files changed

+78
-48
lines changed

6 files changed

+78
-48
lines changed

terraform/components/full-cluster/cfb-container.json.tpl

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,20 @@
77
"essential": true,
88
"portMappings": [
99
{
10-
"containerPort": 8080,
10+
"containerPort": 3000,
1111
"hostPort": 0
1212
}
1313
],
1414
"environment": [
1515
{ "name" : "VUE_APP_BASE_API_URL", "value" : "${vue_app_base_api_url}" },
1616
{ "name" : "NODE_ENV", "value" : "${node_env}" },
1717
{ "name" : "DATABASE_HOST", "value" : "${database_host}" },
18-
{ "name" : "DATABASE_USER", "value" : "${database_user}" },
18+
{ "name" : "DATABASE_USERNAME", "value" : "${database_user}" },
1919
{ "name" : "DATABASE_PORT", "value" : "${database_port}" },
2020
{ "name" : "DATABASE_NAME", "value" : "${database_name}" },
2121
{ "name" : "JWT_KEY", "value" : "${jwt_key}" },
22-
{ "name" : "BYPASS_LOGIN", "value" : "${bypass_login}" }
23-
],
24-
"secrets": [{
25-
"name": "DATABASE_PASSWORD",
26-
"valueFrom": "${database_password_arn}"
27-
}]
22+
{ "name" : "BYPASS_LOGIN", "value" : "${bypass_login}" },
23+
{ "name" : "DATABASE_PASSWORD", "value" : "${database_password}" }
24+
]
2825
}
2926
]

terraform/components/full-cluster/main.tf

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,25 @@ module "s3" {
2525
data "template_file" "cfb_ecs_task_definition" {
2626
template = file("cfb-container.json.tpl")
2727
vars = {
28-
image_address = module.ecs_cluster.cfb_registry
29-
s3_bucket = module.s3.output_bucket_name
30-
vue_app_base_api_url = "bmoreres.codeforbaltimore.org"
31-
node_env = "development"
32-
database_host = module.db.this_db_instance_address
33-
database_user = module.db.this_db_instance_username
34-
database_password_arn = aws_secretsmanager_secret_version.db_password.arn
35-
database_port = module.db.this_db_instance_port
36-
database_name = "healthcareRollcallDB"
37-
jwt_key = "abc123"
38-
bypass_login = "false"
28+
image_address = "codeforbaltimore/bmore-responsive"
29+
s3_bucket = module.s3.output_bucket_name
30+
vue_app_base_api_url = "bmoreres.codeforbaltimore.org"
31+
node_env = "development"
32+
database_host = module.db.this_db_instance_address
33+
database_user = module.db.this_db_instance_username
34+
// database_password_arn = aws_secretsmanager_secret_version.db_password.arn
35+
database_port = module.db.this_db_instance_port
36+
database_name = "healthcareRollcallDB"
37+
jwt_key = "abc123"
38+
bypass_login = "false"
39+
aws_region = var.aws_region
40+
database_password = var.db_password
3941
}
4042
}
4143

4244
resource "aws_secretsmanager_secret" "db_password" {
4345
name_prefix = "db_password"
44-
46+
4547
}
4648

4749
resource "aws_secretsmanager_secret_version" "db_password" {
@@ -96,7 +98,7 @@ module "alb" {
9698
vpc_id = module.vpc.vpc-id
9799
vpc_subnets = module.vpc.public-subnet-ids
98100
lb_sg = module.sg.alb-sg-id
99-
cfb_app_port = 8080
101+
cfb_app_port = 3000
100102
certificate_arn = module.certificate.certificate_arn
101103
}
102104

@@ -114,8 +116,9 @@ module "ecs_cluster" {
114116
bmore-responsive_desired_count = "3"
115117
bmore-responsive_target_group_arn = module.alb.tg-cfb-arn
116118
bmore-responsive_container_name = "bmore-responsive"
117-
bmore-responsive_container_port = "8080"
119+
bmore-responsive_container_port = "3000"
118120
bmore-responsive_container_definitions = data.template_file.cfb_ecs_task_definition.rendered
121+
aws_region = var.aws_region
119122
}
120123

121124
module "asg" {
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
#!/bin/bash
22

3-
# Install the SSM Agent RPM
4-
yum install -y amazon-ssm-agent
5-
6-
yum install -y postgresql-server postgresql-devel
7-
83
echo ECS_CLUSTER=${cluster_name} >> /etc/ecs/ecs.config

terraform/modules/ecs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
| Name | Description | Type | Default | Required |
1313
|------|-------------|------|---------|:-----:|
14+
| aws\_region | n/a | `any` | n/a | yes |
1415
| bmore-responsive\_container\_definitions | The Rendered JSON of a container definition array. See example-container.json for a sample of valid JSON input. | `string` | n/a | yes |
1516
| bmore-responsive\_container\_name | The name of the container to associate with the Load Balancer. Must equal the container name in the container definition JSON | `string` | n/a | yes |
1617
| bmore-responsive\_container\_port | The port on the container to associate with the Load Balancer | `string` | n/a | yes |

terraform/modules/ecs/main.tf

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ data "aws_iam_policy_document" "ecs_cluster_asg_policy" {
6969
}
7070
}
7171

72+
data "aws_caller_identity" "current" {}
73+
7274
resource "aws_iam_role" "ecs_cluster" {
7375
path = "/"
7476
name = "bmore-responsive_ecs_cluster_role"
@@ -148,31 +150,62 @@ EOF
148150

149151
}
150152

151-
resource "aws_iam_role" "task_execution_role" {
152-
name = "ecsTaskExecutionRole"
153-
assume_role_policy = <<EOF
154-
{
155-
"Version": "2012-10-17",
156-
"Statement": [
157-
{
158-
"Effect": "Allow",
159-
"Principal": {
160-
"AWS": "${aws_iam_role.ecs_cluster.arn}"
161-
},
162-
"Action": [
163-
"ssm:GetParameters",
164-
"secretsmanager:GetSecretValue",
165-
"kms:Decrypt"
166-
]
153+
data "aws_iam_policy_document" "task_execution_role_permission_policy_document" {
154+
statement {
155+
effect = "Allow"
156+
actions = [
157+
"ssm:GetParameters",
158+
"secretsmanager:GetSecretValue",
159+
"kms:Decrypt"
160+
]
161+
resources = [
162+
"arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/*",
163+
"arn:aws:secretsmanager:${var.aws_region}:${data.aws_caller_identity.current.account_id}:secret:*",
164+
"arn:aws:kms:${var.aws_region}:${data.aws_caller_identity.current.account_id}:key/*"
165+
]
166+
}
167+
168+
statement {
169+
170+
effect = "Allow"
171+
actions = [
172+
"logs:CreateLogGroup"
173+
]
174+
resources = [
175+
"*"
176+
]
177+
}
178+
}
179+
180+
resource "aws_iam_policy" "task_execution_role_permission_policy" {
181+
name_prefix = "secrets-manager-access-"
182+
policy = data.aws_iam_policy_document.task_execution_role_permission_policy_document.json
183+
}
184+
185+
data "aws_iam_policy_document" "task_execution_role_assume_role_policy_document" {
186+
statement {
187+
effect = "Allow"
188+
principals {
189+
identifiers = ["ecs-tasks.amazonaws.com"]
190+
type = "Service"
167191
}
168-
]
192+
actions = ["sts:AssumeRole"]
193+
}
169194
}
170-
EOF
195+
196+
resource "aws_iam_role" "task_execution_role" {
197+
name = "ecsTaskExecutionRole"
198+
assume_role_policy = data.aws_iam_policy_document.task_execution_role_assume_role_policy_document.json
171199
}
172200

173201
resource "aws_iam_role_policy_attachment" "task_execution_attachment" {
174202
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy" // AWS provided policy
175-
role = "${aws_iam_role.task_execution_role.name}"
203+
role = aws_iam_role.task_execution_role.name
204+
}
205+
206+
resource "aws_iam_role_policy_attachment" "task_execution_permissions_policy_attachment" {
207+
policy_arn = aws_iam_policy.task_execution_role_permission_policy.arn
208+
role = aws_iam_role.task_execution_role.name
176209
}
177210

178211

@@ -183,8 +216,8 @@ resource "aws_ecs_cluster" "ecs_cluster" {
183216
resource "aws_ecs_task_definition" "bmore-responsive_ecs_task_definition" {
184217
family = "bmore-responsive"
185218
container_definitions = var.bmore-responsive_container_definitions
186-
task_role_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
187-
execution_role_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
219+
// task_role_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
220+
execution_role_arn = aws_iam_role.task_execution_role.arn
188221
}
189222

190223
resource "aws_ecs_service" "pricer_ecs_service" {

terraform/modules/ecs/variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ variable "output_bucket_arn" {
3333
type = string
3434
}
3535

36+
variable "aws_region" {}

0 commit comments

Comments
 (0)