Skip to content

Instantly share code, notes, and snippets.

View AndrewBestbier's full-sized avatar

Andrew AndrewBestbier

  • McKinsey & Company
  • London
View GitHub Profile
resource "aws_ecs_cluster" "my_cluster" {
name = "my-cluster" # Naming the cluster
}
provider "aws" {
version = "~> 2.0"
region = "eu-west-2" # Setting my region to London. Use your own region here
}
resource "aws_ecr_repository" "my_first_ecr_repo" {
name = "my-first-ecr-repo" # Naming my repository
}
AWSTemplateFormatVersion: 2010-09-09
Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
PublicSubnetA:
Type: AWS::EC2::Subnet
Database:
Type: AWS::RDS::DBInstance # (1)
Properties:
VPCSecurityGroups:
- !Ref DbSecurityGroup # (2)
AllocatedStorage: "10"
DBSubnetGroupName: !Ref DbSubnetGroup # (3)
DBInstanceClass: "db.t2.micro"
Engine: "postgres"
MasterUsername: Username
InstanceSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Letting HTTP into our instance
VpcId: !Ref VPC
SecurityGroupIngress:
- FromPort: 80
IpProtocol: tcp
ToPort: 80
SourceSecurityGroupId: !Ref ApplicationLoadBalancerSecurityGroup # (1)
ApplicationLoadBalancer:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer # (1)
Properties:
SecurityGroups:
- !Ref ApplicationLoadBalancerSecurityGroup # (2)
Subnets: # (3)
- !Ref PublicSubnetA
- !Ref PublicSubnetB
ApplicationLoadBalancerSecurityGroup:
ApplicationLoadBalancerSecurityGroup:
Type: AWS::EC2::SecurityGroup # (4)
Properties:
GroupDescription: SSH and HTTP
VpcId: !Ref VPC
SecurityGroupIngress: # (5)
- CidrIp: 0.0.0.0/0
FromPort: 80
IpProtocol: tcp
ToPort: 80
PublicRouteTable: # (1)
Type: AWS::EC2::RouteTable # (2)
Properties:
VpcId: !Ref VPC # (3)
PublicRoute: # (4)
Type: AWS::EC2::Route # (5)
DependsOn: AttachGateway
Properties:
RouteTableId: !Ref PublicRouteTable # (6)
InternetGateway: # (1)
Type: AWS::EC2::InternetGateway # (2)
DependsOn: VPC
AttachGateway: # (2)
Type: AWS::EC2::VPCGatewayAttachment # (4)
Properties:
VpcId: !Ref VPC # (5)
InternetGatewayId: !Ref InternetGateway # (6
AutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
LaunchConfigurationName: !Ref AppLaunchConfig
# AvailabilityZones:
# - !Select [0, !GetAZs ]
# - !Select [1, !GetAZs ]
VPCZoneIdentifier: # (1)
- !Ref PublicSubnetA
- !Ref PublicSubnetB