iam.tf 1.5 KB

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