<commit_before># Backups role, policy and role-policy attachment
resource "aws_iam_role" "backups_role" {
  name = "backups"

  assume_role_policy = <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::${var.aws_main_account_id}:root"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}
EOF
}

resource "aws_iam_policy" "backups_policy" {
  name = "backups-access-policy"

  policy = <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "s3:ListAllMyBuckets"
      ],
      "Resource": "arn:aws:s3:::*",
      "Condition": {
        "Bool": {
          "aws:MultiFactorAuthPresent": true
        }
      }
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:ListBucket",
        "s3:GetBucketLocation"
      ],
      "Resource": "arn:aws:s3:::digitalmarketplace-database-backups",
      "Condition": {
        "Bool": {
          "aws:MultiFactorAuthPresent": true
        }
      }
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:GetObject"
      ],
      "Resource": "arn:aws:s3:::digitalmarketplace-database-backups/*",
      "Condition": {
        "Bool": {
          "aws:MultiFactorAuthPresent": true
        }
      }
    }
  ]
}
EOF
}

resource "aws_iam_role_policy_attachment" "backups_role_policy_attachment" {
  role       = "${aws_iam_role.backups_role.id}"
  policy_arn = "${aws_iam_policy.backups_policy.arn}"
}

# Replication role, policy and role-policy attachment
# Only S3 service can assume this role and perform these actions.
# (See https://www.terraform.io/docs/providers/aws/r/s3_bucket.html#using-replication-configuration)
resource "aws_iam_role" "replication_role" {
  name = "replication"

  assume_role_policy = <<POLICY
{
  "Version": "2012-10-17",<commit_msg>Add new replications bucket to backups role list, getbucket and get actions<commit_after># Backups role, policy and role-policy attachment
resource "aws_iam_role" "backups_role" {
  name = "backups"

  assume_role_policy = <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::${var.aws_main_account_id}:root"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}
EOF
}

resource "aws_iam_policy" "backups_policy" {
  name = "backups-access-policy"

  policy = <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "s3:ListAllMyBuckets"
      ],
      "Resource": "arn:aws:s3:::*",
      "Condition": {
        "Bool": {
          "aws:MultiFactorAuthPresent": true
        }
      }
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:ListBucket",
        "s3:GetBucketLocation"
      ],
      "Resource": [
        "arn:aws:s3:::digitalmarketplace-database-backups",
        "arn:aws:s3:::digitalmarketplace-cross-region-database-backups"
      ],
      "Condition": {
        "Bool": {
          "aws:MultiFactorAuthPresent": true
        }
      }
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:GetObject"
      ],
      "Resource": [
        "arn:aws:s3:::digitalmarketplace-database-backups/*",
        "arn:aws:s3:::digitalmarketplace-cross-region-database-backups/*"
      ],
      "Condition": {
        "Bool": {
          "aws:MultiFactorAuthPresent": true
        }
      }
    }
  ]
}
EOF
}

resource "aws_iam_role_policy_attachment" "backups_role_policy_attachment" {
  role       = "${aws_iam_role.backups_role.id}"
  policy_arn = "${aws_iam_policy.backups_policy.arn}"
}

# Replication role, policy and role-policy attachment
# Only S3 service can assume this role and perform these actions.
# (See https://www.terraform.io/docs/providers/aws/r/s3_bucket.html#using-replication-configuration)
resource "aws_iam_role" "replication_role" {
  name = "replication"

  assume_role_policy = <<POLICY
{
  "Version": "2012-10-17",
{'fraction_non_alphanumeric': 0.15835850956696879, 'fraction_numerical': 0.017119838872104734, 'mean_word_length': 2.6216955332725616, 'pattern_counts': {'":': 54, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7133437', 'n_tokens_mistral': 1413, 'n_tokens_neox': 1370, 'n_words': 216}