Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions README.md

This file was deleted.

43 changes: 43 additions & 0 deletions terraform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# How to create Static-Website-Hosting with the help of terraform.
## Pre Requisites.
1. AWS account
2. Terraform
3. VS code
4. Index.html file
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you added index.html file?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NO! it is a mistake.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you commit index.html file also?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No i didn't try this but i can try


# Deployment Steps.

Create a directory.

`mkdir directory name`

Now get into the directory. Use this command.

`cd directory name`

Now you need to create some files in this folder. use this command.

`code filename.tf`
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this command?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll use this command to open our text editer when we type e.g. "code s3 static file.tf" then our text editer will open. we can also use touch command but it is not working with VS code.


Now initialize with these command.

`terraform init`


`terraform fmt`

`terraform validate`

Now apply these to your project with the help of following command.

`terraform apply`

To see your configurations use this command.

`terraform show`

To see your bucket use this command.

`terraform state list`

Now your Static-Website is launched.
29 changes: 29 additions & 0 deletions terraform/s3-static-website/iam.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.27"
}
}

required_version = ">= 0.14.9"
}

provider "aws" {
profile = "default"
region = "us-west-2"
}
data "aws_iam_policy_document" "website_policy" {
statement {
actions = [
"s3:GetObject"
]
principals {
identifiers = ["*"]
type = "AWS"
}
resources = [
"arn:aws:s3:::mys3.terraform/*"
]
}
}
24 changes: 24 additions & 0 deletions terraform/s3-static-website/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.27"
}
}

required_version = ">= 0.14.9"
}

provider "aws" {
profile = "default"
region = "us-west-2"
}
resource "aws_s3_bucket" "b" {
bucket = "mybucket.terraform"
acl = "public-read"
policy = data.aws_iam_policy_document.website_policy.json
website {
index_document = "index.html"
error_document = "index.html"
}
}
9 changes: 9 additions & 0 deletions terraform/s3-static-website/s3.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "aws_s3_bucket" "b" {
bucket = mys3.terraform
acl = "public-read"
policy = data.aws_iam_policy_document.website_policy.json
website {
index_document = "index.html"
error_document = "index.html"
}
}