Advertisement
Guest User

Untitled

a guest
Aug 4th, 2019
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 3.57 KB | None | 0 0
  1. Parameters:
  2.   EnvironmentName:
  3.     Description: KaspersEnvironment
  4.     Type: String
  5.  
  6. Resources:
  7.   VPC:
  8.     Type: AWS::EC2::VPC
  9.     Properties:
  10.       CidrBlock: 10.0.0.0/16
  11.       EnableDnsSupport: false
  12.       EnableDnsHostnames: false
  13.       Tags:
  14.         - Key: Name
  15.           Value: !Ref EnvironmentName
  16.  
  17.   MyPublicUbuntu:
  18.     Type: AWS::EC2::Instance
  19.     Properties:
  20.       AvailabilityZone: eu-central-1a # Frankfurt
  21.       ImageId: "ami-0ac05733838eabc06" # Free Tier Ubuntu
  22.       InstanceType: t2.micro
  23.       SubnetID: !Ref PublicSubnet1
  24.  
  25.   SSHSecurityGroup:
  26.     Type: AWS::EC2::SecurityGroup
  27.     Properties:
  28.       GroupDescription: Enable SSH access via port 22
  29.       VpcId: !Ref VPC
  30.       SecurityGroupIngress:
  31.       - CidrIp: 10.0.0.0/16
  32.         FromPort: 22
  33.         IpProtocol: tcp
  34.         ToPort: 22
  35.  
  36.   HTTPSecurityGroup:
  37.     Type: AWS::EC2::SecurityGroup
  38.     Properties:
  39.       GroupDescription: Enable HTTP access via port 80
  40.       VpcId: !Ref VPC
  41.       SecurityGroupIngress:
  42.       - CidrIp: 10.0.0.0/16
  43.         FromPort: 80
  44.         IpProtocol: tcp
  45.         ToPort: 80
  46.  
  47.   InternetGateway:
  48.     Type: AWS::EC2::InternetGateway
  49.     Properties:
  50.       Tags:
  51.         - Key: Name
  52.           Value: !Ref EnvironmentName
  53.  
  54.   InternetGatewayAttachment:
  55.     Type: AWS::EC2::VPCGatewayAttachment
  56.     Properties:
  57.       InternetGatewayId: !Ref InternetGateway
  58.       VpcId: !Ref VPC
  59.  
  60.   PublicSubnet1:
  61.     Type: AWS::EC2::Subnet
  62.     Properties:
  63.       VpcId: !Ref VPC
  64.       AvailabilityZone: !Select [0, !GetAZs ""]
  65.       CidrBlock: 10.0.1.0/24
  66.       MapPublicIpOnLaunch: true
  67.       Tags:
  68.         - Key: Name
  69.           Value: !Sub ${EnvironmentName} Public Subnet (AZ1)
  70.  
  71.   PrivateSubnet1:
  72.     Type: AWS::EC2::Subnet
  73.     Properties:
  74.       VpcId: !Ref VPC
  75.       AvailabilityZone: !Select [0, !GetAZs ""]
  76.       CidrBlock: 10.0.2.0/24
  77.       MapPublicIpOnLaunch: false
  78.       Tags:
  79.         - Key: Name
  80.           Value: !Sub ${EnvironmentName} Private Subnet (AZ1)
  81.  
  82.   InternetGatewayAttachment:
  83.     Type: AWS::EC2::VPCGatewayAttachment
  84.     Properties:
  85.       InternetGatewayId: !Ref InternetGateway
  86.       VpcId: !Ref VPC
  87.  
  88.   NatGateway1EIP:
  89.     Type: AWS::EC2::EIP
  90.     DependsOn: InternetGatewayAttachment
  91.     Properties:
  92.       Domain: vpc
  93.  
  94.   NatGateway1:
  95.     Type: AWS::EC2::NatGateway
  96.     Properties:
  97.       AllocationId: !GetAtt NatGateway1EIP.AllocationId
  98.       SubnetId: !Ref PublicSubnet1
  99.  
  100.   PublicRouteTable:
  101.     Type: AWS::EC2::RouteTable
  102.     Properties:
  103.       VpcId: !Ref VPC
  104.       Tags:
  105.         - Key: Name
  106.           Value: !Sub ${EnvironmentName} Public Routes
  107.  
  108.   DefaultPublicRoute:
  109.     Type: AWS::EC2::Route
  110.     DependsOn: InternetGatewayAttachment
  111.     Properties:
  112.       RouteTableId: !Ref PublicRouteTable
  113.       DestinationCidrBlock: 10.0.1.0/0
  114.       GatewayId: !Ref InternetGateway
  115.  
  116.   PublicSubnet1RouteTableAssociation:
  117.     Type: AWS::EC2::SubnetRouteTableAssociation
  118.     Properties:
  119.       RouteTableId: !Ref PublicRouteTable
  120.       SubnetId: !Ref PublicSubnet1
  121.  
  122.   PrivateRouteTable1:
  123.     Type: AWS::EC2::RouteTable
  124.     Properties:
  125.       VpcId: !Ref VPC
  126.       Tags:
  127.         - Key: Name
  128.           Value: !Sub ${EnvironmentName} Private Routes (AZ1)
  129.  
  130.   DefaultPrivateRoute1:
  131.     Type: AWS::EC2::Route
  132.     Properties:
  133.       RouteTableId: !Ref PrivateRouteTable1
  134.       DestinationCidrBlock: 10.0.2.0/0
  135.       NatGatewayId: !Ref NatGateway1
  136.  
  137.   PrivateSubnet1RouteTableAssociation:
  138.     Type: AWS::EC2::SubnetRouteTableAssociation
  139.     Properties:
  140.       RouteTableId: !Ref PrivateRouteTable1
  141.       SubnetId: !Ref PrivateSubnet1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement