{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AllowSSMSendCommandToTaggedInstances",
      "Effect": "Allow",
      "Action": "ssm:SendCommand",
      "Resource": [
        "arn:aws:ec2:*:*:instance/*"
      ],
      "Condition": {
        "StringLike": {
          "aws:ResourceTag/SqlHaMonitored": "true"
        }
      }
    },
    {
      "Sid": "AllowSSMSendCommandOfOwnedDoc",
      "Effect": "Allow",
      "Action": "ssm:SendCommand",
      "Resource": [
        "arn:aws:ssm:*:*:document/AWSEC2-DetectSqlHa*"
      ]
    },
    {
      "Sid": "AllowSSMNonMutating",
      "Effect": "Allow",
      "Action": [
        "ssm:DescribeInstanceInformation",
        "ssm:GetCommandInvocation",
        "ssm:ListCommands",
        "ssm:ListCommandInvocations"
      ],
      "Resource": "*"
    },
    {
      "Sid": "AllowEC2NonMutating",
      "Effect": "Allow",
      "Action": [
        "ec2:DescribeInstances",
        "ec2:DescribeInstanceAttribute",
        "ec2:DescribeInstanceStatus",
        "ec2:DescribeTags"
      ],
      "Resource": "*"
    },
    {
      "Sid": "AllowEventsMutateManagedRule",
      "Effect": "Allow",
      "Action": [
        "events:PutTargets",
        "events:PutRule",
        "events:DeleteRule",
        "events:RemoveTargets"
      ],
      "Condition": {
        "StringEquals": {
          "events:ManagedBy": "ec2sqlha.amazonaws.com",
          "aws:PrincipalAccount": "${aws:ResourceAccount}"
        }
      },
      "Resource": "arn:aws:events:*:*:rule/AWSEC2SqlHa*"
    },
    {
      "Sid": "AllowEventsNonMutatingManagedRule",
      "Effect": "Allow",
      "Action": [
        "events:ListTargetsByRule",
        "events:DescribeRule"
      ],
      "Resource": "arn:aws:events:*:*:rule/AWSEC2SqlHa*"
    }
  ]
}
