-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambda_artifacts_bucket.tf
56 lines (48 loc) · 1.7 KB
/
lambda_artifacts_bucket.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
# This bucket is used to store the deployment packages for any Lambda functions
# that will be used in a CyHy environment.
resource "aws_s3_bucket" "lambda_artifacts" {
bucket_prefix = var.cyhy_lambda_artifacts_s3_bucket_prefix
tags = {
"Name" = "Lambda Deployment Artifacts"
}
lifecycle {
prevent_destroy = true
}
}
# Ensure the S3 bucket is encrypted
resource "aws_s3_bucket_server_side_encryption_configuration" "lambda_artifacts" {
bucket = aws_s3_bucket.lambda_artifacts.id
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
# This blocks ANY public access to the bucket or the objects it
# contains, even if misconfigured to allow public access.
resource "aws_s3_bucket_public_access_block" "lambda_artifacts" {
block_public_acls = true
block_public_policy = true
bucket = aws_s3_bucket.lambda_artifacts.id
ignore_public_acls = true
restrict_public_buckets = true
}
# Any objects placed into this bucket should be owned by the bucket
# owner. This ensures that even if objects are added by a different
# account, the bucket-owning account retains full control over the
# objects stored in this bucket.
resource "aws_s3_bucket_ownership_controls" "lambda_artifacts" {
bucket = aws_s3_bucket.lambda_artifacts.id
rule {
object_ownership = "BucketOwnerEnforced"
}
}
# Enable versioning on the bucket. This allows Terraform to determine when a
# new version of the Lambda deployment package is uploaded and update the Lambda
# function accordingly.
resource "aws_s3_bucket_versioning" "lambda_artifacts" {
bucket = aws_s3_bucket.lambda_artifacts.id
versioning_configuration {
status = "Enabled"
}
}