Skip to content

Instantly share code, notes, and snippets.

View SharmilaS22's full-sized avatar
🎯
Focusing

Sharmila S SharmilaS22

🎯
Focusing
View GitHub Profile
@SharmilaS22
SharmilaS22 / main5.tf
Created February 25, 2024 10:28
Terraform provider block for aws
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
# Configure the AWS Provider
@SharmilaS22
SharmilaS22 / sqs-policy.tf
Created July 4, 2023 16:09
Policies for the sqs queue
data "aws_iam_policy_document" "sh_sqs_policy" {
statement {
sid = "shsqsstatement"
effect = "Allow"
principals {
type = "AWS"
identifiers = ["*"]
}
@SharmilaS22
SharmilaS22 / sqs.tf
Last active July 4, 2023 15:37
SQS Queue with the properties
resource "aws_sqs_queue" "sh_queue" {
name = "sh-example-queue"
delay_seconds = 10
visibility_timeout_seconds = 30
max_message_size = 2048
message_retention_seconds = 86400
receive_wait_time_seconds = 2
sqs_managed_sse_enabled = true
}
resource "aws_ecrpublic_repository" "sh_ecr" {
repository_name = "sh_node_helloworld"
}
@SharmilaS22
SharmilaS22 / vpc.tf
Created July 3, 2023 13:35
VPC and subnets
# VPC
resource "aws_vpc" "sh_main" {
cidr_block = "10.0.0.0/23" # 512 IPs
tags = {
Name = "sharmi-vpc"
}
}
# Creating public subnet
resource "aws_subnet" "sh_subnet_1" {
@SharmilaS22
SharmilaS22 / sg.tf
Created June 18, 2023 15:16
Security groups for EC2 and Application Load Balancer
resource "aws_security_group" "sh_sg_for_elb" {
name = "sharmi-sg_for_elb"
vpc_id = aws_vpc.sh_main.id
ingress {
description = "Allow http request from anywhere"
protocol = "tcp"
from_port = 80
to_port = 80
cidr_blocks = ["0.0.0.0/0"]
@SharmilaS22
SharmilaS22 / lb-with-targetGroup.tf
Created June 18, 2023 15:13
Application Load balancer open to internet, with a target group
resource "aws_lb" "sh_lb" {
name = "sharmi-lb-asg"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.sh_sg_for_elb.id]
subnets = [aws_subnet.sh_subnet_1.id, aws_subnet.sh_subnet_1a.id]
depends_on = [aws_internet_gateway.sh_gw]
}
resource "aws_lb_target_group" "sh_alb_tg" {
@SharmilaS22
SharmilaS22 / ec2-with-asg.tf
Created June 18, 2023 15:10
Autoscaling group with launch templates for creating EC2 instances
# ASG with Launch template
resource "aws_launch_template" "sh_ec2_launch_templ" {
name_prefix = "sh_ec2_launch_templ"
image_id = "ami-00c39f71452c08778" # To note: AMI is specific for each region
instance_type = "t2.micro"
user_data = filebase64("user_data.sh")
network_interfaces {
associate_public_ip_address = false
subnet_id = aws_subnet.sh_subnet_2.id
@SharmilaS22
SharmilaS22 / gateways-private.tf
Last active February 25, 2024 10:30
Routetables for Private subnets with NAT and EIP
# Elastic IP for NAT gateway
resource "aws_eip" "sh_eip" {
depends_on = [aws_internet_gateway.sh_gw]
domain = "vpc"
tags = {
Name = "sh_EIP_for_NAT"
}
}
# NAT gateway for private subnets
@SharmilaS22
SharmilaS22 / gateways-public.tf
Created June 18, 2023 15:03
AWS Routetables for public subnet
# Internet Gateway
resource "aws_internet_gateway" "sh_gw" {
vpc_id = aws_vpc.sh_main.id
}
# route table for public subnet - connecting to Internet gateway
resource "aws_route_table" "sh_rt_public" {
vpc_id = aws_vpc.sh_main.id
route {