data "aws_iam_policy_document" "swf_execution_policy" {
  statement {
    actions = [
      "swf:StartWorkflowExecution",
    ]

    resources = [
      "arn:aws:swf:*:437795906767:/domain/${var.environment}-swf_collaborator_report",
    ]
  }
}

resource "aws_iam_policy" "swf_execution_policy" {
  name   = "${var.environment}-${var.service_name}-swf-execution-policy"
  policy = data.aws_iam_policy_document.swf_execution_policy.json
}

data "aws_iam_policy_document" "elasticsearch_read_write_access_policy" {
  statement {
    actions = [
      "es:ESHttpDelete",
      "es:ESHttpGet",
      "es:ESHttpHead",
      "es:ESHttpPost",
      "es:ESHttpPut",
    ]

    resources = [
      module.elasticsearch_collaborator_audit_log.aws_elasticsearch_domain_arn,
      "${module.elasticsearch_collaborator_audit_log.aws_elasticsearch_domain_arn}/*",
    ]
  }
}

resource "aws_iam_policy" "elasticsearch_read_write_access_policy" {
  name   = "Elasticsearch-${var.environment}-${var.service_name}-RW"
  policy = data.aws_iam_policy_document.elasticsearch_read_write_access_policy.json
}

