-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
84 lines (76 loc) · 1.94 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
78
79
80
81
82
83
resource "aws_iam_role" "rss" {
name = "rss"
inline_policy {
name = "rss-policy"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = ["*"]
Effect = "Allow"
Resource = "*"
},
]
})
}
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
data "aws_ssm_parameter" "discord_webhook" {
name = "/AWS_NEWS/DISCORD/WEBHOOK"
}
data "aws_ssm_parameter" "avatar_url" {
name = "/AWS_NEWS/DISCORD/AVATAR_URL"
}
data "aws_ssm_parameter" "color" {
name = "/AWS_NEWS/DISCORD/COLOR"
}
data "external" "rss" {
program = ["bash", "${path.module}/build.sh"]
}
data "archive_file" "rss" {
depends_on = [data.external.rss]
type = "zip"
output_file_mode = "0666"
source_file = "${path.module}/main"
output_path = "${path.module}/main.zip"
}
resource "aws_lambda_function" "rss" {
depends_on = [data.archive_file.rss]
filename = data.archive_file.rss.output_path
function_name = "rss-mapper"
description = "aws rss"
handler = "main"
runtime = "go1.x"
architectures = ["x86_64"]
memory_size = 128
timeout = 5
role = aws_iam_role.rss.arn
source_code_hash = filebase64sha256(data.archive_file.rss.output_path)
environment {
variables = {
DISCORD_WEBHOOK = data.aws_ssm_parameter.discord_webhook.value
AVATAR_URL = data.aws_ssm_parameter.avatar_url.value
COLOR = data.aws_ssm_parameter.color.value
}
}
timeouts {
create = "5m"
}
}
terraform {
backend "s3" {}
}