data "aws_iam_policy_document" "ecr_full_access" {
  # checkov:skip=CKV_AWS_109: Ensure IAM policies does not allow permissions management / resource exposure without constraints
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]
    actions   = ["ecr:*"]
  }
}

data "aws_iam_policy_document" "ccshr-aoma-sts-assume-policy" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:iam::476717493283:role/ccshr-aoma-role",

    ]

    actions = [
      "sts:AssumeRole",
    ]
  }
}


data "aws_iam_policy_document" "ameba-prod-ns-aoma3-sa-aoma-envelope-service-policy" {
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid    = "AllowSQSAndSecretsManagerAccess"
    effect = "Allow"

    resources = [
      "arn:aws:sqs:*:${var.account_id}:*",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/aoma3/abs-OHQUTP",
      "arn:aws:rds:eu-central-1:${var.account_id}:db:ameba-rds-prod",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/aoma3/sae-gQmrF0",
    ]

    actions = [
      "secretsmanager:GetResourcePolicy",
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecretVersionIds",
      "sqs:*",
      "rds:*",
    ]
  }

  statement {
    sid    = "AllowListingQueuesAndSecrets"
    effect = "Allow"

    resources = ["*"]

    actions = [
      "sqs:ListQueues",
      "secretsmanager:ListSecrets",
      "kms:GenerateDataKey",
    ]
  }

  statement {
    sid    = "AllowSpecificSecretListing"
    effect = "Allow"

    resources = ["arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/aoma3/abs-OHQUTP"]

    actions = ["secretsmanager:ListSecrets"]
  }
}

data "aws_iam_policy_document" "aomap-ms-eks-worker-node-policy" {
  # checkov:skip=CKV_AWS_108: Ensure IAM policies does not allow data exfiltration
  # checkov:skip=CKV_AWS_109: Ensure IAM policies does not allow permissions management / resource exposure without constraints
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAQcNotesNotificationQueue",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAApprovalNotificationQueue",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AomaUserSecretKeyNotification",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAApprovalNotificationDLQ",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAQcNotesNotificationDLQ",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AomaUserSecretKeyNotification-DLQ",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/aoma3/aomams-De7PIe",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/aoma3/aps-NDDuRc",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/aoma3/gras-ws-proxy-iZSyiJ",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/aoma3/gps-lHL8qV",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/aoma3/aum-DHYc5P",
    ]

    actions = [
      "sqs:DeleteMessage",
      "sqs:GetQueueUrl",
      "sqs:ChangeMessageVisibility",
      "secretsmanager:DescribeSecret",
      "sqs:SendMessageBatch",
      "sqs:ReceiveMessage",
      "sqs:SendMessage",
      "sqs:GetQueueAttributes",
      "sqs:ListQueueTags",
      "secretsmanager:ListSecretVersionIds",
      "secretsmanager:GetResourcePolicy",
      "sqs:ListDeadLetterSourceQueues",
      "secretsmanager:GetSecretValue",
      "sqs:DeleteMessageBatch",
      "sqs:PurgeQueue",
      "sqs:DeleteQueue",
      "sqs:CreateQueue",
      "sqs:ChangeMessageVisibilityBatch",
      "sqs:SetQueueAttributes",
    ]
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "secretsmanager:GetRandomPassword",
      "sqs:ListQueues",
      "ses:*",
      "secretsmanager:*",
      "kms:*",
    ]
  }
  statement {
    sid       = "VisualEditor2"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "ecr:GetRegistryPolicy",
      "ecr:CreateRepository",
      "ecr:DescribeRegistry",
      "ecr:DescribePullThroughCacheRules",
      "ecr:GetAuthorizationToken",
      "ecr:PutRegistryScanningConfiguration",
      "ecr:CreatePullThroughCacheRule",
      "ecr:DeletePullThroughCacheRule",
      "ecr:PutRegistryPolicy",
      "ecr:GetRegistryScanningConfiguration",
      "ecr:BatchImportUpstreamImage",
      "ecr:DeleteRegistryPolicy",
      "ecr:PutReplicationConfiguration",
    ]
  }

  statement {
    sid    = "VisualEditor3"
    effect = "Allow"

    resources = [
      "arn:aws:ecr:eu-central-1:613871678587:repository/ameba-link-service",
      "arn:aws:ecr:eu-central-1:613871678587:repository/ameba-event-history-processor",
    ]

    actions = ["ecr:*"]
  }
}

data "aws_iam_policy_document" "aomap-acm-access" {
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "acm:DescribeCertificate",
      "acm:ListCertificates",
      "acm:GetCertificate",
      "acm:ListTagsForCertificate",
      "acm:RequestCertificate",
      "acm:ExportCertificate",
    ]
  }
}

data "aws_iam_policy_document" "Billing-RO" {
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "account:GetAccountInformation",
      "account:GetAlternateContact",
      "account:GetChallengeQuestions",
      "account:GetContactInformation",
      "account:GetAccountInformation",
      "billing:GetContractInformation",
      "billing:GetIAMAccessPreference",
      "billing:GetSellerOfRecord",
      "billing:GetBillingData",
      "billing:GetBillingDetails",
      "billing:GetBillingNotifications",
      "billing:GetBillingPreferences",
      "billing:GetContractInformation",
      "billing:GetCredits",
      "billing:GetIAMAccessPreference",
      "billing:GetSellerOfRecord",
      "billing:ListBillingViews",
      "payments:ListPaymentPreferences",
      "ce:DescribeNotificationSubscription",
      "ce:DescribeReport",
      "ce:GetAnomalies",
      "ce:GetAnomalyMonitors",
      "ce:GetAnomalySubscriptions",
      "ce:GetCostAndUsage",
      "ce:GetCostAndUsageWithResources",
      "ce:GetCostCategories",
      "ce:GetCostForecast",
      "ce:GetDimensionValues",
      "ce:GetPreferences",
      "ce:GetReservationCoverage",
      "ce:GetReservationPurchaseRecommendation",
      "ce:GetReservationUtilization",
      "ce:GetRightsizingRecommendation",
      "ce:GetSavingsPlansCoverage",
      "ce:GetSavingsPlansPurchaseRecommendation",
      "ce:GetSavingsPlansUtilization",
      "ce:GetSavingsPlansUtilizationDetails",
      "ce:GetTags",
      "ce:GetUsageForecast",
      "ce:ListCostAllocationTags",
      "ce:ListSavingsPlansPurchaseRecommendationGeneration",
      "consolidatedbilling:GetAccountBillingRole",
      "consolidatedbilling:ListLinkedAccounts",
      "cur:GetClassicReport",
      "cur:GetClassicReportPreferences",
      "cur:ValidateReportDestination",
      "cur:GetUsageReport",
      "freetier:GetFreeTierAlertPreference",
      "freetier:GetFreeTierUsage",
      "invoicing:GetInvoiceEmailDeliveryPreferences",
      "invoicing:GetInvoicePDF",
      "invoicing:ListInvoiceSummaries",
      "payments:GetPaymentInstrument",
      "payments:GetPaymentStatus",
      "payments:ListPaymentPreferences",
      "tax:GetTaxInheritance",
      "tax:GetTaxRegistrationDocument",
      "tax:ListTaxRegistrations"
    ]
  }
}

data "aws_iam_policy_document" "aomap-eks-ameba-prod-ns-ameba-private-sa-ec-policy" {
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]
    actions   = ["acm:ExportCertificate"]
  }

  statement {
    sid    = "VisualEditor1"
    effect = "Allow"

    resources = [
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/mlib-previews",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/metadata-update-video-messages",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/metadata",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/preorder-events",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/master-messages",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/link-messages",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/master-messages-physical",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/link-messages-physical",
      "arn:aws:kafka:eu-central-1:${var.account_id}:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/bulk-registrations",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/jms-events",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/history-events",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/gras-messages",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/eom-messages",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ec-backfill",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/backfill-mb-internal",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/aoma-email-notifications",
      "arn:aws:kafka:eu-central-1:613871678587:group/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ameba.eventconsumer*",
      "arn:aws:kafka:eu-central-1:613871678587:cluster/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3",
    ]

    actions = [
      "kafka-cluster:WriteDataIdempotently",
      "kafka-cluster:WriteData",
      "kafka-cluster:ReadData",
      "kafka-cluster:DescribeTopicDynamicConfiguration",
      "kafka-cluster:DescribeTopic",
      "kafka-cluster:DescribeGroup",
      "kafka-cluster:DescribeClusterDynamicConfiguration",
      "kafka-cluster:DescribeCluster",
      "kafka-cluster:Connect",
      "kafka-cluster:AlterGroup",
    ]
  }

  statement {
    sid       = "VisualEditor3"
    effect    = "Allow"
    resources = ["arn:aws:sqs:eu-central-1:613871678587:AOMAEmailNotification"]
    actions   = ["sqs:*"]
  }

  statement {
    sid       = "VisualEditor4"
    effect    = "Allow"
    resources = ["arn:aws:kms:eu-central-1:613871678587:key/5d51d0ad-aa91-465c-8abb-86b5770bf97b"]
    actions   = ["kms:*"]
  }

  statement {
    sid       = "VisualEditor5"
    effect    = "Allow"
    resources = ["arn:aws:kms:eu-central-1:${var.account_id}:key/f3f00387-1ce2-4e0b-8528-dfcb0a8a56c0"]
    actions   = ["kms:Decrypt"]
  }

  statement {
    sid    = "VisualEditor6"
    effect = "Allow"
    resources = [
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/ec_previews_usr-xNTd8H",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aas/prod/ameba_ec-*",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/glob/prod/ameba_ec-*"
    ]
    actions = [
      "secretsmanager:ListSecretVersionIds",
      "secretsmanager:GetSecretValue",
      "secretsmanager:GetResourcePolicy",
      "secretsmanager:DescribeSecret"
    ]
  }
  statement {
    sid    = "VisualEditor7"
    effect = "Allow"
    resources = [
      "arn:aws:iam::635220336377:role/gdsp-ameba-msk-role"
    ]
    actions = [
      "sts:AssumeRole"
    ]
  }

}


data "aws_iam_policy_document" "aomap-eks-aomap-ms-ns-aoma3-sa-aoma-sas-policy" {
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]
    actions   = ["logs:*"]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/Aoma/SAS-oWP1Rz"]

    actions = [
      "secretsmanager:GetResourcePolicy",
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecretVersionIds",
    ]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]
    actions   = ["secretsmanager:ListSecrets"]
  }
}

data "aws_iam_policy_document" "aomap-sqs-euc1-policy" {
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "kms:DescribeCustomKeyStores",
      "kms:ListKeys",
      "kms:DeleteCustomKeyStore",
      "kms:GenerateRandom",
      "kms:UpdateCustomKeyStore",
      "kms:ListAliases",
      "kms:DisconnectCustomKeyStore",
      "kms:CreateKey",
      "kms:ConnectCustomKeyStore",
      "kms:CreateCustomKeyStore",
    ]
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["arn:aws:kms:eu-central-1:${var.account_id}:alias/aomap-sqs-euc1"]
    actions   = ["kms:*"]
  }
}

data "aws_iam_policy_document" "mediaconvert-amp-source-msrv-dest-prod" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:s3:::amp-audio-archives-prod",
      "arn:aws:s3:::amp-audio-archives-prod/*",
      "arn:aws:s3:::amp-photo-archives-prod",
      "arn:aws:s3:::amp-photo-archives-prod/*",
      "arn:aws:s3:::amp-video-archives-prod",
      "arn:aws:s3:::amp-video-archives-prod/*",
      "arn:aws:s3:::amp-archive-exports-prod",
      "arn:aws:s3:::amp-archive-exports-prod/*",
      "arn:aws:s3:::amp-mediaconvert-output-prod",
      "arn:aws:s3:::amp-mediaconvert-output-prod/*",
    ]

    actions = [
      "s3:ListBucket",
      "s3:GetObject",
    ]
  }

  statement {
    sid    = "VisualEditor1"
    effect = "Allow"

    resources = [
      "arn:aws:s3:::sme-origin-amp",
      "arn:aws:s3:::sme-origin-amp/*",
      "arn:aws:s3:::amp-archive-exports-prod",
      "arn:aws:s3:::amp-archive-exports-prod/*",
      "arn:aws:s3:::amp-mediaconvert-output-prod",
      "arn:aws:s3:::amp-mediaconvert-output-prod/*",
    ]

    actions = [
      "s3:ListBucket",
      "s3:PutObject",
      "s3:GetObjectAcl",
      "s3:PutObjectAcl",
    ]
  }
}

data "aws_iam_policy_document" "aomap-eks-aomap-ms-ns-aoma3-sa-ust-be-service-policy" {
  # checkov:skip=CKV_AWS_109: Ensure IAM policies does not allow permissions management / resource exposure without constraints
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:sqs:eu-central-1:613871678587:ust-assetupload-sqs",
      "arn:aws:sqs:eu-central-1:613871678587:ust-prod-assetupload-sqs",
      "arn:aws:sqs:eu-central-1:613871678587:ust-eom-sender-sqs.fifo",
      "arn:aws:sqs:eu-central-1:613871678587:AOMAEmailNotification",
      "arn:aws:sqs:eu-central-1:613871678587:AOMAEmailNotificationDLQ",
      "arn:aws:secretsmanager:eu-central-1:613871678587:secret:prod/AOMA/Acars-1zrbtO",
    ]

    actions = [
      "secretsmanager:GetResourcePolicy",
      "secretsmanager:GetSecretValue",
      "sqs:Send*",
      "secretsmanager:DescribeSecret",
      "sqs:Delete*",
      "sqs:Receive*",
      "sqs:*",
      "sqs:Get*",
      "secretsmanager:ListSecretVersionIds",
    ]
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "secretsmanager:GetRandomPassword",
      "sqs:ListQueues",
      "kms:*",
      "secretsmanager:ListSecrets",
    ]
  }

  statement {
    sid    = "VisualEditor2"
    effect = "Allow"

    resources = [
      "arn:aws:sqs:eu-central-1:613871678587:ust-assetupload-sqs",
      "arn:aws:sqs:eu-central-1:613871678587:ust-prod-assetupload-sqs",
      "arn:aws:sqs:eu-central-1:613871678587:ust-eom-sender-sqs.fifo",
      "arn:aws:sqs:eu-central-1:613871678587:AOMAEmailNotification",
      "arn:aws:sqs:eu-central-1:613871678587:AOMAEmailNotificationDLQ",
    ]

    actions = ["sqs:List*"]
  }

  statement {
    sid    = "VisualEditor8"
    effect = "Allow"

    resources = [
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/update-legacy-search",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ameba-events",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/aoma-email-notifications",
      "arn:aws:kafka:eu-central-1:613871678587:group/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ust.be.*",
      "arn:aws:kafka:eu-central-1:613871678587:cluster/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3",
    ]

    actions = [
      "kafka:List*",
      "kafka:Get*",
      "kafka:Describe*",
      "kafka-cluster:WriteDataIdempotently",
      "kafka-cluster:WriteData",
      "kafka-cluster:ReadData",
      "kafka-cluster:DescribeTopicDynamicConfiguration",
      "kafka-cluster:DescribeTopic",
      "kafka-cluster:DescribeGroup",
      "kafka-cluster:DescribeClusterDynamicConfiguration",
      "kafka-cluster:DescribeCluster",
      "kafka-cluster:Connect",
      "kafka-cluster:AlterGroup",
    ]
  }

  statement {
    sid    = "VisualEditor9"
    effect = "Allow"

    resources = [
      "arn:aws:s3:::sme-aoma-core-prod-email-notification-attachment",
      "arn:aws:s3:::sme-aoma-core-prod-email-notification-attachment/*",
    ]

    actions = ["s3:*"]
  }
}

data "aws_iam_policy_document" "oneClick_Cognito_aomap_kibana_usersUnauth_Role_1583510894429" {
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "mobileanalytics:PutEvents",
      "cognito-sync:*",
    ]
  }
}

data "aws_iam_policy_document" "promop-EC2create" {
  # checkov:skip=CKV_AWS_107: Ensure IAM policies does not allow credentials exposure
  # checkov:skip=CKV_AWS_109: Ensure IAM policies does not allow permissions management / resource exposure without constraints
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "ec2:CreateDhcpOptions",
      "ec2:AuthorizeSecurityGroupIngress",
      "ec2:DescribeInstances",
      "ec2:GetEbsEncryptionByDefault",
      "ec2:CreateKeyPair",
      "ec2:DescribeSnapshots",
      "ec2:DescribeLocalGatewayVirtualInterfaces",
      "ec2:DescribeHostReservationOfferings",
      "ec2:DescribeTrafficMirrorSessions",
      "ec2:UpdateSecurityGroupRuleDescriptionsIngress",
      "ec2:DescribeExportImageTasks",
      "ec2:DescribeTrafficMirrorFilters",
      "ec2:DescribeVolumeStatus",
      "ec2:StartInstances",
      "ec2:CreateNetworkInterfacePermission",
      "ec2:DescribeLocalGatewayRouteTableVpcAssociations",
      "ec2:CreateRoute",
      "ec2:DescribeScheduledInstanceAvailability",
      "ec2:DescribeVolumes",
      "ec2:GetEbsDefaultKmsKeyId",
      "ec2:DescribeFpgaImageAttribute",
      "ec2:DescribeExportTasks",
      "ec2:DescribeTransitGatewayMulticastDomains",
      "ec2:DescribeKeyPairs",
      "ec2:DescribeReservedInstancesListings",
      "ec2:DescribeCapacityReservations",
      "ec2:DescribeClientVpnRoutes",
      "ec2:DescribeSpotFleetRequestHistory",
      "ec2:BundleInstance",
      "ec2:CreateTags",
      "ec2:DescribeVpcClassicLinkDnsSupport",
      "ec2:DescribeSnapshotAttribute",
      "ec2:DescribeIdFormat",
      "ec2:DescribeFastSnapshotRestores",
      "ec2:RunInstances",
      "ec2:StopInstances",
      "ec2:DescribeVolumeAttribute",
      "ec2:CreateVolume",
      "ec2:DescribeImportSnapshotTasks",
      "ec2:DescribeLocalGatewayVirtualInterfaceGroups",
      "ec2:GetPasswordData",
      "ec2:DescribeVpcEndpointServicePermissions",
      "ec2:DescribeTransitGatewayAttachments",
      "ec2:CreateDefaultVpc",
      "ec2:DescribeScheduledInstances",
      "ec2:SearchLocalGatewayRoutes",
      "ec2:CreateSnapshots",
      "ec2:DescribeImageAttribute",
      "ec2:DescribeFleets",
      "ec2:DescribeReservedInstancesModifications",
      "ec2:DescribeSubnets",
      "ec2:CreateSubnet",
      "ec2:AttachVolume",
      "ec2:DisassociateAddress",
      "ec2:DescribeMovingAddresses",
      "ec2:DescribeFleetHistory",
      "ec2:DescribePrincipalIdFormat",
      "ec2:DescribeFlowLogs",
      "ec2:DescribeRegions",
      "ec2:DescribeTransitGateways",
      "ec2:DescribeVpcEndpointServices",
      "ec2:DescribeSpotInstanceRequests",
      "ec2:DescribeVpcAttribute",
      "ec2:ExportClientVpnClientCertificateRevocationList",
      "ec2:CreateDefaultSubnet",
      "ec2:CreateCapacityReservation",
      "ec2:DescribeTrafficMirrorTargets",
      "ec2:DescribeTransitGatewayRouteTables",
      "ec2:DescribeAvailabilityZones",
      "ec2:DescribeNetworkInterfaceAttribute",
      "ec2:CreateSnapshot",
      "ec2:DescribeLocalGatewayRouteTables",
      "ec2:DescribeVpcEndpointConnections",
      "ec2:SearchTransitGatewayMulticastGroups",
      "ec2:DescribeInstanceStatus",
      "ec2:CreateInstanceExportTask",
      "ec2:DescribeHostReservations",
      "ec2:CreateClientVpnRoute",
      "ec2:DescribeBundleTasks",
      "ec2:DescribeIdentityIdFormat",
      "ec2:DescribeClassicLinkInstances",
      "ec2:DescribeVpcEndpointConnectionNotifications",
      "ec2:DescribeSecurityGroups",
      "ec2:DescribeFpgaImages",
      "ec2:CreateLaunchTemplate",
      "ec2:DescribeVpcs",
      "ec2:DescribeStaleSecurityGroups",
      "ec2:DescribeAggregateIdFormat",
      "ec2:ExportClientVpnClientConfiguration",
      "ec2:DescribeVolumesModifications",
      "ec2:CreateImage",
      "ec2:GetHostReservationPurchasePreview",
      "ec2:DescribeClientVpnConnections",
      "ec2:DescribeByoipCidrs",
      "ec2:GetConsoleScreenshot",
      "ec2:DescribePlacementGroups",
      "ec2:DescribeInternetGateways",
      "ec2:SearchTransitGatewayRoutes",
      "ec2:GetLaunchTemplateData",
      "ec2:CreatePlacementGroup",
      "ec2:DescribeSpotDatafeedSubscription",
      "ec2:DescribeAccountAttributes",
      "ec2:DescribeNetworkInterfacePermissions",
      "ec2:DescribeReservedInstances",
      "ec2:DescribeNetworkAcls",
      "ec2:DescribeRouteTables",
      "ec2:DescribeClientVpnEndpoints",
      "ec2:DescribeEgressOnlyInternetGateways",
      "ec2:DetachVolume",
      "ec2:UpdateSecurityGroupRuleDescriptionsEgress",
      "ec2:DescribeLaunchTemplates",
      "ec2:DescribeVpnConnections",
      "ec2:DescribeVpcPeeringConnections",
      "ec2:DescribeReservedInstancesOfferings",
      "ec2:CreateRouteTable",
      "ec2:GetTransitGatewayAttachmentPropagations",
      "ec2:DescribeFleetInstances",
      "ec2:CreateFleet",
      "ec2:DescribeClientVpnTargetNetworks",
      "ec2:CreateCustomerGateway",
      "ec2:DescribeVpcEndpointServiceConfigurations",
      "ec2:DescribePrefixLists",
      "ec2:GetReservedInstancesExchangeQuote",
      "ec2:DescribeInstanceCreditSpecifications",
      "ec2:DescribeVpcClassicLink",
      "ec2:DescribeLocalGatewayRouteTableVirtualInterfaceGroupAssociations",
      "ec2:CreateFlowLogs",
      "ec2:GetTransitGatewayRouteTablePropagations",
      "ec2:DescribeInstanceTypes",
      "ec2:CreateEgressOnlyInternetGateway",
      "ec2:DescribeVpcEndpoints",
      "ec2:DescribeElasticGpus",
      "ec2:AssociateAddress",
      "ec2:CancelBundleTask",
      "ec2:DescribeVpnGateways",
      "ec2:DescribeTransitGatewayPeeringAttachments",
      "ec2:DescribeAddresses",
      "ec2:DeleteTags",
      "ec2:DescribeInstanceAttribute",
      "ec2:GetCapacityReservationUsage",
      "ec2:DescribeDhcpOptions",
      "ec2:GetConsoleOutput",
      "ec2:DescribeSpotPriceHistory",
      "ec2:DescribeNetworkInterfaces",
      "ec2:CreateSecurityGroup",
      "ec2:GetTransitGatewayRouteTableAssociations",
      "ec2:DescribeIamInstanceProfileAssociations",
      "ec2:DescribeTags",
      "ec2:DescribeLaunchTemplateVersions",
      "ec2:DescribeImportImageTasks",
      "ec2:DescribeNatGateways",
      "ec2:DescribeCustomerGateways",
      "ec2:DescribeLocalGateways",
      "ec2:CreateLaunchTemplateVersion",
      "ec2:DescribeSpotFleetRequests",
      "ec2:DescribeHosts",
      "ec2:DescribeImages",
      "ec2:CreateClientVpnEndpoint",
      "ec2:DescribeSpotFleetInstances",
      "ec2:DescribeSecurityGroupReferences",
      "ec2:DescribePublicIpv4Pools",
      "ec2:DescribeClientVpnAuthorizationRules",
      "ec2:CreateFpgaImage",
      "ec2:DescribeTransitGatewayVpcAttachments",
      "ec2:GetTransitGatewayMulticastDomainAssociations",
      "ec2:DescribeConversionTasks",
    ]
  }
}

data "aws_iam_policy_document" "EKSReadOnly" {
  # checkov:skip=CKV_AWS_107: Ensure IAM policies does not allow credentials exposure
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "eks:DescribeFargateProfile",
      "ec2:DescribeInstances",
      "ec2:GetEbsEncryptionByDefault",
      "ec2:DescribeCoipPools",
      "ec2:DescribeSnapshots",
      "ec2:DescribeLocalGatewayVirtualInterfaces",
      "ec2:DescribeHostReservationOfferings",
      "ec2:DescribeTrafficMirrorSessions",
      "ec2:DescribeExportImageTasks",
      "ec2:DescribeTrafficMirrorFilters",
      "ec2:DescribeVolumeStatus",
      "ec2:DescribeLocalGatewayRouteTableVpcAssociations",
      "ec2:DescribeScheduledInstanceAvailability",
      "ec2:DescribeVolumes",
      "ec2:GetEbsDefaultKmsKeyId",
      "ec2:DescribeFpgaImageAttribute",
      "ec2:DescribeExportTasks",
      "ec2:DescribeTransitGatewayMulticastDomains",
      "ec2:DescribeKeyPairs",
      "ec2:DescribeReservedInstancesListings",
      "ec2:DescribeCapacityReservations",
      "ec2:DescribeClientVpnRoutes",
      "ec2:DescribeSpotFleetRequestHistory",
      "ec2:DescribeVpcClassicLinkDnsSupport",
      "ec2:DescribeSnapshotAttribute",
      "ec2:DescribeIdFormat",
      "ec2:DescribeFastSnapshotRestores",
      "ec2:DescribeVolumeAttribute",
      "ec2:DescribeImportSnapshotTasks",
      "es:ESCrossClusterGet",
      "ec2:DescribeLocalGatewayVirtualInterfaceGroups",
      "ec2:GetPasswordData",
      "ec2:DescribeVpcEndpointServicePermissions",
      "ec2:DescribeTransitGatewayAttachments",
      "ec2:DescribeScheduledInstances",
      "ec2:SearchLocalGatewayRoutes",
      "ec2:DescribeImageAttribute",
      "ec2:DescribeFleets",
      "eks:ListClusters",
      "ec2:DescribeReservedInstancesModifications",
      "ec2:DescribeSubnets",
      "es:ListElasticsearchInstanceTypes",
      "es:DescribeElasticsearchInstanceTypeLimits",
      "ec2:DescribeMovingAddresses",
      "ec2:DescribeFleetHistory",
      "ec2:DescribePrincipalIdFormat",
      "ec2:DescribeFlowLogs",
      "ec2:DescribeRegions",
      "ec2:DescribeTransitGateways",
      "ec2:DescribeVpcEndpointServices",
      "ec2:DescribeSpotInstanceRequests",
      "ec2:DescribeVpcAttribute",
      "es:GetUpgradeHistory",
      "ec2:ExportClientVpnClientCertificateRevocationList",
      "ec2:DescribeInstanceTypeOfferings",
      "ec2:DescribeTrafficMirrorTargets",
      "ec2:DescribeTransitGatewayRouteTables",
      "ec2:DescribeAvailabilityZones",
      "ec2:DescribeNetworkInterfaceAttribute",
      "ec2:DescribeLocalGatewayRouteTables",
      "es:DescribeElasticsearchDomains",
      "ec2:DescribeVpcEndpointConnections",
      "ec2:SearchTransitGatewayMulticastGroups",
      "ec2:DescribeInstanceStatus",
      "es:DescribeReservedElasticsearchInstanceOfferings",
      "ec2:DescribeHostReservations",
      "es:ESHttpGet",
      "ec2:DescribeBundleTasks",
      "ec2:DescribeIdentityIdFormat",
      "ec2:DescribeClassicLinkInstances",
      "es:DescribeElasticsearchDomainConfig",
      "ec2:DescribeVpcEndpointConnectionNotifications",
      "ec2:DescribeSecurityGroups",
      "es:DescribeReservedElasticsearchInstances",
      "ec2:DescribeFpgaImages",
      "es:ListDomainNames",
      "ec2:DescribeVpcs",
      "es:GetUpgradeStatus",
      "ec2:DescribeStaleSecurityGroups",
      "eks:ListTagsForResource",
      "ec2:DescribeAggregateIdFormat",
      "ec2:ExportClientVpnClientConfiguration",
      "ec2:DescribeVolumesModifications",
      "ec2:GetHostReservationPurchasePreview",
      "ec2:DescribeClientVpnConnections",
      "es:ListTags",
      "ec2:DescribeByoipCidrs",
      "ec2:GetConsoleScreenshot",
      "ec2:DescribePlacementGroups",
      "ec2:DescribeInternetGateways",
      "es:ESHttpHead",
      "eks:DescribeNodegroup",
      "ec2:SearchTransitGatewayRoutes",
      "ec2:GetLaunchTemplateData",
      "ec2:DescribeSpotDatafeedSubscription",
      "ec2:DescribeAccountAttributes",
      "ec2:DescribeNetworkInterfacePermissions",
      "ec2:DescribeReservedInstances",
      "ec2:DescribeNetworkAcls",
      "ec2:DescribeRouteTables",
      "ec2:DescribeClientVpnEndpoints",
      "ec2:DescribeEgressOnlyInternetGateways",
      "eks:ListNodegroups",
      "ec2:DescribeLaunchTemplates",
      "ec2:DescribeVpnConnections",
      "ec2:DescribeVpcPeeringConnections",
      "ec2:DescribeReservedInstancesOfferings",
      "ec2:GetTransitGatewayAttachmentPropagations",
      "ec2:DescribeFleetInstances",
      "ec2:DescribeClientVpnTargetNetworks",
      "ec2:DescribeVpcEndpointServiceConfigurations",
      "ec2:DescribePrefixLists",
      "ec2:GetReservedInstancesExchangeQuote",
      "ec2:DescribeInstanceCreditSpecifications",
      "ec2:DescribeVpcClassicLink",
      "ec2:DescribeLocalGatewayRouteTableVirtualInterfaceGroupAssociations",
      "ec2:GetTransitGatewayRouteTablePropagations",
      "es:GetCompatibleElasticsearchVersions",
      "ec2:DescribeInstanceTypes",
      "eks:DescribeCluster",
      "ec2:DescribeVpcEndpoints",
      "ec2:DescribeElasticGpus",
      "ec2:DescribeVpnGateways",
      "ec2:DescribeTransitGatewayPeeringAttachments",
      "ec2:GetDefaultCreditSpecification",
      "ec2:DescribeAddresses",
      "es:ListElasticsearchInstanceTypeDetails",
      "ec2:DescribeInstanceAttribute",
      "ec2:GetCapacityReservationUsage",
      "ec2:DescribeDhcpOptions",
      "ec2:GetConsoleOutput",
      "ec2:DescribeSpotPriceHistory",
      "es:DescribeElasticsearchDomain",
      "ec2:DescribeNetworkInterfaces",
      "eks:ListUpdates",
      "es:DescribeOutboundCrossClusterSearchConnections",
      "ec2:GetTransitGatewayRouteTableAssociations",
      "ec2:DescribeIamInstanceProfileAssociations",
      "ec2:DescribeTags",
      "ec2:GetCoipPoolUsage",
      "ec2:DescribeLaunchTemplateVersions",
      "ec2:DescribeImportImageTasks",
      "ec2:DescribeNatGateways",
      "ec2:DescribeCustomerGateways",
      "ec2:DescribeInstanceEventNotificationAttributes",
      "ec2:DescribeLocalGateways",
      "ec2:DescribeSpotFleetRequests",
      "es:DescribeInboundCrossClusterSearchConnections",
      "ec2:DescribeHosts",
      "ec2:DescribeImages",
      "eks:ListFargateProfiles",
      "ec2:DescribeSpotFleetInstances",
      "ec2:DescribeSecurityGroupReferences",
      "eks:DescribeUpdate",
      "ec2:DescribePublicIpv4Pools",
      "ec2:DescribeClientVpnAuthorizationRules",
      "ec2:DescribeTransitGatewayVpcAttachments",
      "ec2:GetTransitGatewayMulticastDomainAssociations",
      "es:ListElasticsearchVersions",
      "ec2:DescribeConversionTasks",
    ]
  }
}

data "aws_iam_policy_document" "CloudOpsDenyIAM" {
  statement {
    sid       = "VisualEditor0"
    effect    = "Deny"
    resources = ["*"]

    actions = [
      "iam:UpdateAssumeRolePolicy",
      "iam:DeactivateMFADevice",
      "iam:CreateServiceSpecificCredential",
      "iam:DeleteAccessKey",
      "iam:DeleteGroup",
      "iam:UpdateOpenIDConnectProviderThumbprint",
      "iam:RemoveRoleFromInstanceProfile",
      "iam:UpdateGroup",
      "iam:CreateRole",
      "iam:AttachRolePolicy",
      "iam:PutRolePolicy",
      "iam:AddRoleToInstanceProfile",
      "iam:CreateLoginProfile",
      "iam:DetachRolePolicy",
      "iam:CreateAccountAlias",
      "iam:DeleteServerCertificate",
      "iam:UploadSSHPublicKey",
      "iam:DetachGroupPolicy",
      "iam:DetachUserPolicy",
      "iam:DeleteOpenIDConnectProvider",
      "iam:ChangePassword",
      "iam:PutGroupPolicy",
      "iam:UpdateLoginProfile",
      "iam:UpdateServiceSpecificCredential",
      "iam:CreateGroup",
      "iam:RemoveClientIDFromOpenIDConnectProvider",
      "iam:UpdateUser",
      "iam:DeleteUserPolicy",
      "iam:AttachUserPolicy",
      "iam:DeleteRole",
      "iam:UpdateRoleDescription",
      "iam:UpdateAccessKey",
      "iam:UpdateSSHPublicKey",
      "iam:UpdateServerCertificate",
      "iam:DeleteSigningCertificate",
      "iam:UpdateAccountPasswordPolicy",
      "iam:DeleteServiceLinkedRole",
      "iam:CreateInstanceProfile",
      "iam:UntagRole",
      "iam:PutRolePermissionsBoundary",
      "iam:TagRole",
      "iam:ResetServiceSpecificCredential",
      "iam:DeletePolicy",
      "iam:DeleteSSHPublicKey",
      "iam:CreateVirtualMFADevice",
      "iam:CreateSAMLProvider",
      "iam:DeleteRolePermissionsBoundary",
      "iam:CreateUser",
      "iam:CreateAccessKey",
      "iam:AddUserToGroup",
      "iam:RemoveUserFromGroup",
      "iam:DeleteRolePolicy",
      "iam:EnableMFADevice",
      "iam:ResyncMFADevice",
      "iam:DeleteAccountAlias",
      "iam:CreatePolicyVersion",
      "iam:UpdateSAMLProvider",
      "iam:DeleteLoginProfile",
      "iam:DeleteInstanceProfile",
      "iam:UploadSigningCertificate",
      "iam:DeleteAccountPasswordPolicy",
      "iam:PutUserPermissionsBoundary",
      "iam:DeleteUser",
      "iam:DeleteUserPermissionsBoundary",
      "iam:TagUser",
      "iam:CreateOpenIDConnectProvider",
      "iam:UploadServerCertificate",
      "iam:CreatePolicy",
      "iam:UntagUser",
      "iam:CreateServiceLinkedRole",
      "iam:DeleteVirtualMFADevice",
      "iam:AttachGroupPolicy",
      "iam:PutUserPolicy",
      "iam:UpdateRole",
      "iam:UpdateSigningCertificate",
      "iam:DeleteGroupPolicy",
      "iam:AddClientIDToOpenIDConnectProvider",
      "iam:DeleteServiceSpecificCredential",
      "iam:DeletePolicyVersion",
      "iam:SetDefaultPolicyVersion",
      "iam:DeleteSAMLProvider",
    ]
  }
}

data "aws_iam_policy_document" "aomap-ms-ns-aoma3-sa-aoma-export-service-policy" {
  # checkov:skip=CKV_AWS_108: Ensure IAM policies does not allow data exfiltration
  # checkov:skip=CKV_AWS_109: Ensure IAM policies does not allow permissions management / resource exposure without constraints
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/aoma3/aes-w3XPUx",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/aoma3/aes-*",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/ms_export_srvc-*",
    ]

    actions = [
      "secretsmanager:GetResourcePolicy",
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecretVersionIds",
    ]
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["*"]
    actions = [
      "secretsmanager:GetRandomPassword",
      "s3:*",
      "kms:GenerateDataKey",
      "kms:Decrypt"
    ]
  }

  statement {
    sid    = "VisualEditor5"
    effect = "Allow"
    resources = [
      "arn:aws:s3:::sme-delivery-aoma-upload",
      "arn:aws:s3:::sme-delivery-aoma-upload/*",
      "arn:aws:s3:::amp-asset-repo-digb-0001-p",
      "arn:aws:s3:::amp-asset-repo-digb-0001-p/*",
    ]
    actions = [
      "s3:*"
    ]
  }

  statement {
    sid    = "VisualEditor2"
    effect = "Allow"

    resources = [
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/aoma3/aes-w3XPUx",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/aoma3/aes-*",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAExportStatusNotification",
      "arn:aws:sqs:eu-central-1:613871678587:AOMAExportCopyPackageRequest",
      "arn:aws:sqs:eu-central-1:613871678587:AOMAExportCopyPackageResponse",
    ]

    actions = [
      "sqs:DeleteMessage",
      "sqs:GetQueueUrl",
      "sqs:ListDeadLetterSourceQueues",
      "sqs:ChangeMessageVisibility",
      "sqs:PurgeQueue",
      "sqs:ReceiveMessage",
      "sqs:DeleteQueue",
      "sqs:SendMessage",
      "sqs:GetQueueAttributes",
      "sqs:ListQueueTags",
      "sqs:CreateQueue",
      "sqs:SetQueueAttributes",
    ]
  }

  statement {
    sid    = "VisualEditor3"
    effect = "Allow"

    resources = [
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/aoma3/aes-w3XPUx",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/aoma3/aes-*",
    ]

    actions = [
      "sqs:DeleteMessageBatch",
      "sqs:SendMessageBatch",
      "sqs:ChangeMessageVisibilityBatch",
    ]
  }

  statement {
    sid       = "VisualEditor4"
    effect    = "Allow"
    resources = ["arn:aws:iam::635220336377:role/gdsp-sa-aoma-role"]
    actions   = ["sts:AssumeRole"]
  }

  statement {
    sid    = "VisualEditor6"
    effect = "Allow"
    resources = [
      "arn:aws:kafka:eu-central-1:${var.account_id}:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ticket-events",
      "arn:aws:kafka:eu-central-1:${var.account_id}:group/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/aoma3.export*",
      "arn:aws:kafka:eu-central-1:${var.account_id}:cluster/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3",
    ]

    actions = [
      "kafka-cluster:ReadData",
      "kafka-cluster:DescribeTopicDynamicConfiguration",
      "kafka-cluster:DescribeTopic",
      "kafka-cluster:DescribeGroup",
      "kafka-cluster:DescribeClusterDynamicConfiguration",
      "kafka-cluster:DescribeCluster",
      "kafka-cluster:Connect",
      "kafka-cluster:AlterGroup",
    ]
  }
}

data "aws_iam_policy_document" "aomap-eks-aomap-ms-sa-aoma-product-service" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/aoma3/aps-NDDuRc",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAQcNotesNotificationQueue",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAApprovalNotificationQueue",
    ]

    actions = [
      "sqs:DeleteMessage",
      "sqs:GetQueueUrl",
      "sqs:ChangeMessageVisibility",
      "secretsmanager:DescribeSecret",
      "sqs:SendMessageBatch",
      "sqs:ReceiveMessage",
      "sqs:SendMessage",
      "sqs:GetQueueAttributes",
      "sqs:ListQueueTags",
      "secretsmanager:ListSecretVersionIds",
      "secretsmanager:GetResourcePolicy",
      "secretsmanager:GetSecretValue",
      "sqs:ListDeadLetterSourceQueues",
      "sqs:DeleteMessageBatch",
      "sqs:PurgeQueue",
      "sqs:ChangeMessageVisibilityBatch",
      "sqs:SetQueueAttributes",
    ]
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "secretsmanager:GetRandomPassword",
      "sqs:ListQueues",
      "secretsmanager:ListSecrets",
    ]
  }
}

data "aws_iam_policy_document" "aomadevelopers-prod" {
  # checkov:skip=CKV_AWS_108: Ensure IAM policies does not allow data exfiltration
  # checkov:skip=CKV_AWS_109: Ensure IAM policies does not allow permissions management / resource exposure without constraints
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "elasticfilesystem:*",
      "application-autoscaling:*",
      "secretsmanager:*",
      "ecs:*",
      "ecr:*",
      "elasticloadbalancing:*",
      "autoscaling-plans:*",
      "autoscaling:*",
      "mobiletargeting:*",
      "kms:*",
    ]
  }
  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "lambda:Get*",
      "lambda:List*",
    ]
  }

  statement {
    sid    = "VisualEditor2"
    effect = "Allow"
    resources = [
      "arn:aws:s3:::sme-aoma-core-prod-email-notification-attachment",
      "arn:aws:s3:::sme-aoma-core-prod-email-notification-attachment/*"
    ]

    actions = [
      "s3:*"
    ]
  }
}

data "aws_iam_policy_document" "ES-Access" {
  # checkov:skip=CKV_AWS_109: Ensure IAM policies does not allow permissions management / resource exposure without constraints
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]
    actions   = ["es:*"]
  }
}

data "aws_iam_policy_document" "aomap-eks-aomap-ms-sa-gras-ws-proxy" {
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/aoma3/gras-ws-proxy-iZSyiJ"]

    actions = [
      "secretsmanager:GetResourcePolicy",
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecretVersionIds",
    ]
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "secretsmanager:GetRandomPassword",
      "secretsmanager:ListSecrets",
    ]
  }
}

data "aws_iam_policy_document" "GSIRT_AWS_S3AccessLog_Collection" {
  statement {
    sid    = ""
    effect = "Allow"

    resources = [
      "arn:aws:sqs:eu-central-1:${var.account_id}:aomap-s3logs-euc1",
      "arn:aws:sqs:eu-central-1:${var.account_id}:aomap-lblogs-euc1",
      "arn:aws:s3:::sme-aoma-core-prod-ff-s3logs/*",
      "arn:aws:s3:::sme-aoma-core-prod-ff-s3logs",
      "arn:aws:s3:::sme-aoma-core-prod-ff-alblogs/*",
      "arn:aws:s3:::sme-aoma-core-prod-ff-alblogs",
    ]

    actions = [
      "sqs:GetQueueUrl",
      "sqs:ReceiveMessage",
      "sqs:SendMessage",
      "sqs:DeleteMessage",
      "sqs:ChangeMessageVisibility",
      "sqs:GetQueueAttributes",
      "sqs:ListQueues",
      "s3:GetObject",
      "s3:GetObjectVersion",
      "kms:Decrypt",
    ]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]
    actions   = ["sqs:ListQueues"]
  }
}

data "aws_iam_policy_document" "AWSQuickSightIAMPolicy" {
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]
    actions   = ["iam:List*"]
  }
}

data "aws_iam_policy_document" "root" {
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["arn:aws:logs:*:*:*"]

    actions = [
      "logs:CreateLogGroup",
      "logs:CreateLogStream",
      "logs:PutLogEvents",
    ]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["arn:aws:iam::*:role/DeepSecurity*"]

    actions = [
      "iam:GetRole",
      "iam:GetRolePolicy",
    ]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "ec2:DescribeRegions",
      "ec2:DescribeImages",
      "ec2:DescribeInstances",
      "ec2:DescribeTags",
      "ec2:DescribeAvailabilityZones",
      "ec2:DescribeSecurityGroups",
      "ec2:DescribeSubnets",
      "ec2:DescribeVpcs",
      "iam:ListAccountAliases",
    ]
  }
}

data "aws_iam_policy_document" "sme-aoma-core-prod-waf-logging-policy" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:s3:::sme-core-cloud-compliance-waf-logs",
      "arn:aws:s3:::sme-core-cloud-compliance-waf-logs/*",
    ]

    actions = [
      "s3:AbortMultipartUpload",
      "s3:GetBucketLocation",
      "s3:GetObject",
      "s3:ListBucket",
      "s3:ListBucketMultipartUploads",
      "s3:PutObjectAcl",
      "s3:PutObject",
    ]
  }
}

data "aws_iam_policy_document" "aomap-eks-aomap-ms-sa-aoma-mail-service" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/aoma3/aomams-De7PIe",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/ms_product_srvc-*",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAQcNotesNotificationQueue",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAApprovalNotificationQueue",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AomaUserSecretKeyNotification",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAApprovalNotificationDLQ",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAQcNotesNotificationDLQ",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAEmailNotification",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAExportStatusNotification",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAExportStatusNotificationDLQ",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAEmailNotificationDLQ",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMADownloadAssetNotification",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMADownloadAssetNotificationDLQ",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAProductApprovalNotification",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAProductApprovalNotificationDLQ",
      "arn:aws:kms:eu-central-1:${var.account_id}:key/f3f00387-1ce2-4e0b-8528-dfcb0a8a56c0",

    ]

    actions = [
      "sqs:*",
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecretVersionIds",
      "secretsmanager:GetResourcePolicy",
      "secretsmanager:GetSecretValue",
      "kms:*"
    ]
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "secretsmanager:GetRandomPassword",
      "sqs:ListQueues",
      "secretsmanager:ListSecrets",
    ]
  }
}

data "aws_iam_policy_document" "aomap-aoma-txmgr-s3" {
  statement {
    sid    = "programmatically"
    effect = "Allow"

    resources = [
      "arn:aws:s3:::sme-aoma-txmgr-metadata-import-prod-dropoff",
      "arn:aws:s3:::sme-aoma-txmgr-metadata-import-prod-large-track",
      "arn:aws:s3:::sme-aoma-txmgr-metadata-import-prod-priority",
      "arn:aws:s3:::sme-aoma-txmgr-metadata-import-prod-processed",
      "arn:aws:s3:::sme-aoma-txmgr-metadata-import-prod-dropoff/*",
      "arn:aws:s3:::sme-aoma-txmgr-metadata-import-prod-large-track/*",
      "arn:aws:s3:::sme-aoma-txmgr-metadata-import-prod-priority/*",
      "arn:aws:s3:::sme-aoma-txmgr-metadata-import-prod-processed/*",
      "arn:aws:s3:::sme-aoma-core-prod-arvato-temp/*",
      "arn:aws:s3:::sme-aoma-core-prod-arvato-temp",
    ]

    actions = ["s3:*"]
  }

  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:s3:::sme-digsysp-txmgr01",
      "arn:aws:s3:::sme-digsysp-txmgr01/*",
    ]

    actions = [
      "s3:AbortMultipartUpload",
      "s3:GetBucketLocation",
      "s3:GetObject",
      "s3:ListBucket",
      "s3:ListBucketMultipartUploads",
      "s3:PutObjectAcl",
      "s3:PutObject",
      "s3:DeleteObject"
    ]
  }

}

data "aws_iam_policy_document" "aomap-cert-policy" {
  # checkov:skip=CKV_AWS_107: Ensure IAM policies does not allow credentials exposure
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "acm:ExportCertificate",
      "acm:DescribeCertificate",
      "acm:RequestCertificate",
      "acm:GetCertificate",
      "acm:ListCertificates",
      "sts:AssumeRoleWithWebIdentity",
      "acm:ListTagsForCertificate",
    ]
  }
}

data "aws_iam_policy_document" "corep-portal-policy" {
  # checkov:skip=CKV_AWS_107: Ensure IAM policies does not allow credentials exposure
  # checkov:skip=CKV_AWS_108: Ensure IAM policies does not allow data exfiltration
  # checkov:skip=CKV_AWS_109: Ensure IAM policies does not allow permissions management / resource exposure without constraints
  # checkov:skip=CKV_AWS_110: Ensure IAM policies does not allow privilege escalation
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "ssm:SendCommand",
      "waf-regional:GetRuleGroup",
      "waf-regional:GetRateBasedRuleManagedKeys",
      "ses: ListIdentities",
      "waf-regional:GetRateBasedRule",
      "s3:List*",
      "s3:Get*",
      "waf-regional:GetRegexMatchSet",
      "waf-regional:UpdateSqlInjectionMatchSet",
      "ses:GetIdentityDkimAttributes",
      "waf-regional:GetWebACL",
      "ec2:DescribeVolumes",
      "config:DescribeConfigRules",
      "ec2:DescribeKeyPairs",
      "waf-regional:GetXssMatchSet",
      "iam:ListPolicies",
      "iam:GetRole",
      "rds:DescribeDBSnapshots",
      "cloudtrail:LookupEvents",
      "lambda:*",
      "waf-regional:ListIPSets",
      "elasticloadbalancing:AddTags",
      "inspector:ListFindings",
      "glacier:ListVaults",
      "waf-regional:ListLoggingConfigurations",
      "ssm:DescribePatchGroups",
      "ec2:DescribeFlowLogs",
      "waf-regional:ListRateBasedRules",
      "waf-regional:DeleteGeoMatchSet",
      "waf-regional:GetGeoMatchSet",
      "waf-regional:ListResourcesForWebACL",
      "waf-regional:GetRegexPatternSet",
      "ssm:DescribeInstancePatchStatesForPatchGroup",
      "ec2:CreateSnapshot",
      "waf-regional:GetSampledRequests",
      "es:DescribeElasticsearchDomains",
      "rds:AddTagsToResource",
      "ec2:ReleaseAddress",
      "inspector:ListAssessmentTargets",
      "waf-regional:DeleteRateBasedRule",
      "iam:ListRoles",
      "waf-regional:ListGeoMatchSets",
      "waf-regional:DeleteRegexMatchSet",
      "waf-regional:DeleteLoggingConfiguration",
      "waf-regional:ListActivatedRulesInRuleGroup",
      "waf-regional:UpdateByteMatchSet",
      "ec2:DescribeSecurityGroups",
      "s3:PutInventoryConfiguration",
      "es:ListDomainNames",
      "rds:ListTagsForResource",
      "elasticloadbalancing:DescribeTargetGroups",
      "iam:ListGroups",
      "iam:UpdateAssumeRolePolicy",
      "iam:GetPolicyVersion",
      "waf-regional:GetChangeToken",
      "waf-regional:UpdateXssMatchSet",
      "ssm:DescribeInstancePatches",
      "waf-regional:UpdateIPSet",
      "waf-regional:GetSqlInjectionMatchSet",
      "elasticloadbalancing:DescribeLoadBalancers",
      "waf-regional:ListTagsForResource",
      "waf-regional:UpdateRegexMatchSet",
      "waf-regional:ListRegexMatchSets",
      "route53:ListResourceRecordSets",
      "ec2:DescribeReservedInstances",
      "trustedadvisor:Describe*",
      "waf-regional:PutLoggingConfiguration",
      "rds:DescribeDBSnapshots",
      "ec2:DescribeVpcPeeringConnections",
      "glacier:ListTagsForVault",
      "iam:GetAccessKeyLastUsed",
      "waf-regional:CreateSqlInjectionMatchSet",
      "ses:GetIdentityVerificationAttributes",
      "waf-regional:CreateRateBasedRule",
      "eks:DescribeCluster",
      "elasticache:DescribeCacheClusters",
      "waf-regional:ListSqlInjectionMatchSets",
      "waf-regional:CreateRegexPatternSet",
      "ec2:DescribeVpnGateways",
      "iam:GetAccountSummary",
      "ec2:DescribeAddresses",
      "waf-regional:GetByteMatchSet",
      "kafka:ListClusters",
      "s3:GetBucketLogging",
      "iam:ListMFADevices",
      "waf-regional:GetRule",
      "s3:PutEncryptionConfiguration",
      "s3:GetEncryptionConfiguration",
      "directconnect:DescribeVirtualInterfaces",
      "waf-regional:UpdateSizeConstraintSet",
      "waf-regional:CreateSizeConstraintSet",
      "waf-regional:ListRuleGroups",
      "ecs:ListClusters",
      "health:DescribeEvents",
      "sqs:ListQueues",
      "waf-regional:CreateGeoMatchSet",
      "waf-regional:ListByteMatchSets",
      "iam:ListUserPolicies",
      "waf-regional:UpdateRule",
      "waf-regional:DeleteIPSet",
      "elasticloadbalancing:DescribeTargetHealth",
      "iam:ListUsers",
      "waf-regional:CreateRule",
      "iam:ListUserTags",
      "iam:DeleteAccessKey",
      "ec2:DescribeInstances",
      "ses:GetIdentityMailFromDomainAttributes",
      "ec2:DescribeSnapshots",
      "waf-regional:DeleteByteMatchSet",
      "waf-regional:GetWebACLForResource",
      "iam:GetCredentialReport",
      "waf-regional:ListWebACLs",
      "ec2:CreateTags",
      "waf-regional:UpdateRegexPatternSet",
      "iam:ListEntitiesForPolicy",
      "kafka:DescribeCluster",
      "cloudwatch:GetMetricStatistics",
      "waf-regional:ListRules",
      "cloudtrail:DescribeTrails",
      "eks:ListClusters",
      "ec2:DescribeSubnets",
      "iam:GenerateCredentialReport",
      "waf-regional:AssociateWebACL",
      "ce:GetCostAndUsage",
      "kms:ListResourceTags",
      "s3:AbortMultipartUpload",
      "s3:PutBucketTagging",
      "rds:DescribeDBInstances",
      "lambda:UpdateFunctionConfiguration",
      "iam:ListAttachedGroupPolicies",
      "iam:ListAccessKeys",
      "iam:ListGroupPolicies",
      "route53:ListHostedZones",
      "waf-regional:DeleteSizeConstraintSet",
      "waf-regional:CreateRegexMatchSet",
      "ses:GetIdentityNotificationAttributes",
      "es:DescribeElasticsearchDomainConfig",
      "inspector:ListAssessmentRuns",
      "ses:ListIdentityPolicies",
      "waf-regional:DeleteXssMatchSet",
      "ec2:DescribeVpcs",
      "kms:ListAliases",
      "waf-regional:UpdateRateBasedRule",
      "waf-regional:DeleteRegexPatternSet",
      "waf-regional:GetPermissionPolicy",
      "waf-regional:GetLoggingConfiguration",
      "ec2:DescribeInternetGateways",
      "ec2:DeleteVolume",
      "iam:ListAttachedRolePolicies",
      "elasticloadbalancing:DescribeLoadBalancerPolicies",
      "waf-regional:GetIPSet",
      "ec2:Describe*",
      "waf-regional:DeleteRuleGroup",
      "waf-regional:GetChangeTokenStatus",
      "waf-regional:ListRegexPatternSets",
      "iam:UpdateAccessKey",
      "sqs:GetQueueAttributes",
      "ecs:DescribeClusters",
      "elasticloadbalancing:DescribeLoadBalancerAttributes",
      "waf-regional:CreateIPSet",
      "acm:DescribeCertificate",
      "s3:PutBucketLogging",
      "iam:ListGroupsForUser",
      "waf-regional:CreateXssMatchSet",
      "ec2:DescribeVpcEndpoints",
      "waf-regional:ListXssMatchSets",
      "waf-regional:DeleteRule",
      "waf-regional:CreateRuleGroup",
      "ec2:DeleteSnapshot",
      "ec2:DescribeInstanceAttribute",
      "iam:CreateAccessKey",
      "waf-regional:GetSizeConstraintSet",
      "waf-regional:CreateByteMatchSet",
      "elasticloadbalancing:DescribeListeners",
      "es:DescribeElasticsearchDomain",
      "ec2:DescribeNetworkInterfaces",
      "wafv2:*",
      "iam:ListAttachedUserPolicies",
      "acm:ListCertificates",
      "kms:DescribeKey",
      "elasticfilesystem:DescribeFileSystems",
      "inspector:DescribeFindings",
      "s3:PutBucketPublicAccessBlock",
      "waf-regional:DisassociateWebACL",
      "elasticloadbalancing:DescribeTags",
      "ec2:DescribeNatGateways",
      "ec2:DescribeCustomerGateways",
      "support:*",
      "ec2:DescribeImages",
      "cloudfront:ListDistributions",
      "redshift:DescribeClusters",
      "waf-regional:*",
      "s3:GetBucketLocation",
      "ec2:CreateRouteTable",
      "ec2:CreateRoute",
      "ec2:ModifyVpcEndpoint",
      "s3:GetBucketTagging",
      "iam:ListAccountAliases",
      "firehose:CreateDeliveryStream",
      "iam:PassRole",
      "apigateway:GET",
      "elasticmapreduce:ListClusters",
      "ssm:SendCommand",
      "ssm:DescribeInstanceInformation",
      "ssm:GetCommandInvocation",
      "config:GetResourceConfigHistory",
    ]
  }
}

data "aws_iam_policy_document" "aomap-ecs-aomap-ust-taskdef-task-policy" {
  # checkov:skip=CKV_AWS_108: Ensure IAM policies does not allow data exfiltration
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:lambda:eu-central-1:${var.account_id}:function:AOMA-GRAS",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/Aoma/Ust-1BfaDp",
    ]

    actions = [
      "lambda:CreateFunction",
      "lambda:TagResource",
      "lambda:PublishLayerVersion",
      "lambda:DeleteProvisionedConcurrencyConfig",
      "lambda:InvokeAsync",
      "lambda:UntagResource",
      "lambda:PutFunctionConcurrency",
      "lambda:DeleteCodeSigningConfig",
      "secretsmanager:GetSecretValue",
      "lambda:DeleteLayerVersion",
      "lambda:PutFunctionEventInvokeConfig",
      "lambda:DeleteFunctionEventInvokeConfig",
      "lambda:DeleteFunction",
      "lambda:CreateCodeSigningConfig",
      "lambda:PutFunctionCodeSigningConfig",
      "lambda:UpdateFunctionEventInvokeConfig",
      "lambda:DeleteFunctionCodeSigningConfig",
      "lambda:UpdateEventSourceMapping",
      "lambda:UpdateFunctionCodeSigningConfig",
      "lambda:InvokeFunction",
      "lambda:UpdateFunctionConfiguration",
      "lambda:UpdateAlias",
      "lambda:UpdateCodeSigningConfig",
      "lambda:UpdateFunctionCode",
      "lambda:ListFunctionEventInvokeConfigs",
      "lambda:GetFunctionEventInvokeConfig",
      "lambda:PutProvisionedConcurrencyConfig",
      "lambda:DeleteAlias",
      "lambda:PublishVersion",
      "lambda:DeleteFunctionConcurrency",
      "lambda:DeleteEventSourceMapping",
      "lambda:CreateAlias",
    ]
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "sqs:ListQueues",
      "ses:SendRawEmail",
      "logs:*",
      "lambda:CreateEventSourceMapping",
      "secretsmanager:GetSecretValue",
    ]
  }

  statement {
    sid    = "VisualEditor2"
    effect = "Allow"

    resources = [
      "arn:aws:sqs:eu-central-1:${var.account_id}:ust-bulkRegistration-sqs-prod",
      "arn:aws:sqs:eu-central-1:${var.account_id}:ust-assetupload-sqs",
      "arn:aws:sqs:eu-central-1:${var.account_id}:ust-prod-assetupload-sqs",
    ]

    actions = ["sqs:*"]
  }
}

data "aws_iam_policy_document" "aomap-quicksight-prog" {
  # checkov:skip=CKV_AWS_109: Ensure IAM policies does not allow permissions management / resource exposure without constraints
  # checkov:skip=CKV_AWS_110: Ensure IAM policies does not allow privilege escalation
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]
    actions = [
      "quicksight:*",
      "glue:*",
      "athena:*"
    ]
  }
  statement {
    sid       = "VisualEditor88"
    effect    = "Allow"
    resources = ["arn:aws:iam::505950216627:role/promop-quicksight-prog"]
    actions   = ["sts:AssumeRole"]
  }

  statement {
    sid       = "VisualEditor89"
    effect    = "Allow"
    resources = ["arn:aws:iam::638682502729:role/delconvp-quicksight-prog"]
    actions   = ["sts:AssumeRole"]
  }

  statement {
    sid    = "VisualEditor1"
    effect = "Allow"
    resources = ["arn:aws:quicksight:eu-central-1:${var.account_id}:user/default/aomad-quicksight-prog",
    "arn:aws:quicksight:us-east-1:505950216627:user/default/promop-quicksight-prog"]
    actions = ["quicksight:GenerateEmbedUrlForRegisteredUser"]
  }

  statement {
    sid    = "VisualEditor2"
    effect = "Allow"
    resources = [
      "arn:aws:s3:::sme-aoma-core-prod-quicksight",
      "arn:aws:s3:::sme-aoma-core-prod-quicksight/*",
      "arn:aws:s3:::sme-aoma-core-prod-dw/*",
      "arn:aws:s3:::sme-aoma-core-prod-dw",
      "arn:aws:s3:::sme-amp-prod-dw/*",
      "arn:aws:s3:::sme-amp-prod-dw",
      "arn:aws:s3:::sme-amp-prod-rds-backups/*",
      "arn:aws:s3:::sme-amp-prod-rds-backups",
      "arn:aws:s3:::sme-media-services-prod-rds-backups/*",
      "arn:aws:s3:::sme-media-services-prod-rds-backups",
      "arn:aws:s3:::sme-media-conversion-prod-rds-backups",
      "arn:aws:s3:::sme-media-conversion-prod-rds-backups/*",
      "arn:aws:s3:::sme-media-conversion-prod-lambda-archived",
      "arn:aws:s3:::sme-media-conversion-prod-lambda-archived/*",
    ]

    actions = [
      "s3:*",
    ]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["arn:aws:kms:us-east-1:361463692799:key/46219473-a94b-4e07-996a-6785ac63f844"]
    actions   = ["kms:Decrypt"]
  }
}

data "aws_iam_policy_document" "DeepSecurity" {
  statement {
    sid       = "1"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "ec2:DescribeRegions",
      "ec2:DescribeImages",
      "ec2:DescribeInstances",
      "ec2:DescribeTags",
      "ec2:DescribeAvailabilityZones",
      "ec2:DescribeSecurityGroups",
      "ec2:DescribeSubnets",
      "ec2:DescribeVpcs",
      "iam:ListAccountAliases",
    ]
  }

  statement {
    sid       = "2"
    effect    = "Allow"
    resources = ["arn:aws:iam::*:role/DeepSecurity*"]

    actions = [
      "iam:GetRole",
      "iam:GetRolePolicy",
    ]
  }

  statement {
    sid       = "3"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "workspaces:DescribeWorkspaces",
      "workspaces:DescribeWorkspaceDirectories",
      "workspaces:DescribeWorkspaceBundles",
      "workspaces:DescribeTags",
    ]
  }
}

data "aws_iam_policy_document" "aoma-RDS_snapshot_lambda-policy" {
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:s3:::sme-aoma-core-dev-rds-backups",
      "arn:aws:s3:::sme-aoma-core-dev-rds-backups/*",
      "arn:aws:s3:::sme-aoma-core-prod-dw",
      "arn:aws:s3:::sme-aoma-core-prod-dw/*",
      "arn:aws:iam::${var.account_id}:role/aoma-RDS_snapshot_lambda-role",
      "arn:aws:kms:eu-central-1:${var.account_id}:key/f3f00387-1ce2-4e0b-8528-dfcb0a8a56c0",
    ]

    actions = [
      "s3:PutObject",
      "s3:GetObject",
      "iam:PassRole",
      "kms:Decrypt",
      "s3:ListBucket",
      "s3:DeleteObject",
      "s3:GetBucketLocation",
    ]
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "kms:ListKeys",
      "logs:CreateLogStream",
      "rds:DescribeDBSnapshots",
      "rds:CopyDBSnapshot",
      "rds:DescribeExportTasks",
      "rds:StartExportTask",
      "rds:DescribeDBClusterSnapshots",
      "logs:PutDestination",
      "logs:CreateLogGroup",
      "logs:PutLogEvents",
      "rds:DescribeDBSnapshotAttributes",
      "logs:ListLogDeliveries",
      "sns:ListTopics",
    ]
  }

  statement {
    sid       = "VisualEditor2"
    effect    = "Allow"
    resources = ["arn:aws:sns:eu-central-1:${var.account_id}:DB-TEAM"]
    actions   = ["sns:Publish"]
  }
}

data "aws_iam_policy_document" "RDSProxyIAMPolicy" {
  # checkov:skip=CKV_AWS_108: Ensure IAM policies does not allow data exfiltration
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["arn:aws:kms:eu-central-1:${var.account_id}:key/f3f00387-1ce2-4e0b-8528-dfcb0a8a56c0"]
    actions   = ["kms:Decrypt"]

    condition {
      test     = "StringEquals"
      variable = "kms:ViaService"
      values   = ["secretsmanager.eu-central-1.amazonaws.com"]
    }
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "secretsmanager:GetRandomPassword",
      "secretsmanager:GetResourcePolicy",
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecretVersionIds",
      "secretsmanager:ListSecrets",
    ]
  }
}

data "aws_iam_policy_document" "amp-asset-import-request-sqs-prod" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:sqs:us-east-1:554998489284:amp-asset-import-request-sqs-prod",
      "arn:aws:sqs:us-east-1:554998489284:amp-asset-import-status-sqs-prod",
      "arn:aws:sqs:us-east-1:554998489284:amp-graphics-metadata-extract-request-sqs-prod",
      "arn:aws:sqs:us-east-1:554998489284:amp-graphics-metadata-extract-status-sqs-prod",
    ]

    actions = [
      "sqs:DeleteMessage",
      "sqs:GetQueueUrl",
      "sqs:ReceiveMessage",
      "sqs:SendMessage",
      "sqs:GetQueueAttributes",
      "sqs:DeleteMessage",
    ]
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["*"]
    actions   = ["sqs:ListQueues"]
  }
}

data "aws_iam_policy_document" "aomap-prod-presvc" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:s3:::amp-audio-archives-prod",
      "arn:aws:s3:::amp-audio-archives-prod/*",
      "arn:aws:s3:::amp-photo-archives-prod",
      "arn:aws:s3:::amp-photo-archives-prod/*",
      "arn:aws:s3:::amp-video-archives-prod",
      "arn:aws:s3:::amp-video-archives-prod/*",
    ]

    actions = [
      "s3:GetObject",
      "s3:RestoreObject",
      "s3:ListBucket",
    ]
  }

  statement {
    sid    = "VisualEditor1"
    effect = "Allow"

    resources = [
      "arn:aws:sqs:eu-central-1:${var.account_id}:ElementalMediaConvertRequestQ-prod",
      "arn:aws:sqs:eu-central-1:${var.account_id}:ElementalMediaConvertStatusQ-prod",
    ]

    actions = [
      "sqs:GetQueueUrl",
      "sqs:GetQueueAttributes",
      "sqs:SendMessage",
      "sqs:ReceiveMessage",
      "sqs:DeleteMessage",
    ]
  }
}

data "aws_iam_policy_document" "aomap-ecs-aomap-ameba-schema-registry-taskdef-task-policy" {
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]
    actions   = ["logs:*"]
  }
}

data "aws_iam_policy_document" "RDSAdminIAMPassRole" {
  # checkov:skip=CKV_AWS_109: Ensure IAM policies does not allow permissions management / resource exposure without constraints
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "iam:PassRole",
      "iam:ListRoles",
      "acm:RequestCertificate",
      "acm:AddTagsToCertificate",
      "acm:ExportCertificate",
    ]
  }
}

data "aws_iam_policy_document" "aomap-prod-ampcntpv" {
  # checkov:skip=CKV_AWS_109: Ensure IAM policies does not allow permissions management / resource exposure without constraints
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "s3:ListAccessPointsForObjectLambda",
      "s3:GetAccessPoint",
      "sqs:ListQueues",
      "s3:PutAccountPublicAccessBlock",
      "s3:ListAccessPoints",
      "s3:ListJobs",
      "s3:PutStorageLensConfiguration",
      "s3:ListMultiRegionAccessPoints",
      "s3:ListStorageLensConfigurations",
      "s3:GetAccountPublicAccessBlock",
      "s3:ListAllMyBuckets",
      "kms:*",
      "s3:PutAccessPointPublicAccessBlock",
      "s3:CreateJob",
    ]
  }

  statement {
    sid    = "VisualEditor1"
    effect = "Allow"

    resources = [
      "arn:aws:sqs:us-east-1:554998489284:metadata-extract-status-sqs-prod",
      "arn:aws:sqs:us-east-1:554998489284:amp-asset-copy-request-sqs-prod",
      "arn:aws:sqs:us-east-1:554998489284:amp-asset-copy-status-sqs-prod",
      "arn:aws:sqs:us-east-1:554998489284:amp-asset-analyzer-status-sqs-prod",
      "arn:aws:sqs:us-east-1:554998489284:amp-asset-analyzer-request-sqs-prod",
      "arn:aws:sqs:us-east-1:554998489284:da-batch-sqs-job-controller",
    ]

    actions = [
      "sqs:DeleteMessage",
      "sqs:GetQueueUrl",
      "sqs:ListDeadLetterSourceQueues",
      "sqs:ReceiveMessage",
      "sqs:SendMessage",
      "sqs:GetQueueAttributes",
      "sqs:ListQueueTags",
    ]
  }

  statement {
    sid       = "VisualEditor2"
    effect    = "Allow"
    resources = ["arn:aws:sqs:eu-central-1:${var.account_id}:AOMAEmailNotification"]

    actions = [
      "sqs:DeleteMessage",
      "sqs:GetQueueUrl",
      "sqs:UntagQueue",
      "sqs:ReceiveMessage",
      "sqs:SendMessage",
      "sqs:GetQueueAttributes",
      "sqs:ListQueueTags",
      "sqs:TagQueue",
      "sqs:RemovePermission",
      "sqs:ListDeadLetterSourceQueues",
      "sqs:AddPermission",
      "sqs:PurgeQueue",
      "sqs:DeleteQueue",
      "sqs:CreateQueue",
    ]
  }

  statement {
    sid    = "VisualEditor3"
    effect = "Allow"

    resources = [
      "arn:aws:s3:::metadata-extract-request-sqs-payloads-prod",
      "arn:aws:s3:::amp-photo-archives-prod",
      "arn:aws:s3:::amp-audio-archives-prod",
      "arn:aws:s3:::amp-video-archives-prod",
      "arn:aws:s3:::amp-audio-archives-prod-eu",
      "arn:aws:s3:::amp-video-archives-prod-eu",
      "arn:aws:s3:::amp-photo-archives-prod-eu",
      "arn:aws:s3:::amp-asset-transfer-sqs-payloads-prod",
      "arn:aws:s3:::metadata-extract-request-sqs-payloads-prod/*",
      "arn:aws:s3:::amp-photo-archives-prod/*",
      "arn:aws:s3:::amp-audio-archives-prod/*",
      "arn:aws:s3:::amp-video-archives-prod/*",
      "arn:aws:s3:::amp-audio-archives-prod-eu/*",
      "arn:aws:s3:::amp-video-archives-prod-eu/*",
      "arn:aws:s3:::amp-photo-archives-prod-eu/*",
      "arn:aws:s3:::amp-asset-transfer-sqs-payloads-prod/*",
    ]

    actions = ["s3:*"]
  }

  statement {
    sid    = "VisualEditor4"
    effect = "Allow"

    resources = [
      "arn:aws:s3:::metadata-extract-request-sqs-payloads-prod/*",
      "arn:aws:s3:::amp-photo-archives-prod/*",
      "arn:aws:s3:::amp-audio-archives-prod/*",
      "arn:aws:s3:::amp-video-archives-prod/*",
      "arn:aws:s3:::amp-audio-archives-prod-eu/*",
      "arn:aws:s3:::amp-video-archives-prod-eu/*",
      "arn:aws:s3:::amp-photo-archives-prod-eu/*",
      "arn:aws:s3:::metadata-extract-request-sqs-payloads-prod",
      "arn:aws:s3:::amp-photo-archives-prod",
      "arn:aws:s3:::amp-audio-archives-prod",
      "arn:aws:s3:::amp-video-archives-prod",
      "arn:aws:s3:::amp-audio-archives-prod-eu",
      "arn:aws:s3:::amp-video-archives-prod-eu",
      "arn:aws:s3:::amp-photo-archives-prod-eu",
    ]

    actions = [
      "s3:GetObjectMetadata",
      "s3:GetAccessPoint",
      "s3:GetAccountPublicAccessBlock",
      "s3:ListAllMyBuckets",
      "s3:ListAccessPoints",
      "s3:ListJobs",
      "s3:HeadBucket",
    ]
  }

  statement {
    sid    = "VisualEditor5"
    effect = "Allow"

    resources = [
      "arn:aws:sqs:us-east-1:554998489284:metadata-extract-status-sqs-prod",
      "arn:aws:sqs:us-east-1:554998489284:amp-asset-copy-request-sqs-prod",
      "arn:aws:sqs:us-east-1:554998489284:amp-asset-copy-status-sqs-prod",
    ]

    actions = ["sqs:ListQueues"]
  }
}

data "aws_iam_policy_document" "PostgreSQL-Credentials-Rotation-Policy" {
  # checkov:skip=CKV_AWS_108: Ensure IAM policies does not allow data exfiltration
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"
    resources = [
      "arn:aws:kms:eu-central-1:${var.account_id}:key/f3f00387-1ce2-4e0b-8528-dfcb0a8a56c0",
      "arn:aws:kms:eu-central-1:${var.account_id}:key/9606e4c2-e780-40f3-9dbb-265dd73f4491",
    ]

    actions = [
      "kms:Decrypt",
      "kms:Encrypt",
      "kms:GenerateDataKey",
    ]

    condition {
      test     = "StringEquals"
      variable = "kms:ViaService"
      values   = ["secretsmanager.eu-central-1.amazonaws.com"]
    }
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "secretsmanager:UntagResource",
      "secretsmanager:DescribeSecret",
      "secretsmanager:PutSecretValue",
      "secretsmanager:CreateSecret",
      "secretsmanager:DeleteSecret",
      "secretsmanager:ListSecretVersionIds",
      "ses:SendEmail",
      "secretsmanager:GetRandomPassword",
      "logs:CreateLogStream",
      "ses:SendTemplatedEmail",
      "secretsmanager:GetSecretValue",
      "ec2:DescribeNetworkInterfaces",
      "secretsmanager:RestoreSecret",
      "secretsmanager:RotateSecret",
      "ec2:UnassignPrivateIpAddresses",
      "ses:SendRawEmail",
      "ec2:DeleteNetworkInterface",
      "secretsmanager:CancelRotateSecret",
      "ec2:AssignPrivateIpAddresses",
      "logs:CreateLogGroup",
      "logs:PutLogEvents",
      "secretsmanager:UpdateSecret",
      "ec2:CreateNetworkInterface",
      "secretsmanager:GetResourcePolicy",
      "ses:SendBulkTemplatedEmail",
      "secretsmanager:UpdateSecretVersionStage",
      "ses:SendBulkEmail",
      "secretsmanager:ListSecrets",
      "secretsmanager:TagResource",
    ]
  }
}

data "aws_iam_policy_document" "aomap-secrets-manager-policy" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/AOMA/aoma_db-SUecRH",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/AOMA/gras_db-yhVQC5",
    ]

    actions = [
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
    ]
  }
}

data "aws_iam_policy_document" "aomap-ameba-kafkahq-monitor-ecs-task-policy" {
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]
    actions   = ["logs:*"]
  }
}

data "aws_iam_policy_document" "acm-export-cert-policy" {
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "acm:DescribeCertificate",
      "acm:ListCertificates",
      "acm:GetCertificate",
      "acm:ListTagsForCertificate",
      "acm:ExportCertificate",
    ]
  }
}

data "aws_iam_policy_document" "corep-trendmicro_esdomain_policy" {
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["arn:aws:es:us-east-1:991283851267:domain/trend-micro-logs/*"]

    actions = [
      "es:ESHttpGet",
      "es:ESHttpHead",
      "es:ESHttpPost",
      "es:ESHttpPut",
      "es:ESHttpPatch",
      "es:Describe*",
      "es:List*",
      "es:AddTags",
    ]
  }
}

data "aws_iam_policy_document" "waf" {
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "waf:ListByteMatchSets",
      "waf:ListWebACLs",
      "wafv2:ListRuleGroups",
      "wafv2:ListWebACLs",
      "waf-regional:ListLoggingConfigurations",
      "waf:ListRateBasedRules",
      "wafv2:ListLoggingConfigurations",
      "wafv2:ListIPSets",
      "wafv2:ListAvailableManagedRuleGroups",
      "wafv2:ListRegexPatternSets",
      "waf:ListActivatedRulesInRuleGroup",
      "waf-regional:ListRateBasedRules",
      "wafv2:DescribeManagedRuleGroup",
      "waf-regional:ListResourcesForWebACL",
      "waf-regional:ListRegexMatchSets",
      "waf-regional:ListRuleGroups",
      "wafv2:ListResourcesForWebACL",
      "waf:ListSubscribedRuleGroups",
      "waf:ListRegexMatchSets",
      "waf-regional:ListWebACLs",
      "waf:ListIPSets",
      "waf:ListSqlInjectionMatchSets",
      "waf-regional:ListRegexPatternSets",
      "waf:ListRuleGroups",
      "waf-regional:ListSizeConstraintSets",
      "waf-regional:ListIPSets",
      "waf-regional:ListByteMatchSets",
      "waf-regional:ListGeoMatchSets",
      "waf:ListSizeConstraintSets",
      "waf-regional:ListActivatedRulesInRuleGroup",
      "waf-regional:ListRules",
      "waf:ListLoggingConfigurations",
      "waf:ListXssMatchSets",
      "waf:ListGeoMatchSets",
      "waf:ListRules",
      "waf-regional:ListSubscribedRuleGroups",
      "waf:ListRegexPatternSets",
      "waf-regional:ListSqlInjectionMatchSets",
      "waf-regional:ListXssMatchSets",
    ]
  }
}

data "aws_iam_policy_document" "aomap-eks-ameba-prod-ns-ameba-sa-mb-policy" {
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]
    actions   = ["acm:ExportCertificate"]
  }

  statement {
    sid       = "VisualEditor4"
    effect    = "Allow"
    resources = ["arn:aws:kms:eu-central-1:${var.account_id}:key/f3f00387-1ce2-4e0b-8528-dfcb0a8a56c0"]
    actions   = ["kms:Decrypt"]
  }

  statement {
    sid       = "VisualEditor5"
    effect    = "Allow"
    resources = ["arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/ms_msg_brdg_srvc-tqAlDa"]
    actions = [
      "secretsmanager:ListSecretVersionIds",
      "secretsmanager:GetSecretValue",
      "secretsmanager:GetResourcePolicy",
      "secretsmanager:DescribeSecret"
    ]
  }
}

data "aws_iam_policy_document" "aomap-eks-aomap-ms-sa-product-graphql-service" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAQcNotesNotificationQueue",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAApprovalNotificationQueue",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/aoma3/gps-lHL8qV",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/ms_product_graphql_srvc-*",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMADownloadAssetNotification",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMADownloadAssetNotificationDLQ",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAProductApprovalNotification",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAProductApprovalNotificationDLQ",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAEmailNotification",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAEmailNotificationDLQ",
      "arn:aws:sqs:eu-central-1:${var.account_id}:ust-prod-assetupload-sqs",
      "arn:aws:sqs:eu-central-1:${var.account_id}:ust-prod-assetupload-sqs-DLQ",
      "arn:aws:kms:eu-central-1:${var.account_id}:key/f3f00387-1ce2-4e0b-8528-dfcb0a8a56c0"
    ]

    actions = [
      "sqs:*",
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecretVersionIds",
      "secretsmanager:GetResourcePolicy",
      "secretsmanager:GetSecretValue",
      "kms:Decrypt"
    ]
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "secretsmanager:GetRandomPassword",
      "sqs:ListQueues",
      "secretsmanager:ListSecrets",
    ]
  }

  statement {
    sid    = "VisualEditor2"
    effect = "Allow"
    resources = [
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/link-attempts",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ameba-events",
      "arn:aws:kafka:eu-central-1:${var.account_id}:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/update-legacy-search",
      "arn:aws:kafka:eu-central-1:613871678587:group/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/aoma3.pgs.*",
      "arn:aws:kafka:eu-central-1:613871678587:cluster/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3",
    ]

    actions = [
      "kafka-cluster:WriteDataIdempotently",
      "kafka-cluster:WriteData",
      "kafka-cluster:ReadData",
      "kafka-cluster:DescribeTopicDynamicConfiguration",
      "kafka-cluster:DescribeTopic",
      "kafka-cluster:DescribeGroup",
      "kafka-cluster:DescribeClusterDynamicConfiguration",
      "kafka-cluster:DescribeCluster",
      "kafka-cluster:Connect",
      "kafka-cluster:AlterGroup",
    ]
  }

  statement {
    sid    = ""
    effect = "Allow"

    resources = [
      "arn:aws:s3:::amp-asset-repo-amb-0001-p/*",
      "arn:aws:s3:::amp-asset-repo-amb-0001-p",
      "arn:aws:s3:::amp-asset-repo-aud-0001-p/*",
      "arn:aws:s3:::amp-asset-repo-aud-0001-p",
      "arn:aws:s3:::amp-asset-repo-aud-0002-p/*",
      "arn:aws:s3:::amp-asset-repo-aud-0002-p",
      "arn:aws:s3:::amp-asset-repo-aud-0003-p/*",
      "arn:aws:s3:::amp-asset-repo-aud-0003-p",
      "arn:aws:s3:::amp-asset-repo-digb-0001-p/*",
      "arn:aws:s3:::amp-asset-repo-digb-0001-p",
      "arn:aws:s3:::amp-asset-repo-doc-0001-p/*",
      "arn:aws:s3:::amp-asset-repo-doc-0001-p",
      "arn:aws:s3:::amp-asset-repo-doc-0002-p/*",
      "arn:aws:s3:::amp-asset-repo-doc-0002-p",
      "arn:aws:s3:::amp-asset-repo-dod-0001-p/*",
      "arn:aws:s3:::amp-asset-repo-dod-0001-p",
      "arn:aws:s3:::amp-asset-repo-dvdddp-0001-p/*",
      "arn:aws:s3:::amp-asset-repo-dvdddp-0001-p",
      "arn:aws:s3:::amp-asset-repo-gra-0001-p/*",
      "arn:aws:s3:::amp-asset-repo-gra-0001-p",
      "arn:aws:s3:::amp-asset-repo-gra-0002-p/*",
      "arn:aws:s3:::amp-asset-repo-gra-0002-p",
      "arn:aws:s3:::amp-asset-repo-lfv-0001-p/*",
      "arn:aws:s3:::amp-asset-repo-lfv-0001-p",
      "arn:aws:s3:::amp-asset-repo-lfv-0002-p/*",
      "arn:aws:s3:::amp-asset-repo-lfv-0002-p",
      "arn:aws:s3:::amp-asset-repo-packg-0001-p/*",
      "arn:aws:s3:::amp-asset-repo-packg-0001-p",
      "arn:aws:s3:::amp-asset-repo-vid-0001-p/*",
      "arn:aws:s3:::amp-asset-repo-vid-0001-p",
      "arn:aws:s3:::amp-asset-repo-vid-0002-p/*",
      "arn:aws:s3:::amp-asset-repo-vid-0002-p",
      "arn:aws:s3:::amp-asset-repo-vid-0003-p/*",
      "arn:aws:s3:::amp-asset-repo-vid-0003-p",
      "arn:aws:s3:::amp-asset-repo-vid-0004-p/*",
      "arn:aws:s3:::amp-asset-repo-vid-0004-p",
      "arn:aws:s3:::amp-asset-repo-vid-0005-p/*",
      "arn:aws:s3:::amp-asset-repo-vid-0005-p",
      "arn:aws:s3:::amp-asset-repo-vid-0006-p/*",
      "arn:aws:s3:::amp-asset-repo-vid-0006-p",
      "arn:aws:s3:::amp-asset-repo-vid-0007-p/*",
      "arn:aws:s3:::amp-asset-repo-vid-0007-p",
      "arn:aws:s3:::amp-asset-repo-vid-0008-p/*",
      "arn:aws:s3:::amp-asset-repo-vid-0008-p",
      "arn:aws:s3:::amp-asset-repo-vid-0009-p/*",
      "arn:aws:s3:::amp-asset-repo-vid-0009-p",
      "arn:aws:s3:::amp-asset-repo-vid-0010-p/*",
      "arn:aws:s3:::amp-asset-repo-vid-0010-p",
      "arn:aws:s3:::amp-asset-repo-vid-0011-p/*",
      "arn:aws:s3:::amp-asset-repo-vid-0011-p",
      "arn:aws:s3:::amp-asset-repo-vid-0012-p/*",
      "arn:aws:s3:::amp-asset-repo-vid-0012-p",
      "arn:aws:s3:::amp-asset-repo-vid-0013-p/*",
      "arn:aws:s3:::amp-asset-repo-vid-0013-p",
    ]

    actions = [
      "s3:ListBucket",
      "s3:GetObject",
    ]
  }

}

data "aws_iam_policy_document" "aomap-jenkins-s3-policy" {
  # checkov:skip=CKV_AWS_109: Ensure IAM policies does not allow permissions management / resource exposure without constraints
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "s3:ListStorageLensConfigurations",
      "s3:ListAccessPointsForObjectLambda",
      "s3:GetAccessPoint",
      "s3:PutAccountPublicAccessBlock",
      "s3:GetAccountPublicAccessBlock",
      "s3:ListAllMyBuckets",
      "s3:ListAccessPoints",
      "s3:ListJobs",
      "s3:PutStorageLensConfiguration",
      "s3:ListMultiRegionAccessPoints",
      "s3:CreateJob",
      "sqs:*",
      "kms:*"
    ]
  }

  statement {
    sid    = "VisualEditor1"
    effect = "Allow"

    resources = [
      "arn:aws:s3:::sme-aoma-core-prod-db-team-lambda",
      "arn:aws:s3:::sme-aoma-core-prod-db-team-lambda/*",
      "arn:aws:s3:::aoma-envelope-frontend-prod-ui",
      "arn:aws:s3:::aoma-envelope-frontend-prod-ui/*",
    ]

    actions = ["s3:*"]
  }

  statement {
    sid    = "VisualEditor2"
    effect = "Allow"

    resources = [
      "arn:aws:s3:::sme-aoma-ust-dev",
      "arn:aws:s3:::sme-aoma-ust-dev/*",
      "arn:aws:s3:::file-logo-bucket",
      "arn:aws:s3:::file-logo-bucket/*",
    ]

    actions = ["s3:*"]
  }

  statement {
    sid    = "VisualEditor3"
    effect = "Allow"
    resources = [
      "arn:aws:cloudfront::${var.account_id}:distribution/EOVQLWT99T1G5"
    ]
    actions = ["cloudfront:*"]
  }
}

data "aws_iam_policy_document" "corep-aws-config-policy" {
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["arn:aws:s3:::sme-aoma-core-prod-awsconfig/*"]
    actions   = ["s3:PutObject*"]

    condition {
      test     = "StringLike"
      variable = "s3:x-amz-acl"
      values   = ["bucket-owner-full-control"]
    }
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["arn:aws:s3:::sme-aoma-core-prod-awsconfig"]
    actions   = ["s3:GetBucketAcl"]
  }
}

data "aws_iam_policy_document" "ALBIngressControllerIAMPolicy" {
  # checkov:skip=CKV_AWS_109: Ensure IAM policies does not allow permissions management / resource exposure without constraints
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "acm:DescribeCertificate",
      "acm:ListCertificates",
      "acm:GetCertificate",
    ]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "ec2:AuthorizeSecurityGroupIngress",
      "ec2:CreateSecurityGroup",
      "ec2:CreateTags",
      "ec2:DeleteTags",
      "ec2:DeleteSecurityGroup",
      "ec2:DescribeAccountAttributes",
      "ec2:DescribeAddresses",
      "ec2:DescribeInstances",
      "ec2:DescribeInstanceStatus",
      "ec2:DescribeInternetGateways",
      "ec2:DescribeNetworkInterfaces",
      "ec2:DescribeSecurityGroups",
      "ec2:DescribeSubnets",
      "ec2:DescribeTags",
      "ec2:DescribeVpcs",
      "ec2:ModifyInstanceAttribute",
      "ec2:ModifyNetworkInterfaceAttribute",
      "ec2:RevokeSecurityGroupIngress",
    ]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "elasticloadbalancing:AddListenerCertificates",
      "elasticloadbalancing:AddTags",
      "elasticloadbalancing:CreateListener",
      "elasticloadbalancing:CreateLoadBalancer",
      "elasticloadbalancing:CreateRule",
      "elasticloadbalancing:CreateTargetGroup",
      "elasticloadbalancing:DeleteListener",
      "elasticloadbalancing:DeleteLoadBalancer",
      "elasticloadbalancing:DeleteRule",
      "elasticloadbalancing:DeleteTargetGroup",
      "elasticloadbalancing:DeregisterTargets",
      "elasticloadbalancing:DescribeListenerCertificates",
      "elasticloadbalancing:DescribeListeners",
      "elasticloadbalancing:DescribeLoadBalancers",
      "elasticloadbalancing:DescribeLoadBalancerAttributes",
      "elasticloadbalancing:DescribeRules",
      "elasticloadbalancing:DescribeSSLPolicies",
      "elasticloadbalancing:DescribeTags",
      "elasticloadbalancing:DescribeTargetGroups",
      "elasticloadbalancing:DescribeTargetGroupAttributes",
      "elasticloadbalancing:DescribeTargetHealth",
      "elasticloadbalancing:ModifyListener",
      "elasticloadbalancing:ModifyLoadBalancerAttributes",
      "elasticloadbalancing:ModifyRule",
      "elasticloadbalancing:ModifyTargetGroup",
      "elasticloadbalancing:ModifyTargetGroupAttributes",
      "elasticloadbalancing:RegisterTargets",
      "elasticloadbalancing:RemoveListenerCertificates",
      "elasticloadbalancing:RemoveTags",
      "elasticloadbalancing:SetIpAddressType",
      "elasticloadbalancing:SetSecurityGroups",
      "elasticloadbalancing:SetSubnets",
      "elasticloadbalancing:SetWebAcl",
    ]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "iam:CreateServiceLinkedRole",
      "iam:GetServerCertificate",
      "iam:ListServerCertificates",
    ]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]
    actions   = ["cognito-idp:DescribeUserPoolClient"]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "waf-regional:GetWebACLForResource",
      "waf-regional:GetWebACL",
      "waf-regional:AssociateWebACL",
      "waf-regional:DisassociateWebACL",
    ]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "tag:GetResources",
      "tag:TagResources",
    ]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]
    actions   = ["waf:GetWebACL"]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "wafv2:GetWebACL",
      "wafv2:GetWebACLForResource",
      "wafv2:AssociateWebACL",
      "wafv2:DisassociateWebACL",
    ]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "shield:DescribeProtection",
      "shield:GetSubscriptionState",
      "shield:DeleteProtection",
      "shield:CreateProtection",
      "shield:DescribeSubscription",
      "shield:ListProtections",
    ]
  }
}

data "aws_iam_policy_document" "sme-gen-custom" {
  # checkov:skip=CKV_AWS_107: Ensure IAM policies does not allow credentials exposure
  # checkov:skip=CKV_AWS_108: Ensure IAM policies does not allow data exfiltration
  # checkov:skip=CKV_AWS_109: Ensure IAM policies does not allow permissions management / resource exposure without constraints
  # checkov:skip=CKV_AWS_110: Ensure IAM policies does not allow privilege escalation
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "lambda:CreateFunction",
      "cloudwatch:PutMetricData",
      "rds:*",
      "ec2messages:GetEndpoint",
      "logs:DescribeLogStreams",
      "ds:CreateComputer",
      "ecs:RegisterContainerInstance",
      "ecs:Submit*",
      "ec2messages:GetMessages",
      "config:StartConfigurationRecorder",
      "config:PutDeliveryChannel",
      "ecs:Poll",
      "logs:CreateLogStream",
      "ec2messages:DeleteMessage",
      "ec2messages:FailMessage",
      "lambda:DeleteFunction",
      "ecs:DeregisterContainerInstance",
      "ecr:BatchCheckLayerAvailability",
      "config:PutConfigurationRecorder",
      "ecs:DiscoverPollEndpoint",
      "logs:DescribeLogGroups",
      "lambda:InvokeFunction",
      "ecs:CreateCluster",
      "config:PutConfigRule",
      "ecr:GetDownloadUrlForLayer",
      "lambda:UpdateFunctionConfiguration",
      "ecr:GetAuthorizationToken",
      "ec2messages:AcknowledgeMessage",
      "config:PutEvaluations",
      "config:StopConfigurationRecorder",
      "config:PutAggregationAuthorization",
      "logs:CreateLogGroup",
      "logs:PutLogEvents",
      "config:StartConfigRulesEvaluation",
      "support:*",
      "lambda:UpdateFunctionCode",
      "lambda:AddPermission",
      "ecs:StartTelemetrySession",
      "config:PutConfigurationAggregator",
      "ssm:*",
      "ecr:BatchGetImage",
      "config:PutRetentionConfiguration",
      "ec2:*",
      "ds:DescribeDirectories",
      "ec2messages:SendReply",
      "lambda:PublishVersion",
      "ce:*",
    ]
  }
}

data "aws_iam_policy_document" "OrderHistoryCertAccess" {
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["arn:aws:acm:eu-central-1:${var.account_id}:certificate/e113e261-dfd7-461a-991f-d08e6e34efe5"]

    actions = [
      "acm:ExportCertificate",
      "acm:DescribeCertificate",
      "acm:GetCertificate",
      "acm:ImportCertificate",
    ]
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "acm:ListCertificates",
      "acm:ListTagsForCertificate",
    ]
  }

  statement {
    sid       = "VisualEditor2"
    effect    = "Allow"
    resources = ["arn:aws:acm:eu-central-1:${var.account_id}:certificate/e113e261-dfd7-461a-991f-d08e6e34efe5"]
    actions   = ["acm:ListTagsForCertificate"]
  }
}


data "aws_iam_policy_document" "aomap-eks-ameba-prod-ns-ameba-private-sa-agql-policy" {
  statement {
    sid       = "VisualEditor2"
    effect    = "Allow"
    resources = ["arn:aws:sqs:eu-central-1:613871678587:AOMAEmailNotification"]
    actions   = ["sqs:*"]
  }

  statement {
    sid       = "VisualEditor3"
    effect    = "Allow"
    resources = ["arn:aws:kms:eu-central-1:613871678587:key/5d51d0ad-aa91-465c-8abb-86b5770bf97b"]
    actions   = ["kms:*"]
  }

  statement {
    sid       = "VisualEditor4"
    effect    = "Allow"
    resources = ["arn:aws:kms:eu-central-1:${var.account_id}:key/f3f00387-1ce2-4e0b-8528-dfcb0a8a56c0"]
    actions   = ["kms:Decrypt"]
  }

  statement {
    sid       = "VisualEditor5"
    effect    = "Allow"
    resources = ["arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/ameba_graphql-9I06AP"]
    actions = [
      "secretsmanager:ListSecretVersionIds",
      "secretsmanager:GetSecretValue",
      "secretsmanager:GetResourcePolicy",
      "secretsmanager:DescribeSecret"
    ]
  }

}

data "aws_iam_policy_document" "GSIRT_AWS_Monitoring_Role-DescribePolicy" {
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "sqs:GetQueueAttributes",
      "sqs:ListQueues",
      "sqs:GetQueueUrl",
      "s3:ListBucket",
      "s3:GetBucketLocation",
      "s3:ListAllMyBuckets",
      "s3:GetBucketTagging",
      "s3:GetAccelerateConfiguration",
      "s3:GetBucketLogging",
      "s3:GetLifecycleConfiguration",
      "s3:GetBucketCORS",
      "config:DeliverConfigSnapshot",
      "config:DescribeConfigRules",
      "config:DescribeConfigRuleEvaluationStatus",
      "config:GetComplianceDetailsByConfigRule",
      "config:GetComplianceSummaryByConfigRule",
      "iam:GetUser",
      "iam:ListUsers",
      "iam:GetAccountPasswordPolicy",
      "iam:ListAccessKeys",
      "iam:GetAccessKeyLastUsed",
      "autoscaling:Describe*",
      "cloudwatch:Describe*",
      "cloudwatch:Get*",
      "cloudwatch:List*",
      "sns:Get*",
      "sns:List*",
      "logs:DescribeLogGroups",
      "logs:DescribeLogStreams",
      "logs:GetLogEvents",
      "ec2:DescribeInstances",
      "ec2:DescribeReservedInstances",
      "ec2:DescribeSnapshots",
      "ec2:DescribeRegions",
      "ec2:DescribeKeyPairs",
      "ec2:DescribeNetworkAcls",
      "ec2:DescribeSecurityGroups",
      "ec2:DescribeSubnets",
      "ec2:DescribeVolumes",
      "ec2:DescribeVpcs",
      "ec2:DescribeImages",
      "ec2:DescribeAddresses",
      "lambda:ListFunctions",
      "rds:DescribeDBInstances",
      "cloudfront:ListDistributions",
      "elasticloadbalancing:DescribeLoadBalancers",
      "elasticloadbalancing:DescribeInstanceHealth",
      "elasticloadbalancing:DescribeTags",
      "elasticloadbalancing:DescribeTargetGroups",
      "elasticloadbalancing:DescribeTargetHealth",
      "elasticloadbalancing:DescribeListeners",
      "inspector:Describe*",
      "inspector:List*",
      "kinesis:DescribeStream",
      "kinesis:ListStreams",
      "eks:ListAddons",
      "eks:DescribeAddon",
      "eks:ListIdentityProviderConfigs",
      "eks:DescribeIdentityProviderConfig",
      "eks:DescribeAddonVersions",
      "eks:DescribeUpdate",
      "eks:ListTagsForResource",
      "network-firewall:ListTagsForResource",
      "logs:ListLogDeliveries",
      "logs:GetLogDelivery"
    ]
  }
}

data "aws_iam_policy_document" "CWLogs-Put" {
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]
    actions   = ["logs:PutLogEvents"]
  }
}

data "aws_iam_policy_document" "aomap-ECS-Instance-Policy" {
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["arn:aws:sqs:eu-central-1:${var.account_id}:ust-bulkRegistration-sqs-prod"]
    actions   = ["sqs:*"]
  }
}

data "aws_iam_policy_document" "aomap-txmgr-gdsp-msk-access-Policy" {
  statement {
    sid    = ""
    effect = "Allow"
    resources = [
      "arn:aws:iam::635220336377:role/globaldsp-aoma-txmgr-role"
    ]
    actions = [
      "sts:AssumeRole"
    ]
  }
}

data "aws_iam_policy_document" "DMS-Policy" {
  # checkov:skip=CKV_AWS_108: Ensure IAM policies does not allow data exfiltration
  # checkov:skip=CKV_AWS_109: Ensure IAM policies does not allow permissions management / resource exposure without constraints
  # checkov:skip=CKV_AWS_110: Ensure IAM policies does not allow privilege escalation
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "mgh:ListMigrationTasks",
      "mgh:GetHomeRegion",
      "dms:*",
      "sqs:*",
      "lambda:*",
      "docdb-elastic:GetCluster",
      "docdb-elastic:ListClusters",
      "docdb-elastic:ListClusterSnapshots",
      "docdb-elastic:ListTagsForResource",
      "glue:BatchCreatePartition",
      "athena:StartQueryExecution",
      "glue:CreateClassifier",
      "glue:UpdateTable",
      "athena:GetQueryResults",
      "glue:DeleteTable",
      "athena:UpdateWorkGroup",
      "athena:ListWorkGroups",
      "athena:GetNamedQuery",
      "glue:DeleteWorkflow",
      "glue:UpdateCrawler",
      "glue:UpdateWorkflow",
      "glue:CreateScript",
      "glue:UpdateTrigger",
      "athena:GetExecutionEngine",
      "athena:GetExecutionEngines",
      "glue:StartWorkflowRun",
      "glue:StopCrawlerSchedule",
      "glue:PutResourcePolicy",
      "athena:CreateDataCatalog",
      "sns:*",
      "glue:UpdateDatabase",
      "athena:GetQueryResultsStream",
      "glue:CreateTable",
      "glue:DeleteResourcePolicy",
      "glue:DeleteCrawler",
      "athena:GetNamespace",
      "athena:GetQueryExecutions",
      "glue:BatchStopJobRun",
      "glue:DeleteUserDefinedFunction",
      "glue:CreateConnection",
      "athena:GetCatalogs",
      "athena:CreateWorkGroup",
      "glue:CreateCrawler",
      "athena:ListNamedQueries",
      "glue:DeleteSecurityConfiguration",
      "glue:GetMapping",
      "athena:GetNamespaces",
      "glue:DeleteConnection",
      "athena:CreateNamedQuery",
      "glue:UseMLTransforms",
      "glue:BatchDeleteConnection",
      "glue:StartCrawlerSchedule",
      "glue:StartJobRun",
      "glue:BatchDeleteTable",
      "glue:UpdateMLTransform",
      "athena:GetTables",
      "athena:GetTable",
      "glue:UpdateClassifier",
      "athena:BatchGetNamedQuery",
      "glue:CreateWorkflow",
      "glue:DeletePartition",
      "athena:BatchGetQueryExecution",
      "glue:CreateMLTransform",
      "athena:UpdateDataCatalog",
      "glue:CreateSecurityConfiguration",
      "glue:PutWorkflowRunProperties",
      "glue:DeleteDatabase",
      "glue:StartMLEvaluationTaskRun",
      "glue:CreateTrigger",
      "glue:BatchDeletePartition",
      "glue:StopTrigger",
      "glue:CreateUserDefinedFunction",
      "glue:StopCrawler",
      "athena:GetDatabase",
      "athena:GetDataCatalog",
      "glue:*",
      "athena:ListQueryExecutions",
      "glue:StartTrigger",
      "glue:DeleteDevEndpoint",
      "glue:DeleteMLTransform",
      "glue:CreateJob",
      "glue:ImportCatalogToGlue",
      "athena:GetWorkGroup",
      "glue:PutDataCatalogEncryptionSettings",
      "glue:StartCrawler",
      "kms:*",
      "glue:ResetJobBookmark",
      "glue:UpdateJob",
      "glue:CreatePartition",
      "glue:UpdatePartition",
      "glue:StartImportLabelsTaskRun",
      "glue:DeleteClassifier",
      "glue:StartExportLabelsTaskRun",
      "glue:UpdateUserDefinedFunction",
      "glue:CancelMLTaskRun",
      "glue:GetDatabases",
      "glue:StartMLLabelingSetGenerationTaskRun",
      "glue:GetDatabase",
      "glue:UpdateCrawlerSchedule",
      "glue:UpdateConnection",
      "glue:CreateDatabase",
      "glue:CreateDevEndpoint",
      "glue:UpdateDevEndpoint",
      "athena:GetQueryExecution",
      "glue:DeleteTrigger",
      "iam:PassRole",
      "iam:ListRoles",
      "quicksight:*",
    ]
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["arn:aws:mgh:*:*:progressUpdateStream/DMS"]
    actions   = ["mgh:CreateProgressUpdateStream"]
  }

  statement {
    sid       = "VisualEditor2"
    effect    = "Allow"
    resources = ["arn:aws:mgh:*:*:progressUpdateStream/DMS/*"]

    actions = [
      "mgh:DescribeMigrationTask",
      "mgh:AssociateDiscoveredResource",
      "mgh:ListDiscoveredResources",
      "mgh:ImportMigrationTask",
      "mgh:ListCreatedArtifacts",
      "mgh:DisassociateDiscoveredResource",
      "mgh:AssociateCreatedArtifact",
      "mgh:NotifyMigrationTaskState",
      "mgh:DisassociateCreatedArtifact",
      "mgh:PutResourceAttributes",
    ]
  }

  statement {
    sid       = "VisualEditor3"
    effect    = "Allow"
    resources = ["arn:aws:mgh:*:*:progressUpdateStream/DMS/*"]

    actions = [
      "mgh:NotifyApplicationState",
      "mgh:DescribeApplicationState",
    ]
  }

  statement {
    sid    = ""
    effect = "Allow"

    resources = [
      "arn:aws:es:*:*:domain/*/",
      "arn:aws:es:*:*:domain/*/_cluster/settings",
      "arn:aws:es:*:*:domain/*/_cat/indices",
    ]

    actions = ["es:ESHttpGet"]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]
    actions   = ["es:ListDomainNames"]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["arn:aws:es:*:*:domain/*"]
    actions   = ["es:DescribeElasticsearchDomain"]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["arn:aws:es:*:*:domain/*/_opendistro/_sql"]

    actions = [
      "es:ESHttpPost",
      "es:ESHttpGet",
    ]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "timestream:Select",
      "timestream:CancelQuery",
      "timestream:ListTables",
      "timestream:ListDatabases",
      "timestream:ListMeasures",
      "timestream:DescribeTable",
      "timestream:DescribeDatabase",
      "timestream:SelectValues",
      "timestream:DescribeEndpoints",
    ]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "iotanalytics:ListDatasets",
      "iotanalytics:DescribeDataset",
      "iotanalytics:GetDatasetContent",
    ]
  }

  statement {
    sid    = ""
    effect = "Allow"

    resources = [
      "arn:aws:es:*:*:domain/*/",
      "arn:aws:es:*:*:domain/*/_cluster/settings",
      "arn:aws:es:*:*:domain/*/_cat/indices",
    ]

    actions = ["es:ESHttpGet"]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]
    actions   = ["es:ListDomainNames"]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["arn:aws:es:*:*:domain/*"]
    actions   = ["es:DescribeElasticsearchDomain"]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["arn:aws:es:*:*:domain/*/_opendistro/_sql"]

    actions = [
      "es:ESHttpPost",
      "es:ESHttpGet",
    ]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["arn:aws:sagemaker:*:*:transform-job/quicksight-auto-generated-*"]

    actions = [
      "sagemaker:DescribeTransformJob",
      "sagemaker:StopTransformJob",
      "sagemaker:CreateTransformJob",
    ]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]
    actions   = ["sagemaker:ListModels"]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["arn:aws:s3:::quicksight-ml.*"]
    actions   = ["s3:GetObject"]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["arn:aws:s3:::s3-analytics-export-shared-*"]
    actions   = ["s3:GetObject"]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "s3:Get*",
      "s3:List*",
      "s3:Put*",
    ]
  }

  statement {
    sid    = ""
    effect = "Allow"

    actions = [
      "s3:PutObject*",
      "s3:ListBucket",
      "s3:GetObject*",
      "s3:GetBucketLocation",
      "s3:DeleteObject*"
    ]

    resources = [
      "arn:aws:s3:::sme-media-conversion-prod-rds-backups",
      "arn:aws:s3:::sme-media-conversion-prod-rds-backups/*",
      "arn:aws:s3:::sme-media-conversion-prod-lambda-archived",
      "arn:aws:s3:::sme-media-conversion-prod-lambda-archived/*",
    ]
  }
}

data "aws_iam_policy_document" "aomap-ecs-aomap1-mdimport-taskdef-task-policy" {
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]
    actions   = ["logs:*"]
  }
}

data "aws_iam_policy_document" "aomap-secrets-manager-access-policy" {
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/aoma/cloudopsses-iUt75c"]

    actions = [
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecretVersionIds",
      "secretsmanager:GetResourcePolicy",
      "secretsmanager:GetSecretValue",
    ]
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "secretsmanager:ListSecrets",
      "ses:SendEmail",
      "ses:SendRawEmail",
    ]
  }
}

data "aws_iam_policy_document" "KMS-Policy" {
  # checkov:skip=CKV_AWS_109: Ensure IAM policies does not allow permissions management / resource exposure without constraints
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]
    actions   = ["kms:*"]
  }
}

data "aws_iam_policy_document" "aomap-cloudops_ses-key-rotation-function-policy" {
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "organizations:ListPoliciesForTarget",
      "organizations:ListRoots",
      "organizations:ListTargetsForPolicy",
      "ec2:DetachNetworkInterface",
      "ec2:DeleteNetworkInterface",
      "organizations:DescribeAccount",
      "logs:CreateLogGroup",
      "logs:PutLogEvents",
      "organizations:DescribePolicy",
      "organizations:ListChildren",
      "organizations:ListPolicies",
      "ec2:CreateNetworkInterface",
      "secretsmanager:GetRandomPassword",
      "logs:CreateLogStream",
      "organizations:DescribeOrganization",
      "ec2:DescribeNetworkInterfaces",
      "organizations:DescribeOrganizationalUnit",
      "organizations:ListParents",
    ]
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:*"]

    actions = [
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "secretsmanager:PutSecretValue",
      "secretsmanager:UpdateSecretVersionStage",
    ]

    condition {
      test     = "StringEquals"
      variable = "secretsmanager:resource/AllowRotationLambdaArn"
      values   = ["arn:aws:lambda:eu-central-1:${var.account_id}:function:aomap-cloudops_ses-key-rotation-function"]
    }
  }

  statement {
    sid       = "VisualEditor2"
    effect    = "Allow"
    resources = ["arn:aws:iam::476717493283:role/ccshr-aoma-ses2-key-rotation-role"]
    actions   = ["sts:AssumeRole"]
  }

  statement {
    sid       = "VisualEditor3"
    effect    = "Allow"
    resources = ["arn:aws:lambda:eu-central-1:613871678587:function:amino-assets-jobs-stuck-monitor"]
    actions = [
      "lambda:List*",
      "lambda:Get*",
      "lambda:UpdateFunctionCode"

    ]
  }
}

data "aws_iam_policy_document" "aomap-kibana-ameba-sns-notification" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:sns:eu-central-1:613871678587:txmgr-developers",
      "arn:aws:sns:eu-central-1:613871678587:atf-developers",
      "arn:aws:sns:eu-central-1:613871678587:DB-TEAM",
      "arn:aws:sns:eu-central-1:613871678587:metadata-import-support-email"
    ]

    actions = ["sns:Publish"]
  }
}

data "aws_iam_policy_document" "sme-aoma-core-prod-email-notification-attachment-s3-policy" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:s3:::sme-aoma-core-prod-email-notification-attachment",
      "arn:aws:s3:::sme-aoma-core-prod-email-notification-attachment/*",
    ]

    actions = [
      "s3:PutAnalyticsConfiguration",
      "s3:PutAccessPointConfigurationForObjectLambda",
      "s3:GetObjectVersionTagging",
      "s3:DeleteAccessPoint",
      "s3:CreateBucket",
      "s3:DeleteAccessPointForObjectLambda",
      "s3:GetStorageLensConfigurationTagging",
      "s3:ReplicateObject",
      "s3:GetObjectAcl",
      "s3:GetBucketObjectLockConfiguration",
      "s3:DeleteBucketWebsite",
      "s3:GetIntelligentTieringConfiguration",
      "s3:PutLifecycleConfiguration",
      "s3:GetObjectVersionAcl",
      "s3:DeleteObject",
      "s3:GetBucketPolicyStatus",
      "s3:GetObjectRetention",
      "s3:GetBucketWebsite",
      "s3:GetJobTagging",
      "s3:PutReplicationConfiguration",
      "s3:PutObjectLegalHold",
      "s3:GetObjectLegalHold",
      "s3:GetBucketNotification",
      "s3:PutBucketCORS",
      "s3:GetReplicationConfiguration",
      "s3:PutObject",
      "s3:GetObject",
      "s3:PutBucketNotification",
      "s3:DescribeJob",
      "s3:PutBucketLogging",
      "s3:GetAnalyticsConfiguration",
      "s3:PutBucketObjectLockConfiguration",
      "s3:GetObjectVersionForReplication",
      "s3:GetAccessPointForObjectLambda",
      "s3:GetStorageLensDashboard",
      "s3:CreateAccessPoint",
      "s3:GetLifecycleConfiguration",
      "s3:GetInventoryConfiguration",
      "s3:GetBucketTagging",
      "s3:PutAccelerateConfiguration",
      "s3:GetAccessPointPolicyForObjectLambda",
      "s3:DeleteObjectVersion",
      "s3:GetBucketLogging",
      "s3:RestoreObject",
      "s3:GetAccelerateConfiguration",
      "s3:GetBucketPolicy",
      "s3:PutEncryptionConfiguration",
      "s3:GetEncryptionConfiguration",
      "s3:GetObjectVersionTorrent",
      "s3:AbortMultipartUpload",
      "s3:GetBucketRequestPayment",
      "s3:DeleteBucketOwnershipControls",
      "s3:GetAccessPointPolicyStatus",
      "s3:UpdateJobPriority",
      "s3:GetObjectTagging",
      "s3:GetMetricsConfiguration",
      "s3:GetBucketOwnershipControls",
      "s3:DeleteBucket",
      "s3:PutBucketVersioning",
      "s3:GetBucketPublicAccessBlock",
      "s3:PutIntelligentTieringConfiguration",
      "s3:GetAccessPointPolicyStatusForObjectLambda",
      "s3:PutMetricsConfiguration",
      "s3:PutBucketOwnershipControls",
      "s3:UpdateJobStatus",
      "s3:GetBucketVersioning",
      "s3:GetBucketAcl",
      "s3:GetAccessPointConfigurationForObjectLambda",
      "s3:PutInventoryConfiguration",
      "s3:GetObjectTorrent",
      "s3:GetStorageLensConfiguration",
      "s3:DeleteStorageLensConfiguration",
      "s3:PutBucketWebsite",
      "s3:PutBucketRequestPayment",
      "s3:PutObjectRetention",
      "s3:CreateAccessPointForObjectLambda",
      "s3:GetBucketCORS",
      "s3:GetBucketLocation",
      "s3:GetAccessPointPolicy",
      "s3:ReplicateDelete",
      "s3:GetObjectVersion",
    ]
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "s3:ListAccessPointsForObjectLambda",
      "s3:GetAccessPoint",
      "s3:GetAccountPublicAccessBlock",
      "s3:ListAccessPoints",
      "s3:PutStorageLensConfiguration",
      "s3:CreateJob",
    ]
  }
}

data "aws_iam_policy_document" "cloudops-instance-policy" {
  # checkov:skip=CKV_AWS_108: Ensure IAM policies does not allow data exfiltration
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "autoscaling:Describe*",
      "autoscaling:Describe*",
      "cloudtrail:DescribeTrails",
      "cloudtrail:GetEventSelectors",
      "cloudtrail:GetInsightSelectors",
      "cloudtrail:GetTrail",
      "cloudtrail:GetTrailStatus",
      "cloudtrail:ListPublicKeys",
      "cloudtrail:ListTags",
      "cloudtrail:ListTrails",
      "cloudtrail:LookupEvents",
      "cloudwatch:Describe*",
      "cloudwatch:Get*",
      "cloudwatch:GetMetricStatistics",
      "cloudwatch:List*",
      "cloudwatch:ListMetrics",
      "cloudwatch:PutMetricData",
      "ec2:Describe*",
      "ec2:DescribeAccountAttributes",
      "ec2:DescribeAddresses",
      "ec2:DescribeAvailabilityZones",
      "ec2:DescribeClassicLinkInstances",
      "ec2:DescribeCustomerGateways",
      "ec2:DescribeDhcpOptions",
      "ec2:DescribeEgressOnlyInternetGateways",
      "ec2:DescribeFlowLogs",
      "ec2:DescribeInternetGateways",
      "ec2:DescribeMovingAddresses",
      "ec2:DescribeNatGateways",
      "ec2:DescribeNetworkAcls",
      "ec2:DescribeNetworkInterfaceAttribute",
      "ec2:DescribeNetworkInterfacePermissions",
      "ec2:DescribeNetworkInterfaces",
      "ec2:DescribePrefixLists",
      "ec2:DescribeRouteTables",
      "ec2:DescribeSecurityGroupReferences",
      "ec2:DescribeSecurityGroups",
      "ec2:DescribeStaleSecurityGroups",
      "ec2:DescribeSubnets",
      "ec2:DescribeTags",
      "ec2:DescribeVpcAttribute",
      "ec2:DescribeVpcClassicLink",
      "ec2:DescribeVpcClassicLinkDnsSupport",
      "ec2:DescribeVpcEndpointConnectionNotifications",
      "ec2:DescribeVpcEndpointConnections",
      "ec2:DescribeVpcEndpoints",
      "ec2:DescribeVpcEndpointServiceConfigurations",
      "ec2:DescribeVpcEndpointServicePermissions",
      "ec2:DescribeVpcEndpointServices",
      "ec2:DescribeVpcPeeringConnections",
      "ec2:DescribeVpcs",
      "ec2:DescribeVpnConnections",
      "ec2:DescribeVpnGateways",
      "ec2messages:AcknowledgeMessage",
      "ec2messages:DeleteMessage",
      "ec2messages:FailMessage",
      "ec2messages:GetEndpoint",
      "ec2messages:GetMessages",
      "ec2messages:SendReply",
      "elasticloadbalancing:Describe*",
      "kms:ListAliases",
      "lambda:ListFunctions",
      "logs:CreateLogGroup",
      "logs:CreateLogStream",
      "logs:Describe*",
      "logs:DescribeLogGroups",
      "logs:DescribeLogStreams",
      "logs:FilterLogEvents",
      "logs:Get*",
      "logs:GetLogEvents",
      "logs:List*",
      "logs:PutLogEvents",
      "logs:TestMetricFilter",
      "rds:Describe*",
      "rds:ListTagsForResource",
      "s3:Get*",
      "s3:GetBucketLocation",
      "s3:GetObject",
      "s3:List*",
      "s3:ListAllMyBuckets",
      "s3:DeleteObject",
      "sns:Get*",
      "sns:List*",
      "ssm:DescribeAssociation",
      "ssm:DescribeDocument",
      "ssm:GetDeployablePatchSnapshotForInstance",
      "ssm:GetDocument",
      "ssm:GetManifest",
      "ssm:GetParameter",
      "ssm:GetParameters",
      "ssm:ListAssociations",
      "ssm:ListInstanceAssociations",
      "ssmmessages:CreateControlChannel",
      "ssmmessages:CreateDataChannel",
      "ssmmessages:OpenControlChannel",
      "ssmmessages:OpenDataChannel",
      "ssm:PutComplianceItems",
      "ssm:PutConfigurePackageResult",
      "ssm:PutInventory",
      "ssm:UpdateAssociationStatus",
      "ssm:UpdateInstanceAssociationStatus",
      "ssm:UpdateInstanceInformation",
    ]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["arn:aws:ssm:*:*:parameter/AmazonCloudWatch-*"]

    actions = [
      "ssm:GetParameter",
      "ssm:PutParameter",
    ]
  }
}

data "aws_iam_policy_document" "cost-explore-ro" {
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "ce:DescribeCostCategoryDefinition",
      "ce:GetRightsizingRecommendation",
      "ce:GetCostAndUsage",
      "ce:GetSavingsPlansUtilization",
      "ce:GetReservationPurchaseRecommendation",
      "ce:ListCostCategoryDefinitions",
      "ce:GetCostForecast",
      "ce:GetReservationUtilization",
      "ce:GetSavingsPlansPurchaseRecommendation",
      "ce:GetDimensionValues",
      "ce:GetSavingsPlansUtilizationDetails",
      "ce:GetCostAndUsageWithResources",
      "ce:GetReservationCoverage",
      "ce:GetSavingsPlansCoverage",
      "ce:GetTags",
      "ce:GetUsageForecast",
    ]
  }

  statement {
    sid       = "VisualEditor3"
    effect    = "Allow"
    resources = ["arn:aws:lambda:eu-central-1:613871678587:function:amino-assets-jobs-stuck-monitor"]

    actions = [
      "lambda:List*",
      "lambda:Get*",
      "lambda:UpdateFunctionCode"
    ]
  }
}

data "aws_iam_policy_document" "AWSQuickSightRedshiftPolicy" {
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]
    actions   = ["redshift:Describe*"]
  }
}

data "aws_iam_policy_document" "aomap-eks-ameba-prod-ns-ameba-private-sa-gw-policy" {
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]
    actions   = ["acm:ExportCertificate"]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "dynamodb:DescribeContributorInsights",
      "dynamodb:ListTables",
      "dynamodb:RestoreTableToPointInTime",
      "dynamodb:UpdateGlobalTable",
      "dynamodb:DeleteTable",
      "dynamodb:UpdateTableReplicaAutoScaling",
      "dynamodb:DescribeTable",
      "dynamodb:PartiQLInsert",
      "dynamodb:GetItem",
      "dynamodb:DescribeContinuousBackups",
      "dynamodb:DescribeExport",
      "dynamodb:EnableKinesisStreamingDestination",
      "dynamodb:BatchGetItem",
      "dynamodb:DisableKinesisStreamingDestination",
      "dynamodb:UpdateTimeToLive",
      "dynamodb:BatchWriteItem",
      "dynamodb:PutItem",
      "dynamodb:PartiQLUpdate",
      "dynamodb:Scan",
      "dynamodb:UpdateItem",
      "dynamodb:UpdateGlobalTableSettings",
      "dynamodb:CreateTable",
      "dynamodb:GetShardIterator",
      "dynamodb:DescribeReservedCapacity",
      "dynamodb:ExportTableToPointInTime",
      "dynamodb:DescribeBackup",
      "dynamodb:UpdateTable",
      "dynamodb:GetRecords",
      "dynamodb:DescribeTableReplicaAutoScaling",
      "dynamodb:DeleteItem",
      "dynamodb:PurchaseReservedCapacityOfferings",
      "dynamodb:CreateTableReplica",
      "dynamodb:ListTagsOfResource",
      "dynamodb:UpdateContributorInsights",
      "dynamodb:CreateBackup",
      "dynamodb:UpdateContinuousBackups",
      "dynamodb:DescribeReservedCapacityOfferings",
      "dynamodb:PartiQLSelect",
      "dynamodb:CreateGlobalTable",
      "dynamodb:DescribeKinesisStreamingDestination",
      "dynamodb:DescribeLimits",
      "dynamodb:ConditionCheckItem",
      "dynamodb:Query",
      "dynamodb:DescribeStream",
      "dynamodb:DeleteTableReplica",
      "dynamodb:DescribeTimeToLive",
      "dynamodb:ListStreams",
      "dynamodb:DescribeGlobalTableSettings",
      "dynamodb:DescribeGlobalTable",
      "dynamodb:RestoreTableFromBackup",
      "dynamodb:DeleteBackup",
      "dynamodb:PartiQLDelete",
    ]
  }

  statement {
    sid       = "VisualEditor2"
    effect    = "Allow"
    resources = ["arn:aws:kms:eu-central-1:${var.account_id}:key/f3f00387-1ce2-4e0b-8528-dfcb0a8a56c0"]
    actions   = ["kms:Decrypt"]
  }

  statement {
    sid    = "VisualEditor3"
    effect = "Allow"
    resources = ["arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/gateway_app-z4KfVV",
    "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/gateway_app"]
    actions = [
      "secretsmanager:ListSecretVersionIds",
      "secretsmanager:GetSecretValue",
      "secretsmanager:GetResourcePolicy",
      "secretsmanager:DescribeSecret"
    ]
  }
}

data "aws_iam_policy_document" "SendRawEmail" {
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]
    actions   = ["ses:SendRawEmail"]
  }
}

data "aws_iam_policy_document" "AWSLambdaSNSTopicDestinationExecutionRole-7b7093b4-7fe5-431c-a3d6-19223c5df2b4" {
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["arn:aws:sns:eu-central-1:${var.account_id}:DB-TEAM"]
    actions   = ["sns:Publish"]
  }
}

data "aws_iam_policy_document" "aomap-eks-aomap-ms-sa-aoma-data-service" {
  statement {
    sid    = ""
    effect = "Allow"
    resources = ["arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/aoma3/ads-8yJXCz", "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/ms_data_srvc-*", "arn:aws:kms:eu-central-1:${var.account_id}:key/f3f00387-1ce2-4e0b-8528-dfcb0a8a56c0",
    ]

    actions = [
      "secretsmanager:GetResourcePolicy",
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecretVersionIds",
      "secretsmanager:ListSecrets",
      "kms:Decrypt"
    ]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]
    actions   = ["secretsmanager:ListSecrets"]
  }
}

data "aws_iam_policy_document" "AWSQuickSightS3Policy" {
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["arn:aws:s3:::*"]
    actions   = ["s3:ListAllMyBuckets"]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["arn:aws:s3:::sme-aoma-core-prod-quicksight"]
    actions   = ["s3:ListBucket"]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["arn:aws:s3:::sme-aoma-core-prod-quicksight/*"]

    actions = [
      "s3:GetObject",
      "s3:GetObjectVersion",
    ]
  }
}

data "aws_iam_policy_document" "aomap-eks-aomap-ms-sa-user-management-service" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/aoma3/aum-DHYc5P",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/aoma3/*",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/aoma_micro_srv_user_mgmt-*",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AomaUserSecretKeyNotification",
      "arn:aws:kms:eu-central-1:${var.account_id}:key/f3f00387-1ce2-4e0b-8528-dfcb0a8a56c0",

    ]

    actions = [
      "sqs:DeleteMessage",
      "sqs:GetQueueUrl",
      "sqs:ChangeMessageVisibility",
      "secretsmanager:DescribeSecret",
      "sqs:SendMessageBatch",
      "sqs:ReceiveMessage",
      "sqs:SendMessage",
      "sqs:GetQueueAttributes",
      "sqs:ListQueueTags",
      "secretsmanager:ListSecretVersionIds",
      "secretsmanager:GetResourcePolicy",
      "secretsmanager:GetSecretValue",
      "sqs:ListDeadLetterSourceQueues",
      "sqs:DeleteMessageBatch",
      "sqs:PurgeQueue",
      "sqs:ChangeMessageVisibilityBatch",
      "sqs:SetQueueAttributes",
      "kms:Decrypt"
    ]
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "secretsmanager:GetRandomPassword",
      "sqs:ListQueues",
      "secretsmanager:ListSecrets",
    ]
  }
}

data "aws_iam_policy_document" "DatadogAWSIntegrationPolicy" {
  # checkov:skip=CKV_AWS_107: Ensure IAM policies does not allow credentials exposure
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "account:GetAccountInformation",
      "airflow:GetEnvironment",
      "airflow:ListEnvironments",
      "apigateway:GET",
      "appsync:ListGraphqlApis",
      "autoscaling:Describe*",
      "backup:List*",
      "batch:DescribeJobDefinitions",
      "batch:DescribeJobQueues",
      "batch:DescribeJobs",
      "batch:ListJobs",
      "bcm-data-exports:GetExport",
      "bcm-data-exports:ListExports",
      "budgets:ViewBudget",
      "cloudfront:GetDistributionConfig",
      "cloudfront:ListDistributions",
      "cloudtrail:DescribeTrails",
      "cloudtrail:GetTrail",
      "cloudtrail:GetTrailStatus",
      "cloudtrail:ListTrails",
      "cloudtrail:LookupEvents",
      "cloudwatch:Describe*",
      "cloudwatch:Get*",
      "cloudwatch:List*",
      "codebuild:BatchGetProjects",
      "codebuild:ListProjects",
      "codedeploy:BatchGet*",
      "codedeploy:List*",
      "cur:DescribeReportDefinitions",
      "directconnect:Describe*",
      "dms:DescribeReplicationInstances",
      "dynamodb:Describe*",
      "dynamodb:List*",
      "ec2:Describe*",
      "ecs:Describe*",
      "ecs:List*",
      "eks:DescribeCluster",
      "eks:ListClusters",
      "elasticache:Describe*",
      "elasticache:List*",
      "elasticfilesystem:DescribeAccessPoints",
      "elasticfilesystem:DescribeFileSystems",
      "elasticfilesystem:DescribeTags",
      "elasticloadbalancing:Describe*",
      "elasticmapreduce:Describe*",
      "elasticmapreduce:List*",
      "es:DescribeElasticsearchDomains",
      "es:ListDomainNames",
      "es:ListTags",
      "events:CreateEventBus",
      "fsx:DescribeFileSystems",
      "fsx:ListTagsForResource",
      "health:DescribeAffectedEntities",
      "health:DescribeEventDetails",
      "health:DescribeEvents",
      "iam:ListAccountAliases",
      "kinesis:Describe*",
      "kinesis:List*",
      "lambda:List*",
      "logs:DeleteSubscriptionFilter",
      "logs:DescribeDeliveries",
      "logs:DescribeDeliverySources",
      "logs:DescribeLogGroups",
      "logs:DescribeLogStreams",
      "logs:DescribeSubscriptionFilters",
      "logs:FilterLogEvents",
      "logs:GetDeliveryDestination",
      "logs:PutSubscriptionFilter",
      "logs:TestMetricFilter",
      "network-firewall:DescribeLoggingConfiguration",
      "network-firewall:ListFirewalls",
      "oam:ListAttachedLinks",
      "oam:ListSinks",
      "organizations:Describe*",
      "organizations:List*",
      "rds:Describe*",
      "rds:List*",
      "redshift-serverless:ListNamespaces",
      "redshift:DescribeClusters",
      "redshift:DescribeLoggingStatus",
      "route53:List*",
      "route53resolver:ListResolverQueryLogConfigs",
      "s3:GetBucketLocation",
      "s3:GetBucketLogging",
      "s3:GetBucketNotification",
      "s3:GetBucketTagging",
      "s3:ListAllMyBuckets",
      "s3:PutBucketNotification",
      "ses:Get*",
      "ses:List*",
      "sns:GetSubscriptionAttributes",
      "sns:List*",
      "sns:Publish",
      "sqs:ListQueues",
      "ssm:GetServiceSetting",
      "ssm:ListCommands",
      "states:DescribeStateMachine",
      "states:ListStateMachines",
      "sts:AssumeRole",
      "support:DescribeTrustedAdvisor*",
      "support:RefreshTrustedAdvisorCheck",
      "tag:GetResources",
      "tag:GetTagKeys",
      "tag:GetTagValues",
      "timestream:DescribeEndpoints",
      "wafv2:ListLoggingConfigurations",
      "xray:BatchGetTraces",
      "xray:GetTraceSummaries",
    ]
  }
}

data "aws_iam_policy_document" "aomap-eks-ameba-prod-sa-ars-s3-policy" {
  # checkov:skip=CKV_AWS_109: Ensure IAM policies does not allow permissions management / resource exposure without constraints
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:s3:::sme-aoma-core-prod-aoma-reports-prod/*",
      "arn:aws:s3:::sme-aoma-core-prod-aoma-reports-prod",
    ]

    actions = [
      "s3:ListBucketMultipartUploads",
      "s3:GetObjectRetention",
      "s3:DeleteObjectVersion",
      "s3:ListBucket",
      "s3:PutObjectLegalHold",
      "s3:GetObjectLegalHold",
      "s3:GetBucketAcl",
      "s3:PutObject",
      "s3:GetObjectAcl",
      "s3:GetObject",
      "s3:GetObjectTorrent",
      "s3:AbortMultipartUpload",
      "s3:PutObjectRetention",
      "s3:GetObjectTagging",
      "s3:DeleteObject",
      "s3:GetObjectVersion",
    ]
  }

  statement {
    sid       = "VisualEditor2"
    effect    = "Allow"
    resources = ["*"]
    actions   = ["s3:ListAllMyBuckets"]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]
    actions   = ["quicksight:RegisterUser"]
  }

  statement {
    sid    = ""
    effect = "Allow"
    resources = [
      "arn:aws:quicksight:eu-central-1:969009837416:user/default/aomad-quicksight-prog",
      "arn:aws:quicksight:us-east-1:505950216627:user/default/promop-quicksight-prog",
    ]
    actions = ["quicksight:GenerateEmbedUrlForRegisteredUser"]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["arn:aws:iam::505950216627:role/promop-quicksight-prog"]
    actions   = ["sts:AssumeRole"]
  }
}

data "aws_iam_policy_document" "aomap-eks-aomap-ms-ns-aoma3-sa-aoma-ust-policy" {
  # checkov:skip=CKV_AWS_107: Ensure IAM policies does not allow credentials exposure
  # checkov:skip=CKV_AWS_108: Ensure IAM policies does not allow data exfiltration
  # checkov:skip=CKV_AWS_109: Ensure IAM policies does not allow permissions management / resource exposure without constraints
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints

  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "sqs:ListQueues",
      "kms:GenerateRandom",
      "logs:*",
      "kms:*",
      "kms:CreateCustomKeyStore",
      "secretsmanager:*",
      "kms:DescribeCustomKeyStores",
      "kms:ListKeys",
      "kms:DeleteCustomKeyStore",
      "kms:UpdateCustomKeyStore",
      "kms:ListAliases",
      "kms:DisconnectCustomKeyStore",
      "kms:CreateKey",
      "kms:ConnectCustomKeyStore",
      "secretsmanager:ListSecrets",
      "ses:SendRawEmail",
      "sts:AssumeRoleWithWebIdentity",
    ]
  }

  statement {
    sid    = "VisualEditor1"
    effect = "Allow"

    resources = [
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/Aoma/Ust-1BfaDp",
      "arn:aws:sqs:eu-central-1:${var.account_id}:ust-prod-assetupload-sqs",
      "arn:aws:sqs:eu-central-1:${var.account_id}:ust-bulkRegistration-sqs-prod",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMADownloadAssetNotification",
      "arn:aws:kms:eu-central-1:${var.account_id}:key/c0d8c6c0-be34-48ac-8cc0-756dd6a372a8",
      "arn:aws:lambda:eu-central-1:${var.account_id}:function:AOMA-GRAS",
      "arn:aws:s3:::sme-aoma-core-prod-ust-bulk-script-processes/*",
      "arn:aws:s3:::sme-aoma-core-prod-ust-bulk-script-processes",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAEmailNotification",
    ]

    actions = [
      "secretsmanager:GetResourcePolicy",
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "sqs:*",
      "secretsmanager:ListSecretVersionIds",
      "kms:*",
      "lambda:InvokeAsync",
      "lambda:InvokeFunction",
      "s3:Get*",
      "s3:Put*",
      "s3:List*",
    ]
  }

  statement {
    sid    = "VisualEditor2"
    effect = "Allow"

    resources = [
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/amp-asset-events",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ameba-events",
      "arn:aws:kafka:eu-central-1:${var.account_id}:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/jms-events",
      "arn:aws:kafka:eu-central-1:613871678587:group/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/aoma-ust*",
      "arn:aws:kafka:eu-central-1:613871678587:cluster/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3",
    ]

    actions = [
      "kafka-cluster:ReadData",
      "kafka-cluster:DescribeTopic",
      "kafka-cluster:DescribeGroup",
      "kafka-cluster:Connect",
      "kafka-cluster:AlterGroup",
    ]
  }


  statement {
    sid    = "VisualEditor3"
    effect = "Allow"

    resources = [
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ameba-events",
      "arn:aws:kafka:eu-central-1:613871678587:group/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/aoma-ust*",
      "arn:aws:kafka:eu-central-1:613871678587:cluster/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3",
    ]

    actions = [
      "kafka:List*",
      "kafka:Get*",
      "kafka:Describe*",
      "kafka-cluster:Connect",
      "kafka-cluster:WriteDataIdempotently",
      "kafka-cluster:WriteData"
    ]
  }
}

data "aws_iam_policy_document" "aomap-txmgr-secrets-access-policy" {
  statement {
    sid    = ""
    effect = "Allow"

    resources = [
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/AOMA/aoma.properties-8E9kui",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/AOMA/aoma_db-SUecRH",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/AOMA/miload_db-q98VZH",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/AOMA/wildfly_mgmt-zWhLyV",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/AOMA/txmgr_aoma_db-oxE2WD",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/AOMA/txmgr_usm-CbCSoT",
      "arn:aws:secretsmanager:eu-central-1:613871678587:secret:prod/AOMA/txmgr_usm_token-PfzyCn",
      "arn:aws:secretsmanager:eu-central-1:613871678587:secret:prod/AOMA/txmgr_misc_secrets-SvDwLZ",
      "arn:aws:secretsmanager:eu-central-1:613871678587:secret:prod/AOMA/txmgr_app_properties-0ZG7na",
      "arn:aws:secretsmanager:eu-central-1:613871678587:secret:prod/AOMA/txmgr_usm_service-l3beqY",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/aoma_trnsctn_mngr-*"
    ]

    actions = [
      "secretsmanager:GetResourcePolicy",
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecretVersionIds",
      "secretsmanager:GetRandomPassword",
      "secretsmanager:ListSecrets",
      "secretsmanager:UpdateSecret",
    ]
  }

  statement {
    sid    = ""
    effect = "Allow"

    resources = [
      "arn:aws:secretsmanager:eu-central-1:613871678587:secret:prod/AOMA/txmgr_app_properties/aomap-txmgr-ecs-01.smeaomaprod.net-F75xT2",
      "arn:aws:secretsmanager:eu-central-1:613871678587:secret:prod/AOMA/txmgr_app_properties/aomap-txmgr-ecs-02.smeaomaprod.net-sriDur",
      "arn:aws:secretsmanager:eu-central-1:613871678587:secret:prod/AOMA/txmgr_app_properties/aomap-txmgr-ecs-03.smeaomaprod.net-WFrNiE",
      "arn:aws:secretsmanager:eu-central-1:613871678587:secret:prod/AOMA/txmgr_app_properties/aomap-txmgr-ecs-04.smeaomaprod.net-mai4zx",
      "arn:aws:secretsmanager:eu-central-1:613871678587:secret:prod/AOMA/txmgr_app_properties/aomap-parallel-pg-ecs-txmgr01.smeaomaprod.net-rXmDHR",
      "arn:aws:secretsmanager:eu-central-1:613871678587:secret:prod/AOMA/txmgr_app_properties/aomap-parallel-pg-ecs-txmgr02.smeaomaprod.net-vOxo9f",
      "arn:aws:secretsmanager:eu-central-1:613871678587:secret:prod/AOMA/txmgr_app_properties/aomap-parallel-pg-ecs-txmgr03.smeaomaprod.net-JOIEJg",
      "arn:aws:secretsmanager:eu-central-1:613871678587:secret:prod/AOMA/txmgr_app_properties/aomap-parallel-pg-ecs-txmgr04.smeaomaprod.net-h7JHyY",
    ]

    actions = [
      "secretsmanager:*",
    ]
  }


  statement {
    sid    = ""
    effect = "Allow"
    resources = [
      "arn:aws:iam::635220336377:role/globaldsp-aoma-txmgr-role"
    ]
    actions = [
      "sts:AssumeRole"
    ]
  }

  statement {
    sid    = ""
    effect = "Allow"
    resources = [
      "arn:aws:kms:eu-central-1:613871678587:key/f3f00387-1ce2-4e0b-8528-dfcb0a8a56c0"
    ]
    actions = [
      "kms:Decrypt"
    ]
  }
}


data "aws_iam_policy_document" "sme-ust-ci-transfer-role-policy" {
  # checkov:skip=CKV_AWS_107: Ensure IAM policies does not allow credentials exposure
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"
    resources = [
      "arn:aws:s3:::sme-ust-ci-transfer",
      "arn:aws:s3:::sme-ust-ci-transfer/*",
    ]
    actions = [
      "s3:ListBucket",
      "s3:Put*",
      "s3:GetObject",

    ]
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["*"]
    actions = [
      "sts:Assume*",
    ]
  }
  statement {
    sid       = "VisualEditor6"
    effect    = "Allow"
    resources = ["arn:aws:secretsmanager:eu-central-1:554998489284:secret:prod/AOMA/SonyCiUtil*"]
    actions = [
      "secretsmanager:*",
    ]
  }

  statement {
    sid       = "Stmt15826950713"
    effect    = "Allow"
    resources = ["arn:aws:kms:eu-central-1:554998489284:key/0a795e2a-ee6e-4081-9d22-211ae93392e7"]
    actions   = ["kms:Decrypt", "kms:DescribeKey"]
  }
}

data "aws_iam_policy_document" "ameba-prod-ns-digital-archive-sa-amp-asset-preview-service" {
  # checkov:skip=CKV_AWS_109: Ensure IAM policies does not allow permissions management / resource exposure without constraints
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "sqs:DeleteMessage",
      "sqs:GetQueueUrl",
      "sqs:ListQueues",
      "kms:GenerateRandom",
      "sqs:ReceiveMessage",
      "sqs:SendMessage",
      "sqs:GetQueueAttributes",
      "sqs:*",
      "kms:CreateCustomKeyStore",
      "kms:DescribeCustomKeyStores",
      "kms:ListKeys",
      "kms:DeleteCustomKeyStore",
      "kms:UpdateCustomKeyStore",
      "kms:ListAliases",
      "kms:DisconnectCustomKeyStore",
      "kms:CreateKey",
      "kms:ConnectCustomKeyStore",
    ]
  }

  statement {
    sid    = "VisualEditor1"
    effect = "Allow"

    resources = [
      "arn:aws:iam::${var.account_id}:role/aomap-ameba-eks-developer",
      "arn:aws:sqs:eu-central-1:${var.account_id}:ElementalMediaConvertRequestQ-prod",
      "arn:aws:sqs:eu-central-1:${var.account_id}:ElementalMediaConvertStatusQ-prod",
      "arn:aws:s3:::amp-audio-archives-prod/*",
      "arn:aws:s3:::amp-photo-archives-prod/*",
      "arn:aws:s3:::amp-video-archives-prod/*",
      "arn:aws:s3:::amp-audio-archives-prod",
      "arn:aws:s3:::amp-photo-archives-prod",
      "arn:aws:s3:::amp-video-archives-prod",
    ]

    actions = [
      "sqs:DeleteMessage",
      "s3:GetObject",
      "sts:AssumeRole",
      "sqs:GetQueueUrl",
      "sqs:ReceiveMessage",
      "sqs:SendMessage",
      "s3:RestoreObject",
      "sqs:GetQueueAttributes",
      "s3:ListBucket",
    ]
  }

  statement {
    sid    = "VisualEditor2"
    effect = "Allow"

    resources = [
      "arn:aws:s3:::amp-audio-archives-prod/*",
      "arn:aws:s3:::amp-video-archives-prod/*",
      "arn:aws:s3:::amp-photo-archives-prod/*",
      "arn:aws:s3:::amp-audio-archives-prod",
      "arn:aws:s3:::amp-video-archives-prod",
      "arn:aws:s3:::amp-photo-archives-prod",
      "arn:aws:sqs:eu-central-1:${var.account_id}:ElementalMediaConvertStatusQ-prod",
    ]

    actions = [
      "sqs:DeleteMessage",
      "s3:GetObject",
      "sqs:GetQueueUrl",
      "sqs:ReceiveMessage",
      "s3:RestoreObject",
      "sqs:SendMessage",
      "s3:ListBucket",
      "sqs:GetQueueAttributes",
    ]
  }

  statement {
    sid       = "VisualEditor3"
    effect    = "Allow"
    resources = ["arn:aws:sqs:eu-central-1:${var.account_id}:ElementalMediaConvertStatusQ-prod"]
    actions   = ["sqs:*"]
  }

  statement {
    sid       = "VisualEditor4"
    effect    = "Allow"
    resources = ["arn:aws:kms:eu-central-1:${var.account_id}:key/5d51d0ad-aa91-465c-8abb-86b5770bf97b"]
    actions   = ["kms:*"]
  }
}

data "aws_iam_policy_document" "oneClick_CloudTrail_CloudWatchLogs_Role_1584515530199" {
  statement {
    sid       = "AWSCloudTrailCreateLogStream20141101"
    effect    = "Allow"
    resources = ["arn:aws:logs:eu-central-1:${var.account_id}:log-group:cloudtrail-traildash:log-stream:${var.account_id}_CloudTrail_eu-central-1*"]
    actions   = ["logs:CreateLogStream"]
  }

  statement {
    sid       = "AWSCloudTrailPutLogEvents20141101"
    effect    = "Allow"
    resources = ["arn:aws:logs:eu-central-1:${var.account_id}:log-group:cloudtrail-traildash:log-stream:${var.account_id}_CloudTrail_eu-central-1*"]
    actions   = ["logs:PutLogEvents"]
  }
}

data "aws_iam_policy_document" "oneClick_flowlogsRole_1590311915292" {
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "logs:CreateLogGroup",
      "logs:CreateLogStream",
      "logs:DescribeLogGroups",
      "logs:DescribeLogStreams",
      "logs:PutLogEvents",
    ]
  }
}

data "aws_iam_policy_document" "ameba-prod-ns-aoma3-sa-aoma-talent-service" {
  # checkov:skip=CKV_AWS_107: Ensure IAM policies does not allow credentials exposure
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/aoma3/ats-S8FZFw",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/aoma3/ats",
    ]

    actions = [
      "secretsmanager:GetResourcePolicy",
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecretVersionIds",
    ]
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["*"]
    actions   = ["sts:*"]
  }
}

data "aws_iam_policy_document" "eks-fullaccess" {
  # checkov:skip=CKV_AWS_108: Ensure IAM policies does not allow data exfiltration
  # checkov:skip=CKV_AWS_109: Ensure IAM policies does not allow permissions management / resource exposure without constraints
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "acm-pca:*",
      "iam:PassRole",
      "autoscaling:Describe*",
      "cloudwatch:*",
      "logs:*",
      "s3:*",
      "cloudtrail:*",
      "eks:*",
      "kms:CreateGrant",
      "acm:*",
    ]
  }
}

data "aws_iam_policy_document" "AWSLambdaBasicExecutionRole-6e9d8424-ca57-4655-a163-56795ebfef3e" {
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["arn:aws:logs:eu-central-1:${var.account_id}:*"]
    actions   = ["logs:CreateLogGroup"]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["arn:aws:logs:eu-central-1:${var.account_id}:log-group:/aws/lambda/ustPreFlightCheckProd:*"]

    actions = [
      "logs:CreateLogStream",
      "logs:PutLogEvents",
    ]
  }
}

data "aws_iam_policy_document" "aomap-ecs-aomap-ameba-message-bridge-taskdef-task-policy" {
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]
    actions   = ["logs:*"]
  }
}

data "aws_iam_policy_document" "aomap-ec2-aomap1-prodsrvc01-policy" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAQcNotesNotificationQueue",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAApprovalNotificationQueue",
    ]

    actions = [
      "sqs:DeleteMessage",
      "sqs:GetQueueUrl",
      "sqs:ChangeMessageVisibility",
      "sqs:SendMessageBatch",
      "sqs:ReceiveMessage",
      "sqs:SendMessage",
      "sqs:GetQueueAttributes",
      "sqs:ListQueueTags",
      "sqs:ListDeadLetterSourceQueues",
      "sqs:DeleteMessageBatch",
      "sqs:PurgeQueue",
      "sqs:DeleteQueue",
      "sqs:CreateQueue",
      "sqs:ChangeMessageVisibilityBatch",
      "sqs:SetQueueAttributes",
    ]
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["*"]
    actions   = ["sqs:ListQueues"]
  }
}

data "aws_iam_policy_document" "lambda-create" {
  # checkov:skip=CKV_AWS_109: Ensure IAM policies does not allow permissions management / resource exposure without constraints
  # checkov:skip=CKV_AWS_110: Ensure IAM policies does not allow privilege escalation
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "sns:*",
      "acm:ExportCertificate",
      "iam:PassRole",
      "backup-storage:*",
      "ses:*",
      "cloudwatch:*",
      "kms:*",
      "logs:PutMetricFilter",
      "lambda:*",
      "backup:*",
      "events:*",
      "scheduler:*",
    ]
  }
}

data "aws_iam_policy_document" "aomap-ecs-aomap-gras-graphql-taskdef-task-policy" {
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]
    actions   = ["logs:*"]
  }
}

data "aws_iam_policy_document" "aomap-ssm-sec-agent-status-upload" {
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "ssm:UpdateInstanceInformation",
      "ssmmessages:CreateControlChannel",
      "ssmmessages:CreateDataChannel",
      "ssmmessages:OpenControlChannel",
      "ssmmessages:OpenDataChannel",
      "ec2messages:AcknowledgeMessage",
      "ec2messages:DeleteMessage",
      "ec2messages:FailMessage",
      "ec2messages:GetEndpoint",
      "ec2messages:GetMessages",
      "ec2messages:SendReply",
    ]
  }

  statement {
    sid    = ""
    effect = "Allow"

    resources = [
      "arn:aws:s3:::portal-agents-amazon-ssm-packages-command",
      "arn:aws:s3:::portal-agents-amazon-ssm-packages-command/*",
    ]

    actions = [
      "s3:GetBucketLocation",
      "s3:PutObject",
      "s3:GetObject",
      "s3:GetEncryptionConfiguration",
      "s3:AbortMultipartUpload",
      "s3:ListMultipartUploadParts",
      "s3:ListBucket",
      "s3:ListBucketMultipartUploads",
      "s3:GetBucketAcl",
    ]
  }
}

data "aws_iam_policy_document" "AWSLoadBalancerControllerIAMPolicy" {
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]
    actions   = ["iam:CreateServiceLinkedRole"]

    condition {
      test     = "StringEquals"
      variable = "iam:AWSServiceName"
      values   = ["elasticloadbalancing.amazonaws.com"]
    }
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "ec2:DescribeAccountAttributes",
      "ec2:DescribeAddresses",
      "ec2:DescribeAvailabilityZones",
      "ec2:DescribeInternetGateways",
      "ec2:DescribeVpcs",
      "ec2:DescribeVpcPeeringConnections",
      "ec2:DescribeSubnets",
      "ec2:DescribeSecurityGroups",
      "ec2:DescribeInstances",
      "ec2:DescribeNetworkInterfaces",
      "ec2:DescribeTags",
      "ec2:GetCoipPoolUsage",
      "ec2:DescribeCoipPools",
      "ec2:GetSecurityGroupsForVpc",
      "elasticloadbalancing:DescribeLoadBalancers",
      "elasticloadbalancing:DescribeLoadBalancerAttributes",
      "elasticloadbalancing:DescribeListeners",
      "elasticloadbalancing:DescribeListenerCertificates",
      "elasticloadbalancing:DescribeSSLPolicies",
      "elasticloadbalancing:DescribeRules",
      "elasticloadbalancing:DescribeTargetGroups",
      "elasticloadbalancing:DescribeTargetGroupAttributes",
      "elasticloadbalancing:DescribeTargetHealth",
      "elasticloadbalancing:DescribeTags",
      "elasticloadbalancing:DescribeTrustStores",
      "elasticloadbalancing:DescribeListenerAttributes",
      "elasticloadbalancing:DescribeCapacityReservation",
    ]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "cognito-idp:DescribeUserPoolClient",
      "acm:ListCertificates",
      "acm:DescribeCertificate",
      "iam:ListServerCertificates",
      "iam:GetServerCertificate",
      "waf-regional:GetWebACL",
      "waf-regional:GetWebACLForResource",
      "waf-regional:AssociateWebACL",
      "waf-regional:DisassociateWebACL",
      "wafv2:GetWebACL",
      "wafv2:GetWebACLForResource",
      "wafv2:AssociateWebACL",
      "wafv2:DisassociateWebACL",
      "shield:GetSubscriptionState",
      "shield:DescribeProtection",
      "shield:CreateProtection",
      "shield:DeleteProtection",
    ]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "ec2:AuthorizeSecurityGroupIngress",
      "ec2:RevokeSecurityGroupIngress",
    ]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]
    actions   = ["ec2:CreateSecurityGroup"]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["arn:aws:ec2:*:*:security-group/*"]
    actions   = ["ec2:CreateTags"]

    condition {
      test     = "StringEquals"
      variable = "ec2:CreateAction"
      values   = ["CreateSecurityGroup"]
    }

    condition {
      test     = "Null"
      variable = "aws:RequestTag/elbv2.k8s.aws/cluster"
      values   = ["false"]
    }
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["arn:aws:ec2:*:*:security-group/*"]

    actions = [
      "ec2:CreateTags",
      "ec2:DeleteTags",
    ]

    condition {
      test     = "Null"
      variable = "aws:RequestTag/elbv2.k8s.aws/cluster"
      values   = ["true"]
    }

    condition {
      test     = "Null"
      variable = "aws:ResourceTag/elbv2.k8s.aws/cluster"
      values   = ["false"]
    }
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "ec2:AuthorizeSecurityGroupIngress",
      "ec2:RevokeSecurityGroupIngress",
      "ec2:DeleteSecurityGroup",
    ]

    condition {
      test     = "Null"
      variable = "aws:ResourceTag/elbv2.k8s.aws/cluster"
      values   = ["false"]
    }
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "elasticloadbalancing:CreateLoadBalancer",
      "elasticloadbalancing:CreateTargetGroup",
    ]

    condition {
      test     = "Null"
      variable = "aws:RequestTag/elbv2.k8s.aws/cluster"
      values   = ["false"]
    }
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "elasticloadbalancing:CreateListener",
      "elasticloadbalancing:DeleteListener",
      "elasticloadbalancing:CreateRule",
      "elasticloadbalancing:DeleteRule",
    ]
  }

  statement {
    sid    = ""
    effect = "Allow"

    resources = [
      "arn:aws:elasticloadbalancing:*:*:targetgroup/*/*",
      "arn:aws:elasticloadbalancing:*:*:loadbalancer/net/*/*",
      "arn:aws:elasticloadbalancing:*:*:loadbalancer/app/*/*",
    ]

    actions = [
      "elasticloadbalancing:AddTags",
      "elasticloadbalancing:RemoveTags",
    ]

    condition {
      test     = "Null"
      variable = "aws:RequestTag/elbv2.k8s.aws/cluster"
      values   = ["true"]
    }

    condition {
      test     = "Null"
      variable = "aws:ResourceTag/elbv2.k8s.aws/cluster"
      values   = ["false"]
    }
  }

  statement {
    sid    = ""
    effect = "Allow"

    resources = [
      "arn:aws:elasticloadbalancing:*:*:listener/net/*/*/*",
      "arn:aws:elasticloadbalancing:*:*:listener/app/*/*/*",
      "arn:aws:elasticloadbalancing:*:*:listener-rule/net/*/*/*",
      "arn:aws:elasticloadbalancing:*:*:listener-rule/app/*/*/*",
    ]

    actions = [
      "elasticloadbalancing:AddTags",
      "elasticloadbalancing:RemoveTags",
    ]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "elasticloadbalancing:ModifyLoadBalancerAttributes",
      "elasticloadbalancing:SetIpAddressType",
      "elasticloadbalancing:SetSecurityGroups",
      "elasticloadbalancing:SetSubnets",
      "elasticloadbalancing:DeleteLoadBalancer",
      "elasticloadbalancing:ModifyTargetGroup",
      "elasticloadbalancing:ModifyTargetGroupAttributes",
      "elasticloadbalancing:DeleteTargetGroup",
      "elasticloadbalancing:ModifyListenerAttributes",
      "elasticloadbalancing:ModifyCapacityReservation",
    ]

    condition {
      test     = "Null"
      variable = "aws:ResourceTag/elbv2.k8s.aws/cluster"
      values   = ["false"]
    }
  }

  statement {
    sid    = ""
    effect = "Allow"

    resources = [
      "arn:aws:elasticloadbalancing:*:*:targetgroup/*/*",
      "arn:aws:elasticloadbalancing:*:*:loadbalancer/net/*/*",
      "arn:aws:elasticloadbalancing:*:*:loadbalancer/app/*/*",
    ]

    actions = ["elasticloadbalancing:AddTags"]

    condition {
      test     = "StringEquals"
      variable = "elasticloadbalancing:CreateAction"

      values = [
        "CreateTargetGroup",
        "CreateLoadBalancer",
      ]
    }

    condition {
      test     = "Null"
      variable = "aws:RequestTag/elbv2.k8s.aws/cluster"
      values   = ["false"]
    }
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["arn:aws:elasticloadbalancing:*:*:targetgroup/*/*"]

    actions = [
      "elasticloadbalancing:RegisterTargets",
      "elasticloadbalancing:DeregisterTargets",
    ]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "elasticloadbalancing:SetWebAcl",
      "elasticloadbalancing:ModifyListener",
      "elasticloadbalancing:AddListenerCertificates",
      "elasticloadbalancing:RemoveListenerCertificates",
      "elasticloadbalancing:ModifyRule",
    ]
  }
}

data "aws_iam_policy_document" "AWSQuickSightRDSPolicy" {
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]
    actions   = ["rds:Describe*"]
  }
}

data "aws_iam_policy_document" "ECSReadOnly" {
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "ecs:ListAttributes",
      "ecs:DescribeTaskSets",
      "ecs:DescribeTaskDefinition",
      "ecs:DescribeClusters",
      "ecs:ListServices",
      "ecs:ListAccountSettings",
      "ecs:ListTagsForResource",
      "ecs:ListTasks",
      "ecs:ListTaskDefinitionFamilies",
      "ecs:DescribeServices",
      "ecs:ListContainerInstances",
      "ecs:DescribeContainerInstances",
      "ecs:DescribeTasks",
      "ecs:ListTaskDefinitions",
      "ecs:ListClusters",
    ]
  }
}

data "aws_iam_policy_document" "aomap-ecs-aomap-txmgr-taskdef-task-policy" {
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]
    actions   = ["logs:*"]
  }

}

data "aws_iam_policy_document" "sqs-aomap" {
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]
    actions   = ["sqs:ListQueues"]
  }

  statement {
    sid    = "VisualEditor1"
    effect = "Allow"

    resources = [
      "arn:aws:sqs:eu-central-1:${var.account_id}:ust-bulkRegistration-sqs-prod",
      "arn:aws:sqs:eu-central-1:${var.account_id}:ust-eom-sender-sqs.fifo",
      "arn:aws:sqs:eu-central-1:${var.account_id}:ust-assetupload-sqs",
      "arn:aws:sqs:eu-central-1:${var.account_id}:ust-prod-assetupload-sqs",
    ]

    actions = ["sqs:*"]
  }
}

data "aws_iam_policy_document" "aomap-ecs-aomap-gql-registry-taskdef-task-policy" {
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]
    actions   = ["logs:*"]
  }
}

data "aws_iam_policy_document" "aomap-ecs-aomap-ameba-event-consumer-taskdef-task-policy" {
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]
    actions   = ["logs:*"]
  }
}

data "aws_iam_policy_document" "AWS_Events_Invoke_Inspector_Assessment_Template" {
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]
    actions   = ["inspector:StartAssessmentRun"]
  }
}

data "aws_iam_policy_document" "oneClick_Cognito_aomap_kibana_usersAuth_Role_1583510894429" {
  # checkov:skip=CKV_AWS_107: Ensure IAM policies does not allow credentials exposure
  # checkov:skip=CKV_AWS_109: Ensure IAM policies does not allow permissions management / resource exposure without constraints
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "mobileanalytics:PutEvents",
      "cognito-sync:*",
      "cognito-identity:*",
    ]
  }
}

data "aws_iam_policy_document" "aomap-sqs" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAQcNotesNotificationQueue",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAQcNotesNotificationDLQ",
      "arn:aws:sqs:eu-central-1:${var.account_id}:AOMAApprovalNotificationQueue",
    ]

    actions = ["sqs:*"]
  }
}

data "aws_iam_policy_document" "oneClick_lambda_elasticsearch_execution_1583517028477" {
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["arn:aws:logs:*:*:*"]

    actions = [
      "logs:CreateLogGroup",
      "logs:CreateLogStream",
      "logs:PutLogEvents",
    ]
  }

  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["arn:aws:es:*:*:*"]
    actions   = ["es:ESHttpPost"]
  }
}

data "aws_iam_policy_document" "RDS-EC2" {
  # checkov:skip=CKV_AWS_109: Ensure IAM policies does not allow permissions management / resource exposure without constraints
  # checkov:skip=CKV_AWS_110: Ensure IAM policies does not allow privilege escalation
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "ec2:CreateNetworkInterface",
      "ec2:DescribeInstances",
      "ec2:DescribeNetworkInterfaces",
      "ec2:DeleteNetworkInterface",
      "sqs:*",
      "ec2:AttachNetworkInterface",
      "athena:UpdateWorkGroup",
      "athena:UpdateDataCatalog",
      "athena:StartQueryExecution",
      "athena:ListWorkGroups",
      "athena:ListQueryExecutions",
      "athena:ListNamedQueries",
      "athena:GetWorkGroup",
      "athena:GetTables",
      "athena:GetTable",
      "athena:GetQueryResultsStream",
      "athena:GetQueryResults",
      "athena:GetQueryExecutions",
      "athena:GetQueryExecution",
      "athena:GetNamespaces",
      "athena:GetNamespace",
      "athena:GetNamedQuery",
      "athena:GetExecutionEngines",
      "athena:GetExecutionEngine",
      "athena:GetDatabase",
      "athena:GetDataCatalog",
      "athena:GetCatalogs",
      "athena:CreateWorkGroup",
      "athena:CreateNamedQuery",
      "athena:CreateDataCatalog",
      "athena:BatchGetQueryExecution",
      "athena:BatchGetNamedQuery",
      "glue:*",
      "kms:Decrypt",
    ]
  }

  statement {
    sid    = ""
    effect = "Allow"

    actions = [
      "s3:PutObject*",
      "s3:ListBucket",
      "s3:GetObject*",
      "s3:GetBucketLocation",
      "s3:DeleteObject*"
    ]

    resources = [
      "arn:aws:s3:::sme-media-conversion-prod-rds-backups",
      "arn:aws:s3:::sme-media-conversion-prod-rds-backups/*",
      "arn:aws:s3:::sme-media-conversion-prod-lambda-archived",
      "arn:aws:s3:::sme-media-conversion-prod-lambda-archived/*",
    ]
  }
}

data "aws_iam_policy_document" "asset-preview-service-lambda-policy-prod" {
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = "Logging"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "logs:CreateLogGroup",
      "logs:CreateLogStream",
      "logs:PutLogEvents",
    ]
  }

  statement {
    sid       = "PassRole"
    effect    = "Allow"
    resources = ["arn:aws:iam::${var.account_id}:role/asset-preview-service-mediaconvert-prod"]
    actions   = ["iam:PassRole"]
  }

  statement {
    sid       = "MediaConvertService"
    effect    = "Allow"
    resources = ["*"]
    actions   = ["mediaconvert:*"]
  }

  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:sqs:eu-central-1:${var.account_id}:ElementalMediaConvertRequestQ-prod",
      "arn:aws:sqs:eu-central-1:${var.account_id}:ElementalMediaConvertStatusQ-prod",
    ]

    actions = [
      "sqs:DeleteMessage",
      "sqs:GetQueueUrl",
      "sqs:GetQueueAttributes",
      "sqs:ReceiveMessage",
      "sqs:SendMessage",
    ]
  }
}

data "aws_iam_policy_document" "aomap-eks-ameba-prod-ns-aoma3-sa-aoma-batch-service-policy" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:sqs:*:${var.account_id}:*",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/aoma3/abs-OHQUTP",
      "arn:aws:rds:eu-central-1:${var.account_id}:db:ameba-rds-stage-01",
    ]

    actions = [
      "secretsmanager:GetResourcePolicy",
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "sqs:*",
      "secretsmanager:ListSecretVersionIds",
      "rds:*",
    ]
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "sqs:ListQueues",
      "secretsmanager:ListSecrets",
    ]
  }

  statement {
    sid       = "VisualEditor2"
    effect    = "Allow"
    resources = ["arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/aoma3/abs-OHQUTP"]
    actions   = ["secretsmanager:ListSecrets"]
  }

  statement {
    sid    = "VisualEditor3"
    effect = "Allow"

    resources = [
      "arn:aws:kafka:eu-central-1:${var.account_id}:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/amp-asset-events",
      "arn:aws:kafka:eu-central-1:${var.account_id}:group/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/abs-*",
      "arn:aws:kafka:eu-central-1:${var.account_id}:cluster/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3",
    ]

    actions = [
      "kafka-cluster:ReadData",
      "kafka-cluster:DescribeTopic",
      "kafka-cluster:DescribeGroup",
      "kafka-cluster:Connect",
      "kafka-cluster:AlterGroup",
    ]
  }
}

data "aws_iam_policy_document" "aomap-ameba-link-service-prod-role-policy" {
  statement {
    sid       = "VisualEditor2"
    effect    = "Allow"
    resources = ["arn:aws:sqs:eu-central-1:613871678587:AOMAEmailNotification"]
    actions   = ["sqs:*"]
  }

  statement {
    sid       = "VisualEditor3"
    effect    = "Allow"
    resources = ["arn:aws:kms:eu-central-1:613871678587:key/5d51d0ad-aa91-465c-8abb-86b5770bf97b"]
    actions   = ["kms:*"]
  }
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/link-attempts",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/history-events",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/gras-messages",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/eom-messages",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ameba-events",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/aoma.amp.product_track_links",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/aoma.amp.product_side_links",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/aoma.amp.product_links",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/update-legacy-search",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/aoma-email-notifications",
      "arn:aws:kafka:eu-central-1:613871678587:group/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ameba-link-service*",
      "arn:aws:kafka:eu-central-1:613871678587:cluster/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3",
    ]

    actions = [
      "kafka-cluster:WriteDataIdempotently",
      "kafka-cluster:WriteData",
      "kafka-cluster:ReadData",
      "kafka-cluster:DescribeTopic",
      "kafka-cluster:DescribeGroup",
      "kafka-cluster:Connect",
      "kafka-cluster:AlterGroup"
    ]
  }

  statement {
    sid       = "VisualEditor4"
    effect    = "Allow"
    resources = ["arn:aws:kms:eu-central-1:${var.account_id}:key/f3f00387-1ce2-4e0b-8528-dfcb0a8a56c0"]
    actions   = ["kms:Decrypt"]
  }

  statement {
    sid       = "VisualEditor5"
    effect    = "Allow"
    resources = ["arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/ameba_link_srvc-MgmjDt"]
    actions = [
      "secretsmanager:ListSecretVersionIds",
      "secretsmanager:GetSecretValue",
      "secretsmanager:GetResourcePolicy",
      "secretsmanager:DescribeSecret"
    ]
  }

  statement {
    sid       = "VisualEditor6"
    effect    = "Allow"
    resources = ["arn:aws:iam::635220336377:role/gdsp-ameba-labelcopy-msk-role"]
    actions   = ["sts:AssumeRole"]
  }
}

data "aws_iam_policy_document" "aomap-ameba-evnt-hist-prod-role-policy" {
  statement {
    sid       = "VisualEditor2"
    effect    = "Allow"
    resources = ["arn:aws:sqs:eu-central-1:613871678587:AOMAEmailNotification"]
    actions   = ["sqs:*"]
  }

  statement {
    sid       = "VisualEditor3"
    effect    = "Allow"
    resources = ["arn:aws:kms:eu-central-1:613871678587:key/5d51d0ad-aa91-465c-8abb-86b5770bf97b"]
    actions   = ["kms:*"]
  }
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/history-events",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/gras-messages",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/eom-messages",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/master-messages",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/master-messages-physical",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/link-messages",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/link-messages-physical",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/aoma-email-notifications",
      "arn:aws:kafka:eu-central-1:613871678587:group/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ameba-event-history*",
      "arn:aws:kafka:eu-central-1:613871678587:cluster/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3",
    ]

    actions = [
      "kafka-cluster:ReadData",
      "kafka-cluster:DescribeTopic",
      "kafka-cluster:DescribeGroup",
      "kafka-cluster:Connect",
      "kafka-cluster:AlterGroup",
    ]
  }

  statement {
    sid       = "VisualEditor4"
    effect    = "Allow"
    resources = ["arn:aws:kms:eu-central-1:${var.account_id}:key/f3f00387-1ce2-4e0b-8528-dfcb0a8a56c0"]
    actions   = ["kms:Decrypt"]
  }

  statement {
    sid       = "VisualEditor5"
    effect    = "Allow"
    resources = ["arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/ameba_event_hstry_prcsr-sXuGzI"]
    actions = [
      "secretsmanager:ListSecretVersionIds",
      "secretsmanager:GetSecretValue",
      "secretsmanager:GetResourcePolicy",
      "secretsmanager:DescribeSecret"
    ]
  }

  statement {
    sid    = "VisualEditor6"
    effect = "Allow"
    resources = [
      "arn:aws:iam::635220336377:role/gdsp-ameba-msk-role"
    ]
    actions = [
      "sts:AssumeRole"
    ]
  }

  statement {
    sid    = "VisualEditor7"
    effect = "Allow"

    resources = [
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/history-events",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/gras-messages",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/aoma-email-notifications",
      "arn:aws:kafka:eu-central-1:613871678587:group/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ameba-event-history*",
      "arn:aws:kafka:eu-central-1:613871678587:cluster/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3",
    ]

    actions = [
      "kafka-cluster:ReadData",
      "kafka-cluster:DescribeTopic",
      "kafka-cluster:DescribeGroup",
      "kafka-cluster:Connect",
      "kafka-cluster:AlterGroup",
      "kafka-cluster:WriteData",
      "kafka-cluster:WriteDataIdempotently",
    ]
  }
}

data "aws_iam_policy_document" "aomap-ameba-labelcopy-loader-role-policy" {

  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:kafka:eu-central-1:${var.account_id}:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/history-events",
      "arn:aws:kafka:eu-central-1:${var.account_id}:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ameba*",
      "arn:aws:kafka:eu-central-1:${var.account_id}:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ameba-lc-internal",
      "arn:aws:kafka:eu-central-1:${var.account_id}:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/aoma-email-notifications",
      "arn:aws:kafka:eu-central-1:${var.account_id}:group/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ameba-lc*",
      "arn:aws:kafka:eu-central-1:${var.account_id}:cluster/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3",
    ]

    actions = [
      "kafka-cluster:ReadData",
      "kafka-cluster:DescribeTopic",
      "kafka-cluster:DescribeGroup",
      "kafka-cluster:Connect",
      "kafka-cluster:AlterGroup"
    ]
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["arn:aws:kms:eu-central-1:613871678587:key/5d51d0ad-aa91-465c-8abb-86b5770bf97b"]
    actions   = ["kms:*"]
  }

  statement {
    sid       = "VisualEditor2"
    effect    = "Allow"
    resources = ["arn:aws:kms:eu-central-1:${var.account_id}:key/f3f00387-1ce2-4e0b-8528-dfcb0a8a56c0"]
    actions   = ["kms:Decrypt"]
  }

  statement {
    sid       = "VisualEditor3"
    effect    = "Allow"
    resources = ["arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/ameba_labelcopy_srvc-*"]
    actions = [
      "secretsmanager:ListSecretVersionIds",
      "secretsmanager:GetSecretValue",
      "secretsmanager:GetResourcePolicy",
      "secretsmanager:DescribeSecret"
    ]
  }

  statement {
    sid    = "VisualEditor4"
    effect = "Allow"
    resources = [
      "arn:aws:iam::635220336377:role/gdsp-ameba-labelcopy-msk-role"
    ]
    actions = [
      "sts:AssumeRole"
    ]
  }

  statement {
    sid    = "VisualEditor5"
    effect = "Allow"

    resources = [
      "arn:aws:kafka:eu-central-1:${var.account_id}:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/history-events",
      "arn:aws:kafka:eu-central-1:${var.account_id}:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/update-legacy-search",
      "arn:aws:kafka:eu-central-1:${var.account_id}:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/aoma-email-notifications",
      "arn:aws:kafka:eu-central-1:${var.account_id}:group/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ameba-lc*",
      "arn:aws:kafka:eu-central-1:${var.account_id}:cluster/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3",
    ]

    actions = [
      "kafka-cluster:WriteDataIdempotently",
      "kafka-cluster:WriteData",
      "kafka-cluster:ReadData",
      "kafka-cluster:DescribeTopic",
      "kafka-cluster:DescribeGroup",
      "kafka-cluster:Connect",
      "kafka-cluster:AlterGroup",
    ]
  }
}


data "aws_iam_policy_document" "ameba-prod-sts-assume-policy" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:iam::613871678587:role/aomap-ameba-evnt-hist-prod-role",
      "arn:aws:iam::613871678587:role/aomap-ameba-link-service-prod-role",

    ]

    actions = [
      "sts:AssumeRole",
    ]
  }
}

data "aws_iam_policy_document" "RDSAdminPolicyForTerraform" {
  # checkov:skip=CKV_AWS_109: Ensure IAM policies does not allow permissions management / resource exposure without constraints
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid    = "RDSActions"
    effect = "Allow"

    actions = [
      "rds:StartDBInstance",
      "rds:StopDBInstance",
      "rds:RebootDBInstance",
      "rds:CreateDBSnapshot",
      "rds:CopyDBSnapshot",
      "rds:ModifyDBSnapshotAttribute",
      "rds:DeleteDBSnapshot",
      "rds:CreateDBClusterSnapshot",
      "rds:AddTagsToResource",
      "rds:CreateEventSubscription",
      "rds:ModifyEventSubscription",
      "rds:DeleteEventSubscription",
      "rds:ApplyPendingMaintenanceAction"
    ]

    resources = ["*"]
  }

  statement {
    sid    = "RDSSnapshotExport"
    effect = "Allow"

    actions = [
      "iam:PassRole"
    ]

    resources = [
      "arn:aws:iam::613871678587:role/RDSAdmin"
    ]

    condition {
      test     = "StringEquals"
      variable = "iam:PassedToService"

      values = [
        "rds.amazonaws.com"
      ]
    }
  }

  statement {
    sid    = "RDSS3Export"
    effect = "Allow"

    actions = [
      "s3:PutObject"
    ]

    resources = [
      "arn:aws:s3:::sme-aoma-core-prod-rds-backups/*"
    ]
  }
}

data "aws_iam_policy_document" "aomap-msk-access" {
  statement {
    sid    = "VisualEditor1"
    effect = "Allow"

    actions = [
      "kafka-cluster:WriteDataIdempotently",
      "kafka-cluster:WriteData",
      "kafka-cluster:ReadData",
      "kafka-cluster:DescribeTopicDynamicConfiguration",
      "kafka-cluster:DescribeTopic",
      "kafka-cluster:DescribeGroup",
      "kafka-cluster:DescribeClusterDynamicConfiguration",
      "kafka-cluster:DescribeCluster",
      "kafka-cluster:Connect",
      "kafka-cluster:AlterGroup"
    ]

    resources = [
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/metadata-update-video-messages",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/metadata",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/master-messages",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ameba-events",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/link-messages",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/master-messages-physical",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/link-messages-physical",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/jms-events",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ec-backfill",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/backfill-mb-internal",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/aoma-email-notifications",
      "arn:aws:kafka:eu-central-1:613871678587:group/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ameba.messagebridge*",
      "arn:aws:kafka:eu-central-1:613871678587:cluster/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3"
    ]
  }

  statement {
    sid    = "VisualEditor2"
    effect = "Allow"
    actions = [
      "sqs:*"
    ]
    resources = [
      "arn:aws:sqs:eu-central-1:613871678587:AOMAEmailNotification"
    ]
  }

  statement {
    sid    = "VisualEditor3"
    effect = "Allow"
    actions = [
      "kms:*"
    ]
    resources = [
      "arn:aws:kms:eu-central-1:613871678587:key/5d51d0ad-aa91-465c-8abb-86b5770bf97b"
    ]
  }
}

data "aws_iam_policy_document" "aomap-eks-ameba-prod-sa-sr-role-policy" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:kafka:eu-central-1:613871678587:transactional-id/*/*/*",
      "arn:aws:kafka:eu-central-1:613871678587:topic/*",
      "arn:aws:kafka:eu-central-1:613871678587:group/*",
      "arn:aws:kafka:eu-central-1:613871678587:cluster/*",
    ]

    actions = [
      "kafka-cluster:WriteDataIdempotently",
      "kafka-cluster:WriteData",
      "kafka-cluster:ReadData",
      "kafka-cluster:DescribeTopicDynamicConfiguration",
      "kafka-cluster:DescribeTopic",
      "kafka-cluster:DescribeGroup",
      "kafka-cluster:DescribeClusterDynamicConfiguration",
      "kafka-cluster:DescribeCluster",
      "kafka-cluster:CreateTopic",
      "kafka-cluster:Connect",
      "kafka-cluster:AlterGroup",
      "kafka-cluster:*",
    ]
  }

  statement {
    sid       = "VisualEditor2"
    effect    = "Allow"
    resources = ["arn:aws:sqs:eu-central-1:613871678587:AOMAEmailNotification", ]
    actions   = ["sqs:*", ]
  }

  statement {
    sid       = "VisualEditor3"
    effect    = "Allow"
    resources = ["arn:aws:kms:eu-central-1:613871678587:key/5d51d0ad-aa91-465c-8abb-86b5770bf97b"]
    actions   = ["kms:*"]

  }
}

data "aws_iam_policy_document" "KubeCostFederatedRoleIAMPolicy" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"
    actions = [
      "s3:ListBucket",
      "s3:GetBucketLocation"
    ]
    resources = ["arn:aws:s3:::sme-core-cloud-shared-kubecost"]
  }

  statement {
    sid    = "VisualEditor1"
    effect = "Allow"
    actions = [
      "s3:PutObject",
      "s3:GetObject",
      "s3:ListBucketMultipartUploads",
      "s3:AbortMultipartUpload",
      "s3:ListBucket",
      "s3:DeleteObject",
      "s3:ListMultipartUploadParts"
    ]
    resources = [
      "arn:aws:s3:::sme-core-cloud-shared-kubecost",
      "arn:aws:s3:::sme-core-cloud-shared-kubecost/*"
    ]
  }

  statement {
    sid       = "VisualEditor2"
    effect    = "Allow"
    actions   = ["ec2:Describe*"]
    resources = ["*"]
  }
}

data "aws_iam_policy_document" "aomap-eks-aomap-ms-sa-aoma-mail-service-kafka-policy" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"
    resources = [
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/aoma-email-notifications",
      "arn:aws:kafka:eu-central-1:613871678587:group/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ams.*",
      "arn:aws:kafka:eu-central-1:613871678587:cluster/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3"
    ]
    actions = [
      "kafka:List*",
      "kafka:Get*",
      "kafka:Describe*",
      "kafka-cluster:WriteDataIdempotently",
      "kafka-cluster:WriteData",
      "kafka-cluster:ReadData",
      "kafka-cluster:DescribeTopicDynamicConfiguration",
      "kafka-cluster:DescribeTopic",
      "kafka-cluster:DescribeGroup",
      "kafka-cluster:DescribeClusterDynamicConfiguration",
      "kafka-cluster:DescribeCluster",
      "kafka-cluster:Connect",
      "kafka-cluster:AlterGroup"
    ]
  }
}

data "aws_iam_policy_document" "aomap-eks-ameba-prod-ns-ameba-private-sa-agql-kafka-policy" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"
    resources = [
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/backfill-mb-internal",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ec-backfill",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/link-attempts",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/preorder-events",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/jms-events",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ameba-events",
      "arn:aws:kafka:eu-central-1:${var.account_id}:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ameba-lc-internal",
      "arn:aws:kafka:eu-central-1:${var.account_id}:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/bulk-registrations",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/history-events",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/gras-messages",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/eom-messages",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/update-legacy-search",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/aoma-email-notifications",
      "arn:aws:kafka:eu-central-1:613871678587:group/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ameba.gql.*",
      "arn:aws:kafka:eu-central-1:613871678587:cluster/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3"
    ]
    actions = [
      "kafka:List*",
      "kafka:Get*",
      "kafka:Describe*",
      "kafka-cluster:WriteDataIdempotently",
      "kafka-cluster:WriteData",
      "kafka-cluster:ReadData",
      "kafka-cluster:DescribeTopicDynamicConfiguration",
      "kafka-cluster:DescribeTopic",
      "kafka-cluster:DescribeGroup",
      "kafka-cluster:DescribeClusterDynamicConfiguration",
      "kafka-cluster:DescribeCluster",
      "kafka-cluster:Connect",
      "kafka-cluster:AlterGroup"
    ]
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["arn:aws:iam::638682502729:role/delconvp-quicksight-prog"]
    actions   = ["sts:AssumeRole"]
  }
}

data "aws_iam_policy_document" "aomap-eks-ameba-prod-sa-kafka-utils-role-policy" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:kafka:eu-central-1:613871678587:transactional-id/*/*/*",
      "arn:aws:kafka:eu-central-1:613871678587:topic/*",
      "arn:aws:kafka:eu-central-1:613871678587:group/*",
      "arn:aws:kafka:eu-central-1:613871678587:cluster/*",
    ]

    actions = [
      "kafka-cluster:WriteDataIdempotently",
      "kafka-cluster:WriteData",
      "kafka-cluster:ReadData",
      "kafka-cluster:DescribeTopicDynamicConfiguration",
      "kafka-cluster:DescribeTopic",
      "kafka-cluster:DescribeGroup",
      "kafka-cluster:DescribeClusterDynamicConfiguration",
      "kafka-cluster:DescribeCluster",
      "kafka-cluster:CreateTopic",
      "kafka-cluster:Connect",
      "kafka-cluster:AlterGroup",
      "kafka-cluster:*",
    ]
  }

  statement {
    sid       = "VisualEditor2"
    effect    = "Allow"
    resources = ["arn:aws:sqs:eu-central-1:613871678587:AOMAEmailNotification"]
    actions   = ["sqs:*"]
  }

  statement {
    sid       = "VisualEditor3"
    effect    = "Allow"
    resources = ["arn:aws:kms:eu-central-1:613871678587:key/5d51d0ad-aa91-465c-8abb-86b5770bf97b"]
    actions   = ["kms:*"]
  }
}

data "aws_iam_policy_document" "aomap-amp-archive-exports-prod-policy" {
  statement {
    sid    = "VisualEditor1"
    effect = "Allow"
    actions = [
      "s3:PutObject",
      "s3:GetObject",
      "s3:ListBucketMultipartUploads",
      "s3:AbortMultipartUpload",
      "s3:ListBucket",
      "s3:DeleteObject",
      "s3:ListMultipartUploadParts"
    ]
    resources = [
      "arn:aws:s3:::amp-archive-exports-prod",
      "arn:aws:s3:::amp-archive-exports-prod/*"
    ]
  }
}

data "aws_iam_policy_document" "aomap-eks-ameba-prod-ns-ameba-prod-sa-ameba-gql-role-policy" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/gras-messages",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/eom-messages",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ameba-events",
      "arn:aws:kafka:eu-central-1:${var.account_id}:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ameba-lc-internal",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/aoma-email-notifications",
      "arn:aws:kafka:eu-central-1:613871678587:group/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/ameba.gql.*",
      "arn:aws:kafka:eu-central-1:613871678587:cluster/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3",
    ]

    actions = [
      "kafka:List*",
      "kafka:Get*",
      "kafka:Describe*",
      "kafka-cluster:WriteDataIdempotently",
      "kafka-cluster:WriteData",
      "kafka-cluster:ReadData",
      "kafka-cluster:DescribeTopicDynamicConfiguration",
      "kafka-cluster:DescribeTopic",
      "kafka-cluster:DescribeGroup",
      "kafka-cluster:DescribeClusterDynamicConfiguration",
      "kafka-cluster:DescribeCluster",
      "kafka-cluster:Connect",
      "kafka-cluster:AlterGroup",
    ]
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["arn:aws:kms:eu-central-1:${var.account_id}:key/f3f00387-1ce2-4e0b-8528-dfcb0a8a56c0"]
    actions   = ["kms:Decrypt"]
  }

  statement {
    sid       = "VisualEditor2"
    effect    = "Allow"
    resources = ["arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/ameba_graphql-9I06AP"]
    actions = [
      "secretsmanager:ListSecretVersionIds",
      "secretsmanager:GetSecretValue",
      "secretsmanager:GetResourcePolicy",
      "secretsmanager:DescribeSecret"
    ]
  }
}

data "aws_iam_policy_document" "arvatok8s-prod-elasticsearch" {
  statement {
    sid    = ""
    effect = "Allow"

    resources = [
      "arn:aws:s3:::arvatok8s-prod-elasticsearch-backup",
      "arn:aws:s3:::arvatok8s-prod-elasticsearch-backup/*",
    ]

    actions = ["s3:*"]
  }
}

data "aws_iam_policy_document" "aomap-ameba-sa-ks-prod-role-policy" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:kafka:eu-central-1:613871678587:transactional-id/*/*/*",
      "arn:aws:kafka:eu-central-1:613871678587:topic/*",
      "arn:aws:kafka:eu-central-1:613871678587:group/*",
      "arn:aws:kafka:eu-central-1:613871678587:cluster/*"
    ]

    actions = [
      "kafka-cluster:WriteDataIdempotently",
      "kafka-cluster:WriteData",
      "kafka-cluster:ReadData",
      "kafka-cluster:DescribeTopicDynamicConfiguration",
      "kafka-cluster:DescribeTopic",
      "kafka-cluster:DescribeGroup",
      "kafka-cluster:DescribeClusterDynamicConfiguration",
      "kafka-cluster:DescribeCluster",
      "kafka-cluster:CreateTopic",
      "kafka-cluster:Connect",
      "kafka-cluster:AlterGroup",
      "kafka-cluster:*"
    ]
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["arn:aws:kms:eu-central-1:${var.account_id}:key/f3f00387-1ce2-4e0b-8528-dfcb0a8a56c0"]
    actions   = ["kms:Decrypt"]
  }

  statement {
    sid       = "VisualEditor2"
    effect    = "Allow"
    resources = ["arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/ms_msg_brdg_srvc-tqAlDa"]
    actions = [
      "secretsmanager:ListSecretVersionIds",
      "secretsmanager:GetSecretValue",
      "secretsmanager:GetResourcePolicy",
      "secretsmanager:DescribeSecret"
    ]
  }
}

data "aws_iam_policy_document" "aomap-sa-msk-eom-prod-policy" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/master-messages",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/link-messages",
      "arn:aws:kafka:eu-central-1:613871678587:group/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/eom.*",
      "arn:aws:kafka:eu-central-1:613871678587:cluster/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3",
    ]

    actions = [
      "kafka-cluster:ReadData",
      "kafka-cluster:DescribeTopicDynamicConfiguration",
      "kafka-cluster:DescribeTopic",
      "kafka-cluster:DescribeGroup",
      "kafka-cluster:DescribeClusterDynamicConfiguration",
      "kafka-cluster:DescribeCluster",
      "kafka-cluster:Connect",
      "kafka-cluster:AlterGroup",
    ]
  }
}

data "aws_iam_policy_document" "aomap-sa-msk-ampsv-prod-policy" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/aoma-email-notifications",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/amp-asset-events",
      "arn:aws:kafka:eu-central-1:613871678587:group/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/AMP_*",
      "arn:aws:kafka:eu-central-1:613871678587:cluster/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3"
    ]

    actions = [
      "kafka-cluster:WriteDataIdempotently",
      "kafka-cluster:WriteData",
      "kafka-cluster:ReadData",
      "kafka-cluster:DescribeTopicDynamicConfiguration",
      "kafka-cluster:DescribeTopic",
      "kafka-cluster:DescribeGroup",
      "kafka-cluster:DescribeClusterDynamicConfiguration",
      "kafka-cluster:DescribeCluster",
      "kafka-cluster:Connect",
      "kafka-cluster:AlterGroup"
    ]
  }
}

data "aws_iam_policy_document" "aomap-sa-msk-mlib-prod-policy" {
  statement {
    sid    = "VisualEditor5"
    effect = "Allow"

    resources = [
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/mlib-backfill",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/master-messages",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/link-messages",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/master-messages-physical",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/link-messages-physical",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/amp-asset-events",
      "arn:aws:kafka:eu-central-1:613871678587:group/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/Mlib.*",
      "arn:aws:kafka:eu-central-1:613871678587:cluster/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3",
    ]

    actions = [
      "kafka-cluster:ReadData",
      "kafka-cluster:DescribeTopicDynamicConfiguration",
      "kafka-cluster:DescribeTopic",
      "kafka-cluster:DescribeGroup",
      "kafka-cluster:DescribeClusterDynamicConfiguration",
      "kafka-cluster:DescribeCluster",
      "kafka-cluster:Connect",
      "kafka-cluster:AlterGroup",
    ]
  }

  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/mlib-previews",
      "arn:aws:kafka:eu-central-1:613871678587:group/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/Mlib.*",
      "arn:aws:kafka:eu-central-1:613871678587:cluster/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3",
    ]

    actions = [
      "kafka-cluster:WriteDataIdempotently",
      "kafka-cluster:WriteData",
      "kafka-cluster:ReadData",
      "kafka-cluster:DescribeTopicDynamicConfiguration",
      "kafka-cluster:DescribeTopic",
      "kafka-cluster:DescribeGroup",
      "kafka-cluster:DescribeClusterDynamicConfiguration",
      "kafka-cluster:DescribeCluster",
      "kafka-cluster:Connect",
      "kafka-cluster:AlterGroup",
    ]
  }
}

data "aws_iam_policy_document" "aomap-sa-msk-delivery-prod-policy" {
  statement {
    sid    = "VisualEditor5"
    effect = "Allow"

    resources = [
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/mlib-backfill",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/master-messages",
      "arn:aws:kafka:eu-central-1:613871678587:topic/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/link-messages",
      "arn:aws:kafka:eu-central-1:613871678587:group/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3/delivery.*",
      "arn:aws:kafka:eu-central-1:613871678587:cluster/aomap-ameba-msk-01/6d2ff71b-58da-45fc-bc8f-fd60ce7429f3-3",
    ]

    actions = [
      "kafka-cluster:ReadData",
      "kafka-cluster:DescribeTopicDynamicConfiguration",
      "kafka-cluster:DescribeTopic",
      "kafka-cluster:DescribeGroup",
      "kafka-cluster:DescribeClusterDynamicConfiguration",
      "kafka-cluster:DescribeCluster",
      "kafka-cluster:Connect",
      "kafka-cluster:AlterGroup",
    ]
  }
}

data "aws_iam_policy_document" "aomap-txmgr-ecr-policy" {
  statement {
    actions = [
      "ecr:BatchCheckLayerAvailability",
      "ecr:CompleteLayerUpload",
      "ecr:GetDownloadUrlForLayer",
      "ecr:InitiateLayerUpload",
      "ecr:PutImage",
      "ecr:UploadLayerPart"
    ]
    resources = [
      "arn:aws:ecr:eu-central-1:613871678587:repository/txmgr-vault-service"
    ]
  }
}

data "aws_iam_policy_document" "sme-india-content-s3-policy" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:s3:::sme-india-content",
      "arn:aws:s3:::sme-india-content/*",
      "arn:aws:s3:::sme-india-streaming",
      "arn:aws:s3:::sme-india-streaming/*",
    ]

    actions = [
      "s3:ListBucket",
      "s3:ListAllMyBuckets",
      "s3:PutObject",
      "s3:GetObject",
      "s3:GetObjectTagging",
      "s3:GetObjectVersion",
      "s3:GetObjectVersionTagging",
      "s3:DeleteObject"
    ]
  }

  statement {
    sid    = "VisualEditor1"
    effect = "Allow"

    resources = ["*"]

    actions = [
      "s3:List*",
    ]
  }
}

data "aws_iam_policy_document" "ameba-prod-ns-aoma3-sa-aoma-health-metrics-role-policy" {
  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["arn:aws:iam::635220336377:role/gdsp-sa-aoma-role"]
    actions   = ["sts:AssumeRole"]
  }
}

data "aws_iam_policy_document" "aomap-ameba-db-athena-policy" {
  # checkov:skip=CKV_AWS_109: Ensure IAM policies does not allow permissions management / resource exposure without constraints
  # checkov:skip=CKV_AWS_110: Ensure IAM policies does not allow privilege escalation
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = ["*"]

    actions = [
      "athena:*",
      "glue:*"
    ]
  }

  statement {
    sid    = "VisualEditor1"
    effect = "Allow"

    resources = [
      "arn:aws:s3:::sme-aoma-core-prod-quicksight/*",
      "arn:aws:s3:::sme-aoma-core-prod-quicksight",
      "arn:aws:s3:::sme-aoma-core-prod-dw/*",
      "arn:aws:s3:::sme-aoma-core-prod-dw",
      "arn:aws:s3:::sme-aoma-core-prod-rds-backups/*",
      "arn:aws:s3:::sme-aoma-core-prod-rds-backups",
      "arn:aws:s3:::sme-aoma-core-prod-athena-out/*",
      "arn:aws:s3:::sme-aoma-core-prod-athena-out"
    ]

    actions = [
      "s3:*",
    ]
  }

  statement {
    sid       = "VisualEditor2"
    effect    = "Allow"
    resources = ["arn:aws:kms:eu-central-1:${var.account_id}:key/f3f00387-1ce2-4e0b-8528-dfcb0a8a56c0"]
    actions   = ["kms:Decrypt"]
  }

}

data "aws_iam_policy_document" "ameba-prod-ns-aoma3-sa-aoma-file-storage-service-policy" {
  # checkov:skip=CKV_AWS_108: Ensure IAM policies does not allow data exfiltration
  # checkov:skip=CKV_AWS_109: Ensure IAM policies does not allow permissions management / resource exposure without constraints
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid    = "AllowSQSAndSecretsManagerAccess"
    effect = "Allow"

    resources = [
      "arn:aws:s3:::sme-core-aoma-prod-file-storage*",
      "arn:aws:s3:::sme-core-aoma-prod-file-storage/*",
      "arn:aws:secretsmanager:eu-central-1:613871678587:secret:prod/aoma3/afss-JbW8wM",
      "arn:aws:secretsmanager:eu-central-1:613871678587:secret:db/aoma/prod/ms_product_graphql_srvc-*",
      "arn:aws:kms:eu-central-1:${var.account_id}:key/f3f00387-1ce2-4e0b-8528-dfcb0a8a56c0",

    ]

    actions = [
      "s3:*",
      "secretsmanager:ListSecretVersionIds",
      "secretsmanager:GetSecretValue",
      "secretsmanager:GetResourcePolicy",
      "secretsmanager:DescribeSecret",
      "kms:Decrypt"
    ]
  }

  statement {
    sid       = "AllowListingQueuesAndSecrets"
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "sqs:ListQueues",
      "secretsmanager:*",
      "ecr:*",
      "secretsmanager:ListSecrets",
    ]
  }
}


data "aws_iam_policy_document" "aomad-eks-ameba-dev-ns-aoma-ern-service-policy" {
  statement {
    sid    = "VisualEditor1"
    effect = "Allow"
    resources = [
      "arn:aws:secretsmanager:eu-central-1:613871678587:secret:prod/AOMA/aoma_ern_service_secrets-VAFy50"
    ]

    actions = [
      "secretsmanager:*",
    ]
  }
}


data "aws_iam_policy_document" "aomad-eks-ameba-dev-ns-txmgr-digital-assurance-service-policy" {
  statement {
    sid    = "VisualEditor1"
    effect = "Allow"
    resources = [
      "arn:aws:secretsmanager:eu-central-1:613871678587:secret:prod/AOMA/aoma_txmgr_digital_assurance_secrets-RKjURj"
    ]

    actions = [
      "secretsmanager:*",
    ]
  }
}

# AOMARegistrationPostProcessingProd SQS queue
data "aws_iam_policy_document" "aomap-sqs-registration-post-processing-read" {
  statement {
    sid    = ""
    effect = "Allow"

    actions = [
      "sqs:ReceiveMessage",
      "sqs:DeleteMessage",
      "sqs:GetQueueAttributes",
      "sqs:GetQueueUrl"
    ]

    resources = [
      "arn:aws:sqs:eu-central-1:613871678587:AOMARegistrationPostProcessing"
    ]
  }
}

data "aws_iam_policy_document" "aomap-sqs-registration-post-processing-create" {
  statement {
    sid    = ""
    effect = "Allow"

    actions = [
      "sqs:SendMessage"
    ]

    resources = [
      "arn:aws:sqs:eu-central-1:613871678587:AOMARegistrationPostProcessing"
    ]
  }
}

data "aws_iam_policy_document" "AOMA-SQS-Policy" {
  statement {
    sid    = "VisualEditor0"
    effect = "Allow"

    resources = [
      "arn:aws:sqs:::arn:aws:sqs:eu-central-1:${var.account_id}:AOMAQcNotesNotificationQueue"
    ]

    actions = [
      "sqs:DeleteMessage",
      "sqs:GetQueueUrl",
      "sqs:ChangeMessageVisibility",
      "sqs:SendMessageBatch",
      "sqs:ReceiveMessage",
      "sqs:SendMessage",
      "sqs:GetQueueAttributes",
      "sqs:ListQueueTags",
      "sqs:ListDeadLetterSourceQueues",
      "sqs:DeleteMessageBatch",
      "sqs:PurgeQueue",
      "sqs:DeleteQueue",
      "sqs:CreateQueue",
      "sqs:ChangeMessageVisibilityBatch",
      "sqs:SetQueueAttributes",
    ]
  }

  statement {
    sid       = "VisualEditor1"
    effect    = "Allow"
    resources = ["*"]
    actions   = ["sqs:ListQueues"]
  }
}

data "aws_iam_policy_document" "full-rds-proxy-access" {
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]

    actions = [
      "rds:CreateDBProxy",
      "rds:CreateDBProxyEndpoint",
      "rds:DeleteDBProxy",
      "rds:DeleteDBProxyEndpoint",
      "rds:DeregisterDBProxyTargets",
      "rds:DescribeDBProxies",
      "rds:DescribeDBProxyEndpoints",
      "rds:DescribeDBProxyTargetGroups",
      "rds:DescribeDBProxyTargets",
      "rds:ModifyDBProxy",
      "rds:ModifyDBProxyEndpoint",
      "rds:ModifyDBProxyTargetGroup",
      "rds:RegisterDBProxyTargets",
    ]
  }
}


data "aws_iam_policy_document" "aomap-eks-aoma2-kafka-sa-policy" {

  statement {
    sid       = "VisualEditor0"
    effect    = "Allow"
    resources = ["arn:aws:iam::635220336377:role/gdsp-aoma-service-msk-role"]
    actions   = ["sts:AssumeRole"]
  }
}


data "aws_iam_policy_document" "aomap-txmgr-kafka-consumer-service-policy" {

  statement {
    sid    = "secretsManagerRO"
    effect = "Allow"
    resources = [
      "arn:aws:secretsmanager:eu-central-1:613871678587:secret:prod/AOMA/txmgr_aoma_db-oxE2WD",
      "arn:aws:secretsmanager:eu-central-1:613871678587:secret:prod/AOMA/txmgr_kafka_consumer_secrets-9thZX5",
    ]
    actions = [
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecrets"
    ]
  }

  statement {
    sid    = "secretsManagerRW"
    effect = "Allow"
    resources = [
      "arn:aws:secretsmanager:eu-central-1:613871678587:secret:prod/AOMA/txmgr_kafka_consumer_app_properties-mwsIxB",
      "arn:aws:secretsmanager:eu-central-1:613871678587:secret:prod/AOMA/txmgr_usm_token-PfzyCn"
    ]
    actions = [
      "secretsmanager:*"
    ]
  }

  statement {
    sid    = "assumeRole"
    effect = "Allow"
    resources = [
      "arn:aws:iam::635220336377:role/globaldsp-aoma-txmgr-role"
    ]
    actions = ["sts:AssumeRole"]
  }
}



data "aws_iam_policy_document" "aomap-kafka-cluster-read-policy" {
  statement {
    sid    = "KafkaClusterReadAccess"
    effect = "Allow"

    resources = [
      "arn:aws:kafka:eu-central-1:${var.account_id}:cluster/aoma*"
    ]

    actions = [
      "kafka-cluster:Connect",
      "kafka-cluster:DescribeCluster",
    ]
  }

  statement {
    sid    = "KafkaTopicReadAccess"
    effect = "Allow"

    resources = [
      "arn:aws:kafka:eu-central-1:${var.account_id}:topic/aoma*/*/*"
    ]

    actions = [
      "kafka-cluster:DescribeTopic",
      "kafka-cluster:ReadData",
    ]
  }
}

data "aws_iam_policy_document" "aomap-storage-gateway-policy" {
  statement {
    sid    = ""
    effect = "Allow"

    resources = [
      "arn:aws:s3:::sme-aoma-core-storage-gateway-prod",
      "arn:aws:s3:::sme-aoma-core-storage-gateway-prod/*",
    ]

    actions = [
      "s3:*"
    ]
  }
}

data "aws_iam_policy_document" "aomap-deployment-eventbridge-policy" {
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid    = ""
    effect = "Allow"

    resources = ["*"]

    actions = [
      "events:PutRule",
      "events:DescribeRule",
      "events:PutTargets",
      "events:RemoveTargets",
      "events:DeleteRule",
      "events:ListTargetsByRule",
      "events:ListTagsForResource",
      "events:TagResource",
      "events:UntagResource"
    ]
  }
}

data "aws_iam_policy_document" "aoma-prod-rds-proxy-kms-policy" {
  # checkov:skip=CKV_AWS_111: Ensure IAM policies does not allow write access without constraints
  statement {
    sid       = "RDSProxySecretsKMSAccess"
    effect    = "Allow"
    resources = ["arn:aws:kms:eu-central-1:${var.account_id}:key/f3f00387-1ce2-4e0b-8528-dfcb0a8a56c0"]
    actions   = ["kms:Decrypt"]
  }
}

data "aws_iam_policy_document" "aoma-prod-rds-proxy-secret-cldntv-policy" {
  statement {
    sid    = "RDSProxySecretAccess"
    effect = "Allow"

    resources = [
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/ms_amp_cldntv_tsk_prgrs_vrfr-*",
    ]

    actions = [
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecretVersionIds",
    ]
  }
}

data "aws_iam_policy_document" "aoma-prod-rds-proxy-secret-prvw_srvc-policy" {
  statement {
    sid    = "RDSProxySecretAccess"
    effect = "Allow"

    resources = [
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/ms_amp_asset_preview_service-*",
    ]

    actions = [
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecretVersionIds",
    ]
  }
}

data "aws_iam_policy_document" "aoma-prod-rds-proxy-secret-aspra_utl-policy" {
  statement {
    sid    = "RDSProxySecretAccess"
    effect = "Allow"

    resources = [
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/ms_amp_aspera_util-*",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/da/AmpAsperaUtil-*",
    ]

    actions = [
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecretVersionIds",
    ]
  }
}

data "aws_iam_policy_document" "ameba-prod-ns-aoma2-prod-sa-aoma-service-timer-policy" {
  statement {
    sid    = "SecretsManagerAccess"
    effect = "Allow"

    resources = [
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/AOMA/database-secrets.properties-*",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/AOMA/aoma_service_timer_secrets-*",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/AOMA/gras_ws_client_secrets-*",
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:prod/AOMA/eomsender_secrets-*",
    ]

    actions = [
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecretVersionIds",
    ]
  }

  statement {
    sid       = "SecretsManagerList"
    effect    = "Allow"
    resources = ["*"]
    actions   = ["secretsmanager:ListSecrets"]
  }
}

data "aws_iam_policy_document" "aoma-prod-rds-proxy-secret-batch-srvc-policy" {
  statement {
    sid    = "RDSProxySecretAccess"
    effect = "Allow"

    resources = [
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/ms_aoma_batch_srvc-*",
    ]

    actions = [
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecretVersionIds",
    ]
  }
}

data "aws_iam_policy_document" "aoma-prod-rds-proxy-secret-exp-clnt-policy" {
  statement {
    sid    = "RDSProxySecretAccess"
    effect = "Allow"

    resources = [
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/ms_amp_asset_export_client-*",
    ]

    actions = [
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecretVersionIds",
    ]
  }
}

data "aws_iam_policy_document" "aoma-prod-rds-proxy-secret-envlp-policy" {
  statement {
    sid    = "RDSProxySecretAccess"
    effect = "Allow"

    resources = [
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/ms_envelope_srvc-*",
    ]

    actions = [
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecretVersionIds",
    ]
  }
}

data "aws_iam_policy_document" "aoma-prod-rds-proxy-secret-ust-srvc-policy" {
  statement {
    sid    = "RDSProxySecretAccess"
    effect = "Allow"

    resources = [
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/ust_srvc-*",
    ]

    actions = [
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecretVersionIds",
    ]
  }
}

data "aws_iam_policy_document" "aoma-prod-rds-proxy-secret-ust-be-srvc-policy" {
  statement {
    sid    = "RDSProxySecretAccess"
    effect = "Allow"

    resources = [
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/ust_be_srvc-*",
    ]

    actions = [
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecretVersionIds",
    ]
  }
}

data "aws_iam_policy_document" "aoma-prod-rds-proxy-secret-da-batch-init-policy" {
  statement {
    sid    = "RDSProxySecretAccess"
    effect = "Allow"

    resources = [
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/ms_da_batch_initiator-*",
    ]

    actions = [
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecretVersionIds",
    ]
  }
}

data "aws_iam_policy_document" "aoma-prod-rds-proxy-secret-da-asset-imp-policy" {
  statement {
    sid    = "RDSProxySecretAccess"
    effect = "Allow"

    resources = [
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/da_asset_importer-*",
    ]

    actions = [
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecretVersionIds",
    ]
  }
}

data "aws_iam_policy_document" "aoma-prod-rds-proxy-secret-da-cntct-sht-hndlr-policy" {
  statement {
    sid    = "RDSProxySecretAccess"
    effect = "Allow"

    resources = [
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/ms_amp_contactsheet_handler-*",
    ]

    actions = [
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecretVersionIds",
    ]
  }
}

data "aws_iam_policy_document" "aoma-prod-rds-proxy-secret-amino-srvc-policy" {
  statement {
    sid    = "RDSProxySecretAccess"
    effect = "Allow"

    resources = [
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/amino_srvc-*",
    ]

    actions = [
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecretVersionIds",
    ]
  }
}

data "aws_iam_policy_document" "aoma-prod-rds-proxy-secret-txn-mgr-policy" {
  statement {
    sid    = "RDSProxySecretAccess"
    effect = "Allow"

    resources = [
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/aoma_trnsctn_mngr-*",
    ]

    actions = [
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecretVersionIds",
    ]
  }
}

data "aws_iam_policy_document" "aoma-prod-rds-proxy-secret-tlnt-srvc-policy" {
  statement {
    sid    = "RDSProxySecretAccess"
    effect = "Allow"

    resources = [
      "arn:aws:secretsmanager:eu-central-1:${var.account_id}:secret:db/aoma/prod/ms_aoma_talent_srvc-*",
    ]

    actions = [
      "secretsmanager:GetSecretValue",
      "secretsmanager:DescribeSecret",
      "secretsmanager:ListSecretVersionIds",
    ]
  }
}

data "aws_iam_policy_document" "sme-aoma-spain-s3-policy" {
  statement {
    sid    = "ListBucket"
    effect = "Allow"

    resources = [
      "arn:aws:s3:::sme-aoma-spain",
    ]

    actions = [
      "s3:ListBucket",
      "s3:ListAllMyBuckets"
    ]
  }

  statement {
    sid    = "ReadWriteObjects"
    effect = "Allow"

    resources = [
      "arn:aws:s3:::sme-aoma-spain/amp-asset-catalog-transfer/Spain/*",
    ]

    actions = [
      "s3:GetObject",
      "s3:PutObject",
      "s3:DeleteObject",
    ]
  }
}
