iam.tf 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # tfsec:ignore:aws-iam-no-policy-wildcards - baseline this setting first. We use wildcards in policies
  2. data "aws_iam_policy_document" "policy_portal_data_sync_lambda" {
  3. # checkov:skip=CKV_AWS_111: see tfsec aws-iam-no-policy-wildcard ignore comment
  4. statement {
  5. effect = "Allow"
  6. actions = [
  7. "ec2:CreateNetworkInterface",
  8. "logs:CreateLogStream",
  9. "ec2:DescribeNetworkInterfaces",
  10. "logs:DescribeLogStreams",
  11. "ec2:DeleteNetworkInterface",
  12. "logs:PutRetentionPolicy",
  13. "logs:CreateLogGroup",
  14. "logs:PutLogEvents",
  15. "sqs:ListQueues"
  16. ]
  17. resources = ["*"]
  18. }
  19. # tfsec:ignore:aws-iam-no-policy-wildcards - baseline this setting first. We use wildcards in policies
  20. statement {
  21. effect = "Allow"
  22. actions = [
  23. "sqs:*",
  24. ]
  25. resources = [
  26. aws_sqs_queue.sqs_queue.arn,
  27. aws_sqs_queue.sqs_queue_dlq.arn
  28. ]
  29. }
  30. statement {
  31. effect = "Allow"
  32. actions = [
  33. "kms:GenerateDataKey",
  34. "kms:Decrypt"
  35. ]
  36. resources = [
  37. aws_kms_key.sqs_key.arn
  38. ]
  39. }
  40. }
  41. resource "aws_iam_policy" "policy_portal_data_sync_lambda" {
  42. name = "policy_portal_data_sync_lambda"
  43. path = "/"
  44. policy = data.aws_iam_policy_document.policy_portal_data_sync_lambda.json
  45. description = "IAM policy for portal_data_sync_lambda"
  46. }
  47. resource "aws_iam_role" "portal_lambda_role" {
  48. name = "portal-data-sync-lambda-role"
  49. assume_role_policy = <<EOF
  50. {
  51. "Version": "2012-10-17",
  52. "Statement": [
  53. {
  54. "Sid": "",
  55. "Effect": "Allow",
  56. "Principal": {
  57. "Service": [
  58. "lambda.amazonaws.com"
  59. ]
  60. },
  61. "Action": "sts:AssumeRole"
  62. }
  63. ]
  64. }
  65. EOF
  66. }
  67. resource "aws_iam_role_policy_attachment" "lambda_role" {
  68. role = aws_iam_role.portal_lambda_role.name
  69. policy_arn = aws_iam_policy.policy_portal_data_sync_lambda.arn
  70. }