section-1_22.tf 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Support group check and delete function
  2. ## IAM Policy
  3. data "template_file" "support_group_check_policy" {
  4. template = file("${path.module}/templates/lambda_support_group_check_policy.json.tpl")
  5. }
  6. resource "aws_iam_role" "support_group_check" {
  7. path = "/lambda/"
  8. name = "${var.resource_name_prefix}-support-group-check"
  9. assume_role_policy = data.template_file.iam_lambda_assume_role_policy.rendered
  10. }
  11. resource "aws_iam_role_policy" "support_group_check" {
  12. name = "${var.resource_name_prefix}-lambda-support-group-check"
  13. role = aws_iam_role.support_group_check.id
  14. policy = data.template_file.support_group_check_policy.rendered
  15. }
  16. ## /IAM Policy
  17. ## Create the function
  18. data "archive_file" "support_group_check" {
  19. type = "zip"
  20. source_file = "${path.module}/files/support_group_check.py"
  21. output_path = "${var.temp_artifacts_dir}/support_group_check.zip"
  22. }
  23. resource "aws_lambda_function" "support_group_check" {
  24. filename = "${var.temp_artifacts_dir}/support_group_check.zip"
  25. function_name = "${var.resource_name_prefix}-support-group-check"
  26. role = aws_iam_role.support_group_check.arn
  27. handler = "support_group_check.lambda_handler"
  28. source_code_hash = data.archive_file.support_group_check.output_base64sha256
  29. runtime = "python2.7"
  30. timeout = var.lambda_timeout
  31. tags = merge(var.standard_tags, var.tags)
  32. }
  33. ## /Create the function
  34. ## Schedule the lambda function
  35. resource "aws_cloudwatch_event_rule" "support_group_check" {
  36. name = "${var.resource_name_prefix}-support-group-check"
  37. description = "remove expiring access keys"
  38. schedule_expression = var.lambda_cron_schedule
  39. }
  40. resource "aws_cloudwatch_event_target" "support_group_check" {
  41. rule = aws_cloudwatch_event_rule.support_group_check.name
  42. target_id = "${var.resource_name_prefix}-support-group-check"
  43. arn = aws_lambda_function.support_group_check.arn
  44. }
  45. resource "aws_lambda_permission" "support_group_check" {
  46. statement_id = "AllowExecutionFromCloudWatch"
  47. action = "lambda:InvokeFunction"
  48. function_name = aws_lambda_function.support_group_check.function_name
  49. principal = "events.amazonaws.com"
  50. source_arn = aws_cloudwatch_event_rule.support_group_check.arn
  51. }
  52. ## /Schedule the lambda function
  53. # /Support group check and delete function