Created
March 11, 2020 19:36
-
-
Save larkintuckerllc/3959ee7a3c19a75dd5af38f9ecb4a8c8 to your computer and use it in GitHub Desktop.
aws_journey
This file contains 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
provider "aws" { | |
version = "~> 2.0" | |
region = "us-east-1" | |
} | |
resource "aws_vpc" "this" { | |
cidr_block = "10.0.0.0/16" | |
} | |
resource "aws_subnet" "s0" { | |
availability_zone = "us-east-1a" | |
cidr_block = "10.0.0.0/24" | |
vpc_id = aws_vpc.this.id | |
} | |
resource "aws_subnet" "s1" { | |
availability_zone = "us-east-1b" | |
cidr_block = "10.0.1.0/24" | |
vpc_id = aws_vpc.this.id | |
} | |
resource "aws_subnet" "s2" { | |
availability_zone = "us-east-1c" | |
cidr_block = "10.0.2.0/24" | |
vpc_id = aws_vpc.this.id | |
} | |
resource "aws_internet_gateway" "this" { | |
vpc_id = aws_vpc.this.id | |
} | |
resource "aws_route_table" "this" { | |
vpc_id = aws_vpc.this.id | |
route { | |
cidr_block = "0.0.0.0/0" | |
gateway_id = aws_internet_gateway.this.id | |
} | |
} | |
resource "aws_route_table_association" "s0" { | |
subnet_id = aws_subnet.s0.id | |
route_table_id = aws_route_table.this.id | |
} | |
resource "aws_route_table_association" "s1" { | |
subnet_id = aws_subnet.s1.id | |
route_table_id = aws_route_table.this.id | |
} | |
resource "aws_route_table_association" "s2" { | |
subnet_id = aws_subnet.s2.id | |
route_table_id = aws_route_table.this.id | |
} | |
resource "aws_network_acl" "this" { | |
egress { | |
protocol = "-1" | |
rule_no = 100 | |
action = "allow" | |
cidr_block = "0.0.0.0/0" | |
from_port = 0 | |
to_port = 0 | |
} | |
ingress { | |
protocol = "-1" | |
rule_no = 100 | |
action = "allow" | |
cidr_block = "0.0.0.0/0" | |
from_port = 0 | |
to_port = 0 | |
} | |
subnet_ids = [ | |
aws_subnet.s0.id, | |
aws_subnet.s1.id, | |
aws_subnet.s2.id | |
] | |
vpc_id = aws_vpc.this.id | |
} | |
resource "aws_security_group" "this" { | |
egress { | |
cidr_blocks = ["0.0.0.0/0"] | |
from_port = 0 | |
protocol = "-1" | |
to_port = 0 | |
} | |
ingress { | |
cidr_blocks = ["0.0.0.0/0"] | |
from_port = 80 | |
protocol = "tcp" | |
to_port = 80 | |
} | |
ingress { | |
cidr_blocks = ["0.0.0.0/0"] | |
from_port = 22 | |
protocol = "tcp" | |
to_port = 22 | |
} | |
vpc_id = aws_vpc.this.id | |
} | |
data "aws_ami" "this" { | |
filter { | |
name = "name" | |
values = ["amzn2-ami-hvm-2.0.20200207.1-x86_64-gp2"] | |
} | |
most_recent = true | |
owners = ["amazon"] | |
} | |
resource "aws_launch_configuration" "this" { | |
associate_public_ip_address = true | |
image_id = data.aws_ami.this.id | |
name_prefix = "todosrus-" | |
instance_type = "t2.micro" | |
lifecycle { | |
create_before_destroy = true | |
ignore_changes = [ image_id ] | |
} | |
security_groups = [aws_security_group.this.id] | |
user_data = <<EOF | |
#!/bin/bash | |
yum update -y | |
yum install httpd -y | |
service httpd start | |
chkconfig httpd on | |
cd /var/www/html | |
echo "<html><h1>This is WebServer 01</h1></html>" > index.html | |
EOF | |
} | |
resource "aws_lb_target_group" "this" { | |
port = 80 | |
protocol = "HTTP" | |
vpc_id = aws_vpc.this.id | |
} | |
resource "aws_autoscaling_group" "this" { | |
desired_capacity = 3 | |
launch_configuration = aws_launch_configuration.this.name | |
lifecycle { | |
create_before_destroy = true | |
} | |
min_size = 3 | |
max_size = 3 | |
name = aws_launch_configuration.this.name | |
target_group_arns = [aws_lb_target_group.this.arn] | |
vpc_zone_identifier = [ | |
aws_subnet.s0.id, | |
aws_subnet.s1.id, | |
aws_subnet.s2.id | |
] | |
} | |
resource "aws_lb" "this" { | |
internal = false | |
load_balancer_type = "application" | |
security_groups = [aws_security_group.this.id] | |
subnets = [ | |
aws_subnet.s0.id, | |
aws_subnet.s1.id, | |
aws_subnet.s2.id | |
] | |
} | |
resource "aws_lb_listener" "this" { | |
default_action { | |
type = "forward" | |
target_group_arn = aws_lb_target_group.this.arn | |
} | |
load_balancer_arn = aws_lb.this.arn | |
port = "80" | |
protocol = "HTTP" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment