Build your resume in AWS S3

Local Folder Setup

  1. Create a directory in your local environment
  2. Inside that directory create a folder called terraform
  3. Create two files inside that directory main.tf and provider.tf
  4. Contents of provider.tf
     1terraform {
     2     required_providers {
     3         aws = {
     4         source  = "hashicorp/aws"
     5         version = "~> 4.0"
     6         }
     7     }
     8 }
     9
    10 # Configure the AWS Provider
    11 provider "aws" {
    12     region = "us-east-1"
    13 }
    
  5. Open Terminal
  6. Set the following environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
    1. For Linux
      1export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
      2export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
      
    2. For Windows
      1setx AWS_ACCESS_KEY_ID AKIAIOSFODNN7EXAMPLE
      2setx AWS_SECRET_ACCESS_KEY wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
      
  7. Initialize the current terraform directory
    1terraform init
    
  8. Validate the all the configurations by running
    1terraform validate
    
  9. Insert the below contents in your main.tf file
     1# your bucket name
     2variable "bucket_name" {
     3    default = "datavedam-bucket"
     4}
     5
     6resource "aws_s3_bucket" "web_bucket" {
     7  bucket        = var.bucket_name
     8  force_destroy = true
     9  tags = {
    10    Name        = "My Website"
    11    Environment = "Dev"
    12  }
    13}
    14
    15resource "aws_s3_bucket_acl" "bucket_acl" {
    16  bucket = aws_s3_bucket.web_bucket.id
    17  acl    = "public-read"
    18}
    19
    20resource "aws_s3_bucket_website_configuration" "web_config" {
    21  bucket = aws_s3_bucket.web_bucket.bucket
    22  index_document {
    23    suffix = "index.html"
    24  }
    25  error_document {
    26    key = "error.html"
    27  }
    28}
    29
    30resource "aws_s3_bucket_policy" "bucket_policy" {
    31  bucket = aws_s3_bucket.web_bucket.bucket
    32  policy = <<POLICY
    33  {
    34    "Version": "2012-10-17",
    35    "Statement": [
    36        {
    37            "Sid": "PublicReadGetObject",
    38            "Effect": "Allow",
    39            "Principal": "*",
    40            "Action": "s3:GetObject",
    41            "Resource": "arn:aws:s3:::${var.bucket_name}/*"
    42        }
    43    ]
    44  }
    45  POLICY
    46}
    
  10. See what resource will be created in aws
    1terraform plan
    
  11. Create the bucket
    1terraform apply
    
  12. Follow the link to upload your resume.