Skip to content

Commit 5e34af3

Browse files
author
N P
committed
feat(ecs-exec): Enables ECS Exec support
1 parent 0be26b2 commit 5e34af3

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,13 @@ that generates this file and the crawl job can fail fast if it cannot locate it.
223223
relating to WP2Static, [raise an issue on their repo](https://github.com/leonstafford/wp2static/issues).
224224
For any issues relating to this module, [raise an issue against this repo.](https://github.com/TechToSpeech/terraform-aws-serverless-static-wordpress/issues)
225225

226+
227+
### Connecting to container with ECS Exec
228+
229+
ECS Exec is supported to help troubleshooting container issues. Read to [AWS Docs](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html) for usage instructions.
230+
231+
It's recommended that the `ecs_healthcheck_enabled` variable is set to `false` to prevent the container from being terminated and replaced while troubleshooting.
232+
226233
## Inputs
227234

228235
| Name | Description | Type | Default | Required |

ecs.tf

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ data "aws_iam_policy_document" "wordpress_bucket_access" {
4444
}
4545
}
4646

47+
data "aws_iam_policy_document" "wordpress_ecs_exec" {
48+
statement {
49+
actions = [
50+
"ssmmessages:CreateControlChannel",
51+
"ssmmessages:CreateDataChannel",
52+
"ssmmessages:OpenControlChannel",
53+
"ssmmessages:OpenDataChannel"
54+
]
55+
effect = "Allow"
56+
resources = ["*"]
57+
}
58+
}
59+
4760
resource "aws_iam_policy" "wordpress_bucket_access" {
4861
name = "${var.site_name}_WordpressBucketAccess"
4962
description = "The role that allows Wordpress task to do necessary operations"
@@ -55,6 +68,17 @@ resource "aws_iam_role_policy_attachment" "wordpress_bucket_access" {
5568
policy_arn = aws_iam_policy.wordpress_bucket_access.arn
5669
}
5770

71+
resource "aws_iam_policy" "wordpress_ecs_exec" {
72+
name = "${var.site_name}_WordpressECSExec"
73+
description = "Allows ECS Exec to the Wordpress container"
74+
policy = data.aws_iam_policy_document.wordpress_ecs_exec.json
75+
}
76+
77+
resource "aws_iam_role_policy_attachment" "wordpress_ecs_exec" {
78+
role = aws_iam_role.wordpress_task.name
79+
policy_arn = aws_iam_policy.wordpress_ecs_exec.arn
80+
}
81+
5882
resource "aws_iam_role" "wordpress_task" {
5983
name = "${var.site_name}_WordpressTaskRole"
6084
assume_role_policy = data.aws_iam_policy_document.ecs_assume_role_policy.json
@@ -221,10 +245,12 @@ resource "aws_security_group_rule" "wordpress_sg_egress_3306" {
221245

222246

223247
resource "aws_ecs_service" "wordpress_service" {
224-
name = "${var.site_name}_wordpress"
225-
task_definition = "${aws_ecs_task_definition.wordpress_container.family}:${aws_ecs_task_definition.wordpress_container.revision}"
226-
cluster = aws_ecs_cluster.wordpress_cluster.arn
227-
desired_count = var.launch
248+
name = "${var.site_name}_wordpress"
249+
task_definition = "${aws_ecs_task_definition.wordpress_container.family}:${aws_ecs_task_definition.wordpress_container.revision}"
250+
cluster = aws_ecs_cluster.wordpress_cluster.arn
251+
desired_count = var.launch
252+
enable_execute_command = true
253+
228254
# iam_role =
229255
capacity_provider_strategy {
230256
capacity_provider = var.graviton_fargate_enabled ? (contains(local.graviton_fargate_regions_unsupported, data.aws_region.current) ? "FARGATE_SPOT" : "FARGATE") : "FARGATE_SPOT"
@@ -234,7 +260,7 @@ resource "aws_ecs_service" "wordpress_service" {
234260
propagate_tags = "SERVICE"
235261
# Explicitly setting version here: https://stackoverflow.com/questions/62552562/one-or-more-of-the-requested-capabilities-are-not-supported-aws-fargate
236262
platform_version = "1.4.0"
237-
263+
238264
network_configuration {
239265
subnets = var.subnet_ids
240266
security_groups = [aws_security_group.wordpress_security_group.id]

task-definitions/wordpress.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
"awslogs-region": "${wp_region}",
5353
"awslogs-stream-prefix": "ecs"
5454
}
55+
},
56+
"linuxParameters": {
57+
"initProcessEnabled": true
5558
}
5659
}
5760
]

0 commit comments

Comments
 (0)