~repos /website
git clone https://pyrossh.dev/repos/website.git
木 Personal website of pyrossh. Built with astrojs, shiki, vite.
53c2978e
—
pyrossh 6 months ago
add infra code
- deploy.sh +1 -1
- infra/.terraform.lock.hcl +24 -0
- infra/main.tf +180 -0
deploy.sh
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
rm -rf dist
|
|
2
2
|
bun run build
|
|
3
3
|
aws s3 sync --delete ./dist/ s3://pyrossh-website
|
|
4
|
-
aws cloudfront create-invalidation --distribution-id E2KFT51L97LWA1 --paths "/*"
|
|
4
|
+
aws cloudfront create-invalidation --distribution-id E2KFT51L97LWA1 --paths "/*" --no-cli-pager
|
|
5
5
|
cd infra && terraform apply -auto-approve
|
infra/.terraform.lock.hcl
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# This file is maintained automatically by "terraform init".
|
|
2
|
+
# Manual edits may be lost in future updates.
|
|
3
|
+
|
|
4
|
+
provider "registry.terraform.io/hashicorp/aws" {
|
|
5
|
+
version = "5.99.1"
|
|
6
|
+
hashes = [
|
|
7
|
+
"h1:xgPyZArCfKVMy8sThzhb0IernbFy0fJGm897ztejZAQ=",
|
|
8
|
+
"zh:00b0a61c6d295300f0aa7a79a7d40e9f836164f1fff816d38324c148cd846887",
|
|
9
|
+
"zh:1ee9d5ccb67378704642db62113ac6c0d56d69408a9c1afb9a8e14b095fc0733",
|
|
10
|
+
"zh:2035977ed418dcb18290785c1eeb79b7133b39f718c470346e043ac48887ffc7",
|
|
11
|
+
"zh:67e3ca1bf7061900f81cf958d5c771a2fd6048c2b185bec7b27978349b173a90",
|
|
12
|
+
"zh:87fadbe5de7347ede72ad879ff8d8d9334103cd9aa4a321bb086bfac91654944",
|
|
13
|
+
"zh:901d170c457c2bff244a2282d9de595bdb3ebecc33a2034c5ce8aafbcff66db9",
|
|
14
|
+
"zh:92c07d6cf530679565b87934f9f98604652d787968cce6a3d24c148479b7e34b",
|
|
15
|
+
"zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425",
|
|
16
|
+
"zh:a7d4803b4c5ff17f029f8b270c91480442ece27cec7922c38548bcfea2ac2d26",
|
|
17
|
+
"zh:afda848da7993a07d29018ec25ab6feda652e01d4b22721da570ce4fcc005292",
|
|
18
|
+
"zh:baaf16c98b81bad070e0908f057a97108ecd6e8c9f754d7a79b18df4c8453279",
|
|
19
|
+
"zh:c3dd496c5014427599d6b6b1c14c7ebb09a15df78918ae0be935e7bfa83b894c",
|
|
20
|
+
"zh:e2b84c1d40b3f2c4b1d74bf170b9e932983b61bac0e6dab2e36f5057ddcc997f",
|
|
21
|
+
"zh:e49c92cb29c53b4573ed4d9c946486e6bcfc1b63f1aee0c79cc7626f3d9add03",
|
|
22
|
+
"zh:efae8e339c4b13f546e0f96c42eb95bf8347de22e941594849b12688574bf380",
|
|
23
|
+
]
|
|
24
|
+
}
|
infra/main.tf
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
provider "aws" {
|
|
2
|
+
region = "ap-south-1"
|
|
3
|
+
default_tags {
|
|
4
|
+
tags = {
|
|
5
|
+
Environment = "Production"
|
|
6
|
+
ProvisionedBy = "Terraform"
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
provider "aws" {
|
|
12
|
+
alias = "useast"
|
|
13
|
+
region = "us-east-1"
|
|
14
|
+
default_tags {
|
|
15
|
+
tags = {
|
|
16
|
+
Environment = "Production"
|
|
17
|
+
ProvisionedBy = "Terraform"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
resource "aws_route53_zone" "main" {
|
|
23
|
+
name = "pyrossh.dev"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
resource "aws_s3_bucket" "website" {
|
|
27
|
+
bucket = "pyrossh-website"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
# resource "aws_s3_bucket_acl" "website" {
|
|
31
|
+
# bucket = aws_s3_bucket.website.id
|
|
32
|
+
# acl = "private"
|
|
33
|
+
# }
|
|
34
|
+
|
|
35
|
+
# resource "aws_s3_bucket_website_configuration" "s3_bucket" {
|
|
36
|
+
# bucket = aws_s3_bucket.website.id
|
|
37
|
+
|
|
38
|
+
# index_document {
|
|
39
|
+
# suffix = "index.html"
|
|
40
|
+
# }
|
|
41
|
+
|
|
42
|
+
# error_document {
|
|
43
|
+
# key = "error.html"
|
|
44
|
+
# }
|
|
45
|
+
|
|
46
|
+
# }
|
|
47
|
+
|
|
48
|
+
resource "aws_s3_bucket_public_access_block" "website_public_access" {
|
|
49
|
+
bucket = aws_s3_bucket.website.id
|
|
50
|
+
block_public_acls = true
|
|
51
|
+
block_public_policy = true
|
|
52
|
+
ignore_public_acls = true
|
|
53
|
+
restrict_public_buckets = true
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
resource "aws_cloudfront_origin_access_control" "website" {
|
|
57
|
+
name = "s3-cloudfront-oac"
|
|
58
|
+
description = "Grant cloudfront access to s3 bucket ${aws_s3_bucket.website.id}"
|
|
59
|
+
origin_access_control_origin_type = "s3"
|
|
60
|
+
signing_behavior = "always" // "no-override"
|
|
61
|
+
signing_protocol = "sigv4"
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
data "aws_iam_policy_document" "cloudfront_oac_access" {
|
|
65
|
+
statement {
|
|
66
|
+
principals {
|
|
67
|
+
type = "Service"
|
|
68
|
+
identifiers = ["cloudfront.amazonaws.com"]
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
actions = [
|
|
72
|
+
"s3:GetObject"
|
|
73
|
+
]
|
|
74
|
+
|
|
75
|
+
resources = [
|
|
76
|
+
aws_s3_bucket.website.arn,
|
|
77
|
+
"${aws_s3_bucket.website.arn}/*"
|
|
78
|
+
]
|
|
79
|
+
|
|
80
|
+
condition {
|
|
81
|
+
test = "StringEquals"
|
|
82
|
+
variable = "AWS:SourceArn"
|
|
83
|
+
values = [aws_cloudfront_distribution.s3_distribution.arn]
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
resource "aws_s3_bucket_policy" "website_access_policy" {
|
|
89
|
+
bucket = aws_s3_bucket.website.id
|
|
90
|
+
policy = data.aws_iam_policy_document.cloudfront_oac_access.json
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
resource "aws_acm_certificate" "domain_ssl_certificate" {
|
|
95
|
+
domain_name = "pyrossh.dev"
|
|
96
|
+
validation_method = "EMAIL"
|
|
97
|
+
provider = aws.useast
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
resource "aws_cloudfront_function" "subdirectory_redirector" {
|
|
101
|
+
name = "subdirectory_redirector"
|
|
102
|
+
runtime = "cloudfront-js-2.0"
|
|
103
|
+
publish = true
|
|
104
|
+
code = <<CODE
|
|
105
|
+
function handler(event) {
|
|
106
|
+
const request = event.request;
|
|
107
|
+
const uri = request.uri;
|
|
108
|
+
|
|
109
|
+
if (uri.endsWith('/')) {
|
|
110
|
+
request.uri += 'index.html';
|
|
111
|
+
} else if (!uri.includes('.')) {
|
|
112
|
+
request.uri += '/index.html';
|
|
113
|
+
}
|
|
114
|
+
return request;
|
|
115
|
+
}
|
|
116
|
+
CODE
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
resource "aws_cloudfront_distribution" "s3_distribution" {
|
|
120
|
+
origin {
|
|
121
|
+
domain_name = aws_s3_bucket.website.bucket_regional_domain_name
|
|
122
|
+
origin_id = aws_s3_bucket.website.bucket_regional_domain_name
|
|
123
|
+
origin_access_control_id = aws_cloudfront_origin_access_control.website.id
|
|
124
|
+
}
|
|
125
|
+
enabled = true
|
|
126
|
+
is_ipv6_enabled = true
|
|
127
|
+
aliases = ["pyrossh.dev"]
|
|
128
|
+
default_root_object = "index.html"
|
|
129
|
+
|
|
130
|
+
dynamic "custom_error_response" {
|
|
131
|
+
for_each = [400, 403, 404, 405, 414, 416, 500, 501, 502, 503, 504]
|
|
132
|
+
content {
|
|
133
|
+
error_code = custom_error_response.value
|
|
134
|
+
response_code = custom_error_response.value
|
|
135
|
+
response_page_path = custom_error_response.value < 500 ? "/404.html" : "/500.html"
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
default_cache_behavior {
|
|
140
|
+
allowed_methods = ["GET", "HEAD"]
|
|
141
|
+
cached_methods = ["GET", "HEAD"]
|
|
142
|
+
target_origin_id = aws_s3_bucket.website.bucket_regional_domain_name
|
|
143
|
+
forwarded_values {
|
|
144
|
+
query_string = true
|
|
145
|
+
cookies {
|
|
146
|
+
forward = "none"
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
viewer_protocol_policy = "redirect-to-https"
|
|
150
|
+
min_ttl = 0
|
|
151
|
+
default_ttl = 3600
|
|
152
|
+
max_ttl = 86400
|
|
153
|
+
# function_association {
|
|
154
|
+
# event_type = "viewer-request"
|
|
155
|
+
# function_arn = aws_cloudfront_function.subdirectory_redirector.arn
|
|
156
|
+
# }
|
|
157
|
+
}
|
|
158
|
+
price_class = "PriceClass_All"
|
|
159
|
+
restrictions {
|
|
160
|
+
geo_restriction {
|
|
161
|
+
restriction_type = "none"
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
viewer_certificate {
|
|
165
|
+
cloudfront_default_certificate = false
|
|
166
|
+
acm_certificate_arn = aws_acm_certificate.domain_ssl_certificate.arn
|
|
167
|
+
ssl_support_method = "sni-only"
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
resource "aws_route53_record" "a_record_domain" {
|
|
172
|
+
zone_id = aws_route53_zone.main.zone_id
|
|
173
|
+
name = "pyrossh.dev"
|
|
174
|
+
type = "A"
|
|
175
|
+
alias {
|
|
176
|
+
name = aws_cloudfront_distribution.s3_distribution.domain_name
|
|
177
|
+
zone_id = aws_cloudfront_distribution.s3_distribution.hosted_zone_id
|
|
178
|
+
evaluate_target_health = false #
|
|
179
|
+
}
|
|
180
|
+
}
|