-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
58 lines (46 loc) · 1.73 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
locals {
# do not enable public acl if only public is requested (this is to not modify the interface)
acl = var.acl == "public" ? "null" : var.acl
is_public = strcontains(var.acl, "public")
}
module "bucket" {
source = "terraform-aws-modules/s3-bucket/aws"
version = "4.1.2"
bucket = var.name
acl = local.acl
ignore_public_acls = var.ignore_public_acls
restrict_public_buckets = var.restrict_public_buckets
block_public_acls = var.block_public_acls
block_public_policy = var.block_public_policy
control_object_ownership = var.acl != null ? true : var.control_object_ownership
object_ownership = var.object_ownership
cors_rule = var.cors_rule
versioning = var.versioning
website = var.website
policy = local.is_public ? data.aws_iam_policy_document.public[0].json : try(data.aws_iam_policy_document.bucket_policy.0.json, "")
attach_policy = local.is_public || length(var.bucket_iam_policy) > 0 // To Do: Add support for merging two policies
}
// have initial index.html file content
resource "aws_s3_object" "index" {
count = var.create_index_html ? 1 : 0
bucket = module.bucket.s3_bucket_id
key = "index.html"
content = "OK, ${module.bucket.s3_bucket_id}"
acl = var.acl
content_type = "text/html"
lifecycle {
ignore_changes = [
content,
acl
]
}
}
// have/create some more init files into bucket
module "bucket_files" {
source = "./objects"
count = try(var.bucket_files.path, "") != "" ? 1 : 0
bucket = module.bucket.s3_bucket_id
path = var.bucket_files.path
acl = try(var.bucket_files.acl, var.acl)
pattern = try(var.bucket_files.pattern, "**")
}