-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.tf
77 lines (67 loc) · 2.32 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
terraform {
required_version = ">= 0.12"
}
module "lambda" {
source = "git::https://github.com/terraform-aws-modules/terraform-aws-lambda.git?ref=v7.7.1"
function_name = var.name
description = "Gather open pull requests and send it to slack"
handler = "main.lambda_handler"
artifacts_dir = var.lambda.artifacts_dir
build_in_docker = var.lambda.build_in_docker
create_package = var.lambda.create_package
ephemeral_storage_size = var.lambda.ephemeral_storage_size
ignore_source_code_hash = var.lambda.ignore_source_code_hash
local_existing_package = var.lambda.local_existing_package
memory_size = var.lambda.memory_size
recreate_missing_package = var.lambda.recreate_missing_package
runtime = var.lambda.runtime
s3_bucket = var.lambda.s3_bucket
s3_existing_package = var.lambda.s3_existing_package
s3_prefix = var.lambda.s3_prefix
store_on_s3 = var.lambda.store_on_s3
timeout = var.lambda.timeout
attach_policy_json = true
policy_json = data.aws_iam_policy_document.this.json
source_path = [
{
path = "${path.module}/src"
pip_requirements = true
patterns = ["!\\.terragrunt-source-manifest"]
}
]
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.lambda_function_arn
}
resource "aws_lambda_permission" "this" {
action = "lambda:InvokeFunction"
function_name = module.lambda.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 = [
"*"
]
}
}