This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
terraform { | |
required_providers { | |
aws = { | |
source = "hashicorp/aws" | |
version = "~> 5.0" | |
} | |
} | |
} | |
# Configure the AWS Provider |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data "aws_iam_policy_document" "sh_sqs_policy" { | |
statement { | |
sid = "shsqsstatement" | |
effect = "Allow" | |
principals { | |
type = "AWS" | |
identifiers = ["*"] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_ecrpublic_repository" "sh_ecr" { | |
repository_name = "sh_node_helloworld" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 { |
NewerOlder