resource "aws_iam_role" "api_exec_role" { name = "${var.project}-exec-role" assume_role_policy = data.aws_iam_policy_document.api_exec_assume_role.json } data "aws_iam_policy_document" "api_exec_assume_role" { statement { actions = ["sts:AssumeRole"] principals { type = "Service" identifiers = ["ecs-task.amazonaws.com"] } } } resource "aws_iam_role_policy_attachment" "ecs_exec_iam_attach_assume_role" { role = aws_iam_role.api_exec_role.name policy_arn = data.aws_iam_policy_document.api_exec_assume_role } data "aws_iam_policy_document" "ecs_exec_role" { statement { effect = "Allow" actions = [ "ecr:GetAuthorizationToken", "ecr:BatchCheckLayerAvailability", "ecr:GetDownloadUrlForLayer", "ecr:BatchGetImage", "logs:CreateLogStream", "logs:PutLogEvents" ] resources = ["*${var.project}*"] } } 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_document.ecs_exec_role.json }