forked from Kholoud-ouda/StaticWebsiteOnAWS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1-s3.tf
72 lines (69 loc) · 1.85 KB
/
1-s3.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
## S3 Bucket to host the Static website with public access policy
resource "aws_s3_bucket" "this" {
count = "${var.environmentNumber}"
bucket = "${var.frontendBucketName[count.index]}"
policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": [
"arn:aws:s3:::${var.frontendBucketName[count.index]}",
"arn:aws:s3:::${var.frontendBucketName[count.index]}/*"
]
}
]
}
POLICY
website {
index_document = "index.html"
error_document = "index.html"
}
}
## Allow public access to the bucket
resource "aws_s3_bucket_public_access_block" "this" {
count = "${var.environmentNumber}"
bucket = "${aws_s3_bucket.this[count.index].id}"
block_public_acls = false
}
resource "aws_s3_bucket" "artifactsBucket" {
bucket = "${var.project}-pipelines-artifacts"
force_destroy = false
policy = jsonencode({
"Version" : "2012-10-17",
"Id" : "SSEAndSSLPolicy",
"Statement" : [
{
"Sid" : "DenyUnEncryptedObjectUploads",
"Effect" : "Deny",
"Principal" : "*",
"Action" : "s3:PutObject",
"Resource" : "arn:aws:s3:::${var.project}-pipelines-artifacts/*",
"Condition" : {
"StringNotEquals" : {
"s3:x-amz-server-side-encryption" : "aws:kms"
}
}
},
{
"Sid" : "DenyInsecureConnections",
"Effect" : "Deny",
"Principal" : "*",
"Action" : "s3:*",
"Resource" : "arn:aws:s3:::${var.project}-pipelines-artifacts/*",
"Condition" : {
"Bool" : {
"aws:SecureTransport" : "false"
}
}
}
]
})
tags = {
Project = "${var.project}"
}
}