-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
61 lines (51 loc) · 1.47 KB
/
main.tf
File metadata and controls
61 lines (51 loc) · 1.47 KB
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
resource "aws_s3_bucket" "this" {
bucket = var.bucket_name
region = var.region
acl = var.acl
force_destroy = var.force_destroy
versioning {
enabled = var.versioning_enabled ? true : false
mfa_delete = var.versioning_mfa_delete ? true : false
}
server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = var.sse_algorithm
}
}
}
tags = var.tags
}
data "template_file" "this" {
template = file(var.policy_path)
vars = {
account_id = var.account_id
bucket_name = var.bucket_name
}
}
resource "aws_s3_bucket_policy" "this" {
bucket = aws_s3_bucket.this.id
policy = data.template_file.this.rendered
#policy = var.policy
}
# Fix the issue with aws_s3_bucket_public_access_block creation
resource "null_resource" "delay" {
depends_on = [aws_s3_bucket.this]
provisioner "local-exec" {
command = "sleep 5"
}
}
resource "aws_s3_bucket_public_access_block" "this" {
bucket = aws_s3_bucket.this.id
block_public_acls = var.block_public_acls
block_public_policy = var.block_public_policy
ignore_public_acls = var.ignore_public_acls
restrict_public_buckets = var.restrict_public_buckets
depends_on = [null_resource.delay]
}
resource "aws_s3_bucket_object" "this" {
count = length(var.keys) == 0 ? 0 : length(var.keys)
bucket = aws_s3_bucket.this.id
key = var.keys[count.index]
source = "/dev/null"
}