Advertisement
Guest User

Untitled

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