-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
72 lines (60 loc) · 1.5 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
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
}
module "lambda" {
source = "armorfret/lambda/aws"
version = "0.1.0"
source_bucket = var.lambda_bucket
source_version = var.lambda_version
function_name = "hookshot_${var.config_bucket}"
environment_variables = {
S3_BUCKET = var.config_bucket
S3_KEY = "config.yaml"
}
access_policy_document = data.aws_iam_policy_document.lambda_perms.json
source_types = ["events"]
source_arns = [aws_cloudwatch_event_rule.cron.arn]
}
resource "aws_cloudwatch_event_rule" "cron" {
name = "hookshot_${var.config_bucket}_cron"
description = "Launch lambda"
schedule_expression = "rate(${var.rate})"
}
resource "aws_cloudwatch_event_target" "cron" {
rule = aws_cloudwatch_event_rule.cron.name
target_id = "invoke_hookshot"
arn = module.lambda.arn
}
module "publish-user" {
source = "armorfret/s3-publish/aws"
version = "0.2.4"
logging_bucket = var.logging_bucket
publish_bucket = var.config_bucket
}
data "aws_iam_policy_document" "lambda_perms" {
statement {
actions = [
"s3:ListBucket",
"s3:GetObject",
]
resources = [
"arn:aws:s3:::${var.config_bucket}/*",
"arn:aws:s3:::${var.config_bucket}",
]
}
statement {
actions = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
]
resources = [
"arn:aws:logs:*:*:*",
]
}
}