-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
36 lines (31 loc) · 1.11 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
# main.tf - Creates a VPC endpoint for S3 that our Lambda will use.
# Endpoint policy for the S3 endpoint
data "aws_iam_policy_document" "s3_endpoint_policy" {
statement {
actions = ["s3:putObject", "s3:getObject"]
resources = ["${aws_s3_bucket.bucket.arn}/*"]
principals {
type = "*"
identifiers = ["*"]
}
condition {
test = "ArnEquals"
variable = "aws:PrincipalArn"
values = [aws_iam_role.service_lambda_execution_role.arn] # only allow access to this endpoint from the Lambda function
}
}
}
# VPC gateway endpoint for S3. This will make sure our Lambda can access S3 without going over the internet
resource "aws_vpc_endpoint" "s3_vpce" {
vpc_id = var.vpc_id
service_name = "com.amazonaws.${var.aws_region}.s3"
vpc_endpoint_type = "Gateway"
route_table_ids = var.private_rt_ids
policy = data.aws_iam_policy_document.s3_endpoint_policy.json
tags = {
Service = var.service_name
Name = "${var.service_name}-${var.environment}-s3-vpce"
Environment = var.environment
Terraform = "true"
}
}