2020-02-13 09:46:46 -08:00
|
|
|
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------------------------------------
|
|
|
|
# IAM Role for Redirect Lambda
|
|
|
|
|
2021-08-11 10:20:45 -07:00
|
|
|
data "aws_iam_policy_document" "lambda_redirect" {
|
|
|
|
statement {
|
|
|
|
actions = ["sts:AssumeRole"]
|
|
|
|
|
|
|
|
principals {
|
|
|
|
type = "Service"
|
|
|
|
identifiers = [
|
|
|
|
"edgelambda.amazonaws.com",
|
|
|
|
"lambda.amazonaws.com"
|
|
|
|
]
|
2020-02-13 09:46:46 -08:00
|
|
|
}
|
2021-08-11 10:20:45 -07:00
|
|
|
}
|
2020-02-13 09:46:46 -08:00
|
|
|
}
|
2021-08-11 10:20:45 -07:00
|
|
|
|
|
|
|
resource "aws_iam_role" "lambda_redirect" {
|
|
|
|
name = "${var.site}-lambda-redirect-role"
|
|
|
|
assume_role_policy = data.aws_iam_policy_document.lambda_redirect.json
|
2020-02-13 09:46:46 -08:00
|
|
|
|
|
|
|
tags = {
|
|
|
|
Site = var.site
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-19 12:58:46 -08:00
|
|
|
#######################################################
|
|
|
|
# LOGGING POLICY
|
2020-02-13 09:46:46 -08:00
|
|
|
|
2023-02-19 12:58:46 -08:00
|
|
|
data "aws_iam_policy_document" "lambda_logging" {
|
2021-03-01 12:40:35 -08:00
|
|
|
statement {
|
|
|
|
actions = [
|
2023-02-19 12:58:46 -08:00
|
|
|
"logs:CreateLogStream",
|
|
|
|
"logs:PutLogEvents",
|
|
|
|
"logs:CreateLogGroup"
|
2021-03-01 12:40:35 -08:00
|
|
|
]
|
|
|
|
|
2023-02-19 12:58:46 -08:00
|
|
|
resources = [ "arn:aws:logs:*:*:*" ]
|
2021-03-01 12:40:35 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-19 12:58:46 -08:00
|
|
|
resource "aws_iam_policy" "lambda_logging" {
|
|
|
|
name = "${var.site}_lambda_logging"
|
|
|
|
path = "/"
|
|
|
|
description = "IAM policy for logging from a lambda"
|
2021-03-01 12:40:35 -08:00
|
|
|
|
2023-02-19 12:58:46 -08:00
|
|
|
policy = data.aws_iam_policy_document.lambda_logging.json
|
2020-02-13 09:46:46 -08:00
|
|
|
}
|
2021-03-01 12:40:35 -08:00
|
|
|
|
2023-02-19 12:58:46 -08:00
|
|
|
resource "aws_iam_role_policy_attachment" "lambda_logs" {
|
|
|
|
role = aws_iam_role.lambda_redirect.name
|
|
|
|
policy_arn = aws_iam_policy.lambda_logging.arn
|
|
|
|
}
|
2021-03-01 12:40:35 -08:00
|
|
|
|
2023-02-19 12:58:46 -08:00
|
|
|
#######################################################
|
|
|
|
# REPLICATION POLICY
|
2020-02-13 09:46:46 -08:00
|
|
|
|
2023-02-19 12:58:46 -08:00
|
|
|
# aws_iam_policy_document.lambda_replication
|
|
|
|
data "aws_iam_policy_document" "lambda_replication" {
|
|
|
|
statement {
|
|
|
|
actions = [
|
|
|
|
"lambda:EnableReplication*",
|
|
|
|
]
|
|
|
|
resources = [
|
|
|
|
"*"
|
|
|
|
]
|
2020-02-13 09:46:46 -08:00
|
|
|
}
|
|
|
|
|
2023-02-19 12:58:46 -08:00
|
|
|
statement {
|
|
|
|
actions = [
|
|
|
|
"iam:CreateServiceLinkedRole"
|
|
|
|
]
|
|
|
|
resources = [
|
|
|
|
"arn:aws:iam::*:role/aws-service-role/events.amazonaws.com/AWSServiceRoleForCloudWatchEvents*"
|
|
|
|
]
|
|
|
|
condition {
|
|
|
|
test = "StringLike"
|
|
|
|
variable = "iam:AWSServiceName"
|
|
|
|
values = ["events.amazonaws.com"]
|
|
|
|
}
|
|
|
|
}
|
2021-03-01 12:40:35 -08:00
|
|
|
}
|
2020-02-13 09:46:46 -08:00
|
|
|
|
2023-02-19 12:58:46 -08:00
|
|
|
resource "aws_iam_policy" "lambda_replication" {
|
|
|
|
name = "${var.site}_lambda_replication"
|
|
|
|
path = "/"
|
|
|
|
description = "IAM policy for replication by lambda@edge"
|
2021-03-02 16:20:35 -08:00
|
|
|
|
2023-02-19 12:58:46 -08:00
|
|
|
policy = data.aws_iam_policy_document.lambda_replication.json
|
2020-02-13 09:46:46 -08:00
|
|
|
}
|
2021-03-01 12:40:35 -08:00
|
|
|
|
2023-02-19 12:58:46 -08:00
|
|
|
resource "aws_iam_role_policy_attachment" "lambda_replication" {
|
|
|
|
role = aws_iam_role.lambda_redirect.name
|
|
|
|
policy_arn = aws_iam_policy.lambda_replication.arn
|
2020-02-13 09:46:46 -08:00
|
|
|
}
|
2023-02-19 12:58:46 -08:00
|
|
|
|