Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update example for ECS exec #18

Merged
merged 5 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions examples/fargate/data.tf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the following policies as well for exec?

ssmmessages:CreateControlChannel
ssmmessages:CreateDataChannel
ssmmessages:OpenControlChannel
ssmmessages:OpenDataChannel

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, but they are part of the arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore policy

Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,32 @@ data "aws_iam_policy_document" "execution_custom_policy" {
}
}

data "aws_iam_policy_document" "task_custom_policy" {
data "aws_iam_policy_document" "task_ecs_exec_policy" {
statement {
sid = "CustomTaskPolicy"

actions = [
"s3:Get*",
"s3:List*",
"kms:Decrypt",
]

resources = [
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/*",
module.fargate_cluster.ecs_cluster_kms_arn
]
}
statement {
actions = [
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:DescribeLogGroups",
"logs:DescribeLogStreams",
]
resources = ["arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:log-group:*"]
}
statement {
actions = [
"ssmmessages:CreateControlChannel",
"ssmmessages:CreateDataChannel",
"ssmmessages:OpenControlChannel",
"ssmmessages:OpenDataChannel",
]
resources = "*"
}
}
7 changes: 5 additions & 2 deletions examples/fargate/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ module "ecs_task_role" {

role_name = "ecs-task-role-${var.name}"
trusted_role_services = ["ecs-tasks.amazonaws.com"]
policy = data.aws_iam_policy_document.task_custom_policy.json
policy_name = "ecs-task-policy-${var.name}"
custom_role_policy_arns = [
"arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess",
]
policy = data.aws_iam_policy_document.task_ecs_exec_policy.json
policy_name = "ecs-task-policy-${var.name}"
}
4 changes: 4 additions & 0 deletions examples/fargate/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "ecs_cluster_kms_arn" {
value = module.fargate_cluster.ecs_cluster_kms_arn
description = "The AWS Key Management Service key ID to encrypt the data between the local client and the container"
}
Loading