# Assume role policy used by Jenkins scheduler agent role
data "aws_iam_policy_document" "assume_role_policy" {
  statement {
    actions = ["sts:AssumeRole"]

    principals {
      type = "AWS"

      identifiers = [
        "arn:aws:iam::437795906767:role/prod-jenkins-aws-pipeline-agent",
        "arn:aws:iam::437795906767:role/prod-jenkins-aws-task-agent",
      ]
    }
  }
}

# Jenkins agent will assume this role in order to access SecretsManager
resource "aws_iam_role" "neo4j_cypher_scheduler_deploy_role" {
  name               = "${var.environment}-${var.service_name}-deploy-role"
  assume_role_policy = data.aws_iam_policy_document.assume_role_policy.json
}

resource "aws_iam_role_policy_attachment" "neo4j_cypher_scheduler_secret_manager_policy_attachment" {
  role       = aws_iam_role.neo4j_cypher_scheduler_deploy_role.id
  policy_arn = aws_iam_policy.neo4j_cypher_scheduler_manager_policy.arn
}
