<commit_before>data "aws_iam_policy_document" "snapshot_jenkins_data_role" {
  statement {
    actions = ["sts:AssumeRole"]

    principals {
      type        = "Service"
      identifiers = ["dlm.amazonaws.com"]
    }
  }
}

data "aws_iam_policy_document" "snapshot_jenkins_data_policy" {
  statement {
    actions = [
      "ec2:CreateSnapshot",
      "ec2:DeleteSnapshot",
      "ec2:DescribeVolumes",
      "ec2:DescribeSnapshots",
    ]

    resources = ["*"]

    condition {
      test     = "StringEquals"
      variable = "ec2:ResourceTag/Name"
      values   = ["jenkins data"]
    }
  }

  statement {
    actions   = ["ec2:CreateTags"]
    resources = ["arn:aws:ec2:*::snapshot/*"]
  }
}

resource "aws_iam_role" "snapshot_jenkins_data_role" {
  name               = "snapshot-jenkins-data-role"
  assume_role_policy = "${data.aws_iam_policy_document.snapshot_jenkins_data_role.json}"
}

resource "aws_iam_role_policy" "snapshot_jenkins_data_policy" {
  name   = "snapshot-jenkins-data-policy"
  role   = "${aws_iam_role.snapshot_jenkins_data_role.id}"
  policy = "${data.aws_iam_policy_document.snapshot_jenkins_data_policy.json}"
}

resource "aws_dlm_lifecycle_policy" "snapshot_jenkins_data" {
  description        = "Snapshot the Jenkins data volume daily around midnight and retain snapshots for a week"
  execution_role_arn = "${aws_iam_role.snapshot_jenkins_data_role.arn}"

  policy_details {
    resource_types = ["VOLUME"]

    schedule {
      name = "One week of daily snapshots"

      create_rule {
        interval      = 24
        interval_unit = "HOURS"
        times         = ["11:30"]
      }

      retain_rule {
        count = 7
      }

      copy_tags = true
    }

    target_tags = {
      Name = "jenkins data"
    }
  }
}<commit_msg>Fix issues with jenkins snapshot policy<commit_after>data "aws_iam_policy_document" "snapshot_jenkins_data_role" {
  statement {
    actions = ["sts:AssumeRole"]

    principals {
      type        = "Service"
      identifiers = ["dlm.amazonaws.com"]
    }
  }
}

data "aws_iam_policy_document" "snapshot_jenkins_data_policy" {
  statement {
    actions = [
      "ec2:CreateSnapshot",
      "ec2:DeleteSnapshot",
      "ec2:DescribeVolumes",
      "ec2:DescribeSnapshots",
    ]

    resources = ["*"]
  }

  statement {
    actions   = ["ec2:CreateTags"]
    resources = ["arn:aws:ec2:*::snapshot/*"]
  }
}

resource "aws_iam_role" "snapshot_jenkins_data_role" {
  name               = "snapshot-jenkins-data-role"
  assume_role_policy = "${data.aws_iam_policy_document.snapshot_jenkins_data_role.json}"
}

resource "aws_iam_role_policy" "snapshot_jenkins_data_policy" {
  name   = "snapshot-jenkins-data-policy"
  role   = "${aws_iam_role.snapshot_jenkins_data_role.id}"
  policy = "${data.aws_iam_policy_document.snapshot_jenkins_data_policy.json}"
}

resource "aws_dlm_lifecycle_policy" "snapshot_jenkins_data" {
  description        = "Snapshot the Jenkins data volume daily around midnight and retain snapshots for a week"
  execution_role_arn = "${aws_iam_role.snapshot_jenkins_data_role.arn}"

  policy_details {
    resource_types = ["VOLUME"]

    schedule {
      name = "One week of daily snapshots"

      create_rule {
        interval      = 24
        interval_unit = "HOURS"
        times         = ["23:30"]
      }

      retain_rule {
        count = 7
      }

      copy_tags = true
    }

    target_tags = {
      Name = "jenkins data"
    }
  }
}
{'fraction_non_alphanumeric': 0.11104668019715859, 'fraction_numerical': 0.007828356045230501, 'mean_word_length': 2.9338654503990877, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2265851', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1165, 'n_words': 189}