data "aws_iam_policy_document" "assume_role_policy" {
  statement {
    sid = "AllowAccessToECSForInfrastructureManagement"
    actions = ["sts:AssumeRole"]
    principals {
      type        = "Service"
      identifiers = ["ecs.amazonaws.com"]
    }
  }
}

resource "aws_iam_role" "role" {
  name                 = "ecsInfrastructureRole"
  assume_role_policy   = data.aws_iam_policy_document.assume_role_policy.json

  tags = {
    terraformed = true
  }
}

resource "aws_iam_role_policy_attachment" "abac_policy_attachments" {
  role       = aws_iam_role.role.name
  policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSInfrastructureRolePolicyForVolumes"
}
