Skip to content

Commit d70029c

Browse files
authored
Add support for enable_execute_command (#33)
* Add support for enable_execute_command * Add required SSM permissions to task role
1 parent 0f07028 commit d70029c

File tree

7 files changed

+147
-74
lines changed

7 files changed

+147
-74
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v3.3.0
3+
rev: v3.4.0
44
hooks:
55
- id: check-added-large-files
66
args: ['--maxkb=500']
@@ -18,7 +18,7 @@ repos:
1818
args: ['--allow-missing-credentials']
1919
- id: trailing-whitespace
2020
- repo: git://github.com/antonbabenko/pre-commit-terraform
21-
rev: v1.45.0
21+
rev: v1.50.0
2222
hooks:
2323
- id: terraform_fmt
2424
- id: terraform_docs

CHANGELOG.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
55
<a name="unreleased"></a>
66
## [Unreleased]
77

8+
9+
10+
<a name="6.0.0"></a>
11+
## [6.0.0] - 2021-02-09
12+
13+
- Add missing 'target_group_name' parameter in examples ([#31](https://github.com/umotif-public/terraform-aws-ecs-fargate/issues/31))
14+
- Add support for registering multiple target groups with a service ([#29](https://github.com/umotif-public/terraform-aws-ecs-fargate/issues/29))
15+
- Update README.md
16+
17+
18+
<a name="5.1.0"></a>
19+
## [5.1.0] - 2020-12-09
20+
21+
- update docs
822
- Add secrets to task defintion ([#28](https://github.com/umotif-public/terraform-aws-ecs-fargate/issues/28))
923

1024

@@ -167,7 +181,9 @@ All notable changes to this project will be documented in this file.
167181
- Initial commit
168182

169183

170-
[Unreleased]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/5.0.1...HEAD
184+
[Unreleased]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/6.0.0...HEAD
185+
[6.0.0]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/5.1.0...6.0.0
186+
[5.1.0]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/5.0.1...5.1.0
171187
[5.0.1]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/5.0.0...5.0.1
172188
[5.0.0]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/4.0.3...5.0.0
173189
[4.0.3]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/4.0.2...4.0.3

README.md

Lines changed: 92 additions & 68 deletions
Large diffs are not rendered by default.

data.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@ data "aws_iam_policy_document" "task_permissions" {
3030
}
3131
}
3232

33+
# Task permissions to allow ECS Exec command
34+
data "aws_iam_policy_document" "task_ecs_exec_policy" {
35+
count = var.enable_execute_command ? 1 : 0
36+
37+
statement {
38+
effect = "Allow"
39+
40+
resources = ["*"]
41+
42+
actions = [
43+
"ssmmessages:CreateControlChannel",
44+
"ssmmessages:CreateDataChannel",
45+
"ssmmessages:OpenControlChannel",
46+
"ssmmessages:OpenDataChannel"
47+
]
48+
}
49+
}
50+
3351
# Task ecr privileges
3452
data "aws_iam_policy_document" "task_execution_permissions" {
3553
statement {

main.tf

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ resource "aws_iam_role_policy" "log_agent" {
4545
policy = data.aws_iam_policy_document.task_permissions.json
4646
}
4747

48+
resource "aws_iam_role_policy" "ecs_exec_inline_policy" {
49+
count = var.enable_execute_command ? 1 : 0
50+
51+
name = "${var.name_prefix}-ecs-exec-permissions"
52+
role = aws_iam_role.task.id
53+
policy = data.aws_iam_policy_document.task_ecs_exec_policy[0].json
54+
}
55+
4856
#####
4957
# Security groups
5058
#####
@@ -280,8 +288,9 @@ resource "aws_ecs_service" "service" {
280288
platform_version = var.platform_version
281289
launch_type = length(var.capacity_provider_strategy) == 0 ? "FARGATE" : null
282290

283-
force_new_deployment = var.force_new_deployment
284-
wait_for_steady_state = var.wait_for_steady_state
291+
force_new_deployment = var.force_new_deployment
292+
wait_for_steady_state = var.wait_for_steady_state
293+
enable_execute_command = var.enable_execute_command
285294

286295
deployment_minimum_healthy_percent = var.deployment_minimum_healthy_percent
287296
deployment_maximum_percent = var.deployment_maximum_percent

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,9 @@ variable "wait_for_steady_state" {
270270
description = "If true, Terraform will wait for the service to reach a steady state (like aws ecs wait services-stable) before continuing."
271271
default = false
272272
}
273+
274+
variable "enable_execute_command" {
275+
type = bool
276+
description = "Specifies whether to enable Amazon ECS Exec for the tasks within the service."
277+
default = true
278+
}

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ terraform {
22
required_version = ">= 0.13.0"
33

44
required_providers {
5-
aws = ">= 3.13"
5+
aws = ">= 3.34"
66
}
77
}

0 commit comments

Comments
 (0)