forked from anubhavmishra/terraform-github-actions-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
71 lines (54 loc) · 1.32 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
59
60
61
62
63
64
65
66
67
68
69
70
71
provider "aws" {
region = "us-west-2"
}
resource "aws_s3_bucket" "website_www" {
bucket = "www.${var.domain_example}"
acl = "public-read"
policy = data.aws_iam_policy_document.bucket_policy.json
website {
index_document = "index.html"
error_document = "error.html"
}
}
resource "aws_s3_bucket" "website_subdomain" {
bucket = var.domain_example
acl = "private"
policy = ""
website {
redirect_all_requests_to = "https://www.${var.domain_example}"
}
}
data "aws_iam_policy_document" "bucket_policy" {
statement {
sid = "AllowedIPReadAccess"
actions = [
"s3:GetObject",
]
resources = [
"arn:aws:s3:::www.${var.domain_example}/*",
]
condition {
test = "IpAddress"
variable = "aws:SourceIp"
values = ["0.0.0.0/0"]
}
principals {
type = "*"
identifiers = ["*"]
}
}
}
resource "aws_s3_bucket_object" "website_example" {
key = "index.html"
bucket = aws_s3_bucket.website_www.id
source = "index.html"
content_type = "text/html"
etag = filemd5("index.html")
}
resource "aws_s3_bucket_object" "website_error" {
key = "error.html"
bucket = aws_s3_bucket.website_www.id
source = "error.html"
content_type = "text/html"
etag = filemd5("error.html")
}