forked from plus3it/terraform-aws-codecommit-pr-reminders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
62 lines (52 loc) · 1.42 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
terraform {
required_version = ">= 0.12"
}
module "lambda" {
source = "git::https://github.com/plus3it/terraform-aws-lambda.git?ref=v1.3.0"
function_name = var.name
description = "Gather open pull requests and send it to slack"
handler = "main.lambda_handler"
runtime = "python3.6"
timeout = 30
source_path = "${path.module}/src"
policy = {
json = data.aws_iam_policy_document.this.json
}
environment = {
variables = {
SLACK_WEBHOOK = var.hook_url
LOG_LEVEL = var.log_level
DRYRUN = var.dry_run
}
}
}
# Create Cloudwatch Event Rule
resource "aws_cloudwatch_event_rule" "this" {
name = var.name
description = "Runs lambda function ${var.name} on a schedule"
schedule_expression = var.schedule
tags = var.tags
}
resource "aws_cloudwatch_event_target" "this" {
rule = aws_cloudwatch_event_rule.this.name
arn = module.lambda.function_arn
}
resource "aws_lambda_permission" "this" {
action = "lambda:InvokeFunction"
function_name = module.lambda.function_name
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.this.arn
}
### DATA SOURCES ###
data "aws_iam_policy_document" "this" {
statement {
actions = [
"codecommit:ListRepositories",
"codecommit:ListPullRequests",
"codecommit:GetPullRequest"
]
resources = [
"*"
]
}
}