iam.tf 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. data "aws_iam_policy_document" "policy_document" {
  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. ]
  14. resources = ["*"]
  15. }
  16. statement {
  17. effect = "Allow"
  18. actions = [ "s3:*", ]
  19. resources = [
  20. "arn:${var.aws_partition}:s3:::${aws_s3_bucket.bucket.arn}",
  21. "arn:${var.aws_partition}:s3:::${aws_s3_bucket.bucket.arn}/*",
  22. ]
  23. }
  24. }
  25. resource "aws_iam_policy" "policy" {
  26. name = "threatq_data_sync_lambda"
  27. path = "/"
  28. policy = data.aws_iam_policy_document.policy_document.json
  29. description = "IAM policy for threatq_data_sync_lambda"
  30. }
  31. resource "aws_iam_role" "role" {
  32. name = "threatq-data-sync-lambda-role"
  33. assume_role_policy = <<EOF
  34. {
  35. "Version": "2012-10-17",
  36. "Statement": [
  37. {
  38. "Sid": "",
  39. "Effect": "Allow",
  40. "Principal": {
  41. "Service": [
  42. "lambda.amazonaws.com"
  43. ]
  44. },
  45. "Action": "sts:AssumeRole"
  46. }
  47. ]
  48. }
  49. EOF
  50. }
  51. resource "aws_iam_role_policy_attachment" "policy_attachment" {
  52. role = aws_iam_role.role.name
  53. policy_arn = aws_iam_policy.policy.arn
  54. }