-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b426f7c
Showing
7 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Agenda | ||
if you want to create a static web site with s3 you have to create some resources | ||
1. bucket | ||
2. route53 | ||
3. iam | ||
> | ||
> you have to use a domain for this configuration | ||
> I've used `babak.local`. you can use anything you want.don't worry you don't need to buy a domain name for that | ||
|
||
|
||
|
||
|
||
after you apply terraform configuration on you aws you can copy your static website into the bucket | ||
## AWS CLI Command | ||
`aws s3 sync staticSite s3://babak.local` | ||
--- | ||
with this command you copy all the files within the staticSite folder | ||
|
||
## What is your web site url ? | ||
you can find it with this formula below | ||
|
||
`http://bucket-name.s3-website-Region.amazonaws.com` | ||
|
||
for example here bucket-name is `babak.local` and region is `eu-west-1` | ||
so the url is | ||
`http://babak.local.s3-website-eu-west-1.amazonaws.com` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
#//////////////////////////////// | ||
# IAM policy for S3 | ||
#//////////////////////////////// | ||
data "aws_iam_policy_document" "website_policy" { | ||
statement { | ||
actions = [ | ||
"s3:GetObject" | ||
] | ||
principals { | ||
identifiers = ["*"] | ||
type = "AWS" | ||
} | ||
resources = [ | ||
"arn:aws:s3:::${var.domain_name}/*" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
#//////////////////////////////// | ||
# aws_s3_bucket | ||
#//////////////////////////////// | ||
resource "aws_s3_bucket" "website_bucket" { | ||
bucket = var.domain_name | ||
acl = "public-read" | ||
policy = data.aws_iam_policy_document.website_policy.json | ||
website { | ||
index_document = "index.html" | ||
error_document = "index.html" | ||
} | ||
} | ||
|
||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
#//////////////////////////////// | ||
# Route 53 | ||
#//////////////////////////////// | ||
resource "aws_route53_zone" "primary" { | ||
name = var.domain_name | ||
} | ||
|
||
resource "aws_route53_record" "www" { | ||
zone_id = aws_route53_zone.primary.zone_id | ||
name = var.domain_name | ||
type = "A" | ||
alias { | ||
name = aws_s3_bucket.website_bucket.website_domain | ||
zone_id = aws_s3_bucket.website_bucket.hosted_zone_id | ||
evaluate_target_health = false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Document</title> | ||
</head> | ||
<style> | ||
html, | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
} | ||
body { | ||
background: url("https://images.unsplash.com/photo-1604537466158-719b1972feb8"); | ||
background-size: cover; | ||
background-repeat: no-repeat; | ||
width: 100vw; | ||
height: 100vh; | ||
} | ||
@media screen and (max-width: 800px) { | ||
html { | ||
font-size: 10px; | ||
} | ||
} | ||
@media screen and (max-width: 600px) { | ||
html { | ||
font-size: 9px; | ||
} | ||
} | ||
div { | ||
position: absolute; | ||
|
||
background-color: rgb(224, 224, 224, 0.6); | ||
padding: 10rem 20rem; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
text-align: center; | ||
} | ||
</style> | ||
<body> | ||
<div> | ||
<h1>Viva Terraform</h1> | ||
<h4>you can replace your code!</h4> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
variable "domain_name" { | ||
type = string | ||
} |