|
|
|
resource "aws_iam_role" "api_exec_role" {
|
|
|
|
name = "${var.project}-exec-role"
|
|
|
|
assume_role_policy = data.aws_iam_policy_document.api_exec_assume_role_policy_statement.json
|
|
|
|
}
|
|
|
|
|
|
|
|
data "aws_iam_policy_document" "api_exec_assume_role_policy_statement" {
|
|
|
|
statement {
|
|
|
|
actions = ["sts:AssumeRole"]
|
|
|
|
principals {
|
|
|
|
type = "Service"
|
|
|
|
identifiers = ["ecs-tasks.amazonaws.com"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
data "aws_iam_policy_document" "ecs_exec_policy_statement" {
|
|
|
|
statement {
|
|
|
|
effect = "Allow"
|
|
|
|
actions = [
|
|
|
|
"ecr:GetAuthorizationToken",
|
|
|
|
"ecr:BatchCheckLayerAvailability",
|
|
|
|
"ecr:GetDownloadUrlForLayer",
|
|
|
|
"ecr:BatchGetImage",
|
|
|
|
"logs:CreateLogStream",
|
|
|
|
"logs:PutLogEvents"
|
|
|
|
]
|
|
|
|
resources = ["*"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data "aws_iam_policy" "ecs_exec_policy" {
|
|
|
|
# name = "${var.project}-ecs_exec_policy"
|
|
|
|
# policy = data.aws_iam_policy_document.ecs_exec_policy_statement.json
|
|
|
|
# }
|
|
|
|
arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
|
|
|
|
}
|
|
|
|
resource "aws_iam_role_policy_attachment" "ecs_exec_iam_attach_rules" {
|
|
|
|
role = aws_iam_role.api_exec_role.name
|
|
|
|
policy_arn = data.aws_iam_policy.ecs_exec_policy.arn
|
|
|
|
}
|