Code with Terraform


POC on AWS Services like IAM, S3, Lambda, API Gateway & CloudFront using Terraform (IaC)


Terraform Architecture


S3 (Simple Storage Service)

  • Brief: 
    • An object storage service that offers industry-leading scalability, data availability, security, and performance code 
  • Files used: 

resource "aws_s3_bucket" "api_bucket" {

  bucket = "${var.myregion}-${var.bucket_name}"

  tags = {

    Name        = "${var.myregion}-${var.bucket_name}"

    Environment = "${var.environment}"

  }

}

resource "aws_s3_bucket_acl" "api_acl" {

  bucket = aws_s3_bucket.api_bucket.id

  acl    = var.acl

  depends_on = [

    aws_s3_bucket.api_bucket

  ]

}

variable "bucket_name" {

  default = ""

}

variable "environment" {

  default = ""

}

variable "myregion" {

  default = ""

}

variable "acl" {

  default = ""

}

bucket_name = "lambdabucketapi"

myregion = "us-east-1"

environment = "Dev"

acl                     = "public-read-write"

NOTE: Change values according to your Variables and service names.

resource "aws_s3_object" "object" {

  bucket = "${var.myregion}-${var.bucket_name}"

  key    = var.object_key

  source = var.object_source

  acl = var.object_acl

  etag = filemd5(var.object_source)

  depends_on = [

    aws_s3_bucket.api_bucket

  ]

}

variable "object_key" {

  default = ""

}

variable "object_source" {

  default = ""

}

variable "object_acl" {

  default = ""

}

object_key              = "sample.txt"

object_source        = "Object/sample.txt"

object_acl              = "public-read-write"

  •  Implementation Steps:

Step:1 terraform init

Text

Description automatically generated


Step:2 terraform plan:

Text

Description automatically generated


Step:3 terraform apply:

Text

Description automatically generated
Text

Description automatically generated

Lambda

  • Brief:
    • Lambda is a serverless computing service that lets you build applications that respond quickly to new information and events
  • Services used as mentioned below:
    • aws_iam_role
    • aws_iam_role_policy
    • aws_lambda_function
    • aws_s3_bucket_notification
    • aws_lambda_permission
  • File used:
  • Implementation Steps:
Step:1 terraform init:

Text

Description automatically generated


Step:2 terraform plan:

Text

Description automatically generated


Step:3 terraform apply:

Text

Description automatically generated

Text

Description automatically generated

API Gateway

  • Brief: 
    • An API gateway is an API management tool that sits between a client and a collection of backend services. An API gateway acts as a reverse proxy to accept all application programming interface (API) calls, aggregate the various services required to fulfil them and return the appropriate result.
  • Services used as mentioned below:
    • aws_iam_role
    • aws_iam_role_policy
    • aws_api_gateway_rest_api
    • aws_api_gateway_resource
    • aws_api_gateway_method
    • aws_api_gateway_integration
    • aws_api_gateway_method_response
    • aws_api_gateway_integration_response
    • aws_lambda_permission
    • aws_api_gateway_deployment
  • File used:
  • Implementation Steps:
Step:1 terraform init:


Step:2 terraform plan:


Step:3 terraform apply:

CloudFront

  • Brief: 
    • CloudFront is a fast content delivery network (CDN) service that securely delivers data, videos, applications, and APIs to customers globally with low latency, and high transfer speeds, all within a developer-friendly environment.
    • File used:
    • Implementation Steps:
    Step:1 terraform init:


    Step:2 terraform plan:


    Step:3 terraform apply:

    Terraform Backend & Terraform Output

    • Brief: 
      • A backend defines where terraform stores its state data files. Terraform Back can be anything like AWS S3, Terraform Cloud, Google cloud etc.
      • Output values return information about our infrastructure on the command line and can give information for other Terraform configurations to use. Output values are like return values in programming languages.
    • File used:
      • Implementation Steps:
      Step:1 terraform init:


      Step:2 terraform plan:


      Step:3 terraform apply:

      Git Push automation

      • Brief: 
        • A Git Push defines to push the complete code automatically in git repo “awesome_project”.
      • File used:
        • Implementation Steps:
        Step:1 terraform init:


        Step:2 terraform plan:


        Step:3 terraform apply:


        Full YouTube Video with Step by Step implementation:




        Thanks & Regards,

        Kanchan Soni(https://linktr.ee/kanchansoni
        (A girl who saw the dream with an open eye to compete with self-capability in the area of IT and its Next-Gen Technology, with the ability to complete the task with perfection.)

        Comments

        People also Look For

        All about DevOps (A Complete Guide to DevOps)

        How to Implement Microservice Coded In Hackathon Event

        Upcoming DevOps trends

        All about Cloud Computing