diff --git a/README.md b/README.md deleted file mode 100644 index ce2e5e1..0000000 --- a/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# DevOps Trailing Resources - -1. Terraform -2. Ansible -3. AWS CDK 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" + } +}