Skip to content

Commit

Permalink
all files
Browse files Browse the repository at this point in the history
  • Loading branch information
babakDoraniArab committed Jan 22, 2022
0 parents commit b426f7c
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 0 deletions.
26 changes: 26 additions & 0 deletions README.md
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`
18 changes: 18 additions & 0 deletions iam_policy.tf
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}/*"
]
}
}
15 changes: 15 additions & 0 deletions main.tf
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 added output.tf
Empty file.
18 changes: 18 additions & 0 deletions route53.tf
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
}
}
50 changes: 50 additions & 0 deletions staticSite/index.html
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>
3 changes: 3 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variable "domain_name" {
type = string
}

0 comments on commit b426f7c

Please sign in to comment.