From cf7b1c23c73988e782126b20f850a0e4e79f5cc3 Mon Sep 17 00:00:00 2001 From: GouseAli Date: Wed, 9 Feb 2022 21:58:43 +0500 Subject: [PATCH 1/2] Added S3 Static-Website Terraform --- README.md | 3 ++ terraform/README.md | 43 +++++++++++++++++++++++++++++ terraform/s3-static-website/iam.tf | 29 +++++++++++++++++++ terraform/s3-static-website/main.tf | 24 ++++++++++++++++ terraform/s3-static-website/s3.tf | 9 ++++++ 5 files changed, 108 insertions(+) create mode 100644 terraform/README.md create mode 100644 terraform/s3-static-website/iam.tf create mode 100644 terraform/s3-static-website/main.tf create mode 100644 terraform/s3-static-website/s3.tf diff --git a/README.md b/README.md index ce2e5e1..b34c7e9 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,6 @@ 1. Terraform 2. Ansible 3. AWS CDK + +## Pre Requisites +## Deployment Steps \ No newline at end of file diff --git a/terraform/README.md b/terraform/README.md new file mode 100644 index 0000000..9418224 --- /dev/null +++ b/terraform/README.md @@ -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 + +# 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` + +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. \ No newline at end of file diff --git a/terraform/s3-static-website/iam.tf b/terraform/s3-static-website/iam.tf new file mode 100644 index 0000000..2eef65c --- /dev/null +++ b/terraform/s3-static-website/iam.tf @@ -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/*" + ] + } +} \ No newline at end of file diff --git a/terraform/s3-static-website/main.tf b/terraform/s3-static-website/main.tf new file mode 100644 index 0000000..77ed0e8 --- /dev/null +++ b/terraform/s3-static-website/main.tf @@ -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" + } +} \ No newline at end of file diff --git a/terraform/s3-static-website/s3.tf b/terraform/s3-static-website/s3.tf new file mode 100644 index 0000000..de3a7d6 --- /dev/null +++ b/terraform/s3-static-website/s3.tf @@ -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" + } +} From dd69d9a750cc76d19283745d3b9cc9e30b4f34a1 Mon Sep 17 00:00:00 2001 From: GouseAli <89305721+GouseAli@users.noreply.github.com> Date: Wed, 9 Feb 2022 23:45:43 +0500 Subject: [PATCH 2/2] Delete README.md --- README.md | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index b34c7e9..0000000 --- a/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# DevOps Trailing Resources - -1. Terraform -2. Ansible -3. AWS CDK - -## Pre Requisites -## Deployment Steps \ No newline at end of file