-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
lambda.tf
71 lines (62 loc) · 1.55 KB
/
lambda.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
#
# Lambda function that takes care of requesting the creation and renewal of
# LetsEncrypt certificates and stores them in an S3 bucket.
#
module "certbot_lambda_jenkins" {
source = "github.com/binbashar/terraform-aws-lambda?ref=v1.2.0"
function_name = "${var.name_prefix}-${var.name}"
description = "CertBot Lambda that creates and renews certificates for ${var.certificate_domains}"
handler = "main.lambda_handler"
runtime = "python3.6"
timeout = 300
source_path = "${path.module}/src/"
trusted_entities = ["events.amazonaws.com"]
policy = {
json = data.aws_iam_policy_document.bucket_permissions.json
}
environment = {
variables = {
EMAIL = var.contact_email
DOMAINS = var.certificate_domains
S3_BUCKET = aws_s3_bucket.certificates_store.id
S3_PREFIX = var.name
}
}
}
#
# Lambda permissions on the bucket used to store certificates.
#
data "aws_iam_policy_document" "bucket_permissions" {
statement {
actions = [
"s3:ListBucket"
]
resources = [
aws_s3_bucket.certificates_store.arn
]
}
statement {
actions = [
"s3:PutObject"
]
resources = [
aws_s3_bucket.certificates_store.arn,
"${aws_s3_bucket.certificates_store.arn}/*"
]
}
statement {
actions = [
"route53:ListHostedZones",
"route53:GetChange"
]
resources = ["*"]
}
statement {
actions = [
"route53:ChangeResourceRecordSets"
]
resources = [
"arn:aws:route53:::hostedzone/${var.hosted_zone_id}"
]
}
}