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"
- File used: Object Upload
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:2 terraform plan:
Step:3 terraform apply:
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:2 terraform plan:
Step:3 terraform apply:
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:
- 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:
- 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:
- Brief:
- A Git Push defines to push the complete code automatically in git repo “awesome_project”.
- File used:
- Implementation Steps:
Full YouTube Video with Step by Step implementation:
Comments
Post a Comment