Untitled

 avatar
unknown
plain_text
2 months ago
4.0 kB
3
Indexable
Resources:
  # VPC
  DigvijayVPC:
    Type: 'AWS::EC2::VPC'
    Properties:
      CidrBlock: '10.0.0.0/16'
      EnableDnsSupport: true
      EnableDnsHostnames: true
      Tags:
        - Key: 'Name'
          Value: 'Digvijay Singh'
        - Key: 'Purpose'
          Value: 'Cloudformation-exercise'
          
  # Internet Gateway
  DigvijayIGW:
    Type: 'AWS::EC2::InternetGateway'
    Properties:
      Tags:
        - Key: 'Name'
          Value: 'Digvijay Singh'
        - Key: 'Purpose'
          Value: 'Cloudformation-exercise'
  # Attach Internet Gateway to VPC
  DigvijayIGWAttachment:
    Type: 'AWS::EC2::VPCGatewayAttachment'
    Properties:
      VpcId: !Ref DigvijayVPC
      InternetGatewayId: !Ref DigvijayIGW
  # Public Subnet
  DigvijayPublicSubnet:
    Type: 'AWS::EC2::Subnet'
    Properties:
      VpcId: !Ref DigvijayVPC
      CidrBlock: '10.0.1.0/24'
      AvailabilityZone: !Select [ 0, !GetAZs 'ap-northeast-1' ]
      MapPublicIpOnLaunch: true
      Tags:
        - Key: 'Name'
          Value: 'Digvijay Singh'
        - Key: 'Purpose'
          Value: 'cloudformation-exercise'
  # Private Subnet
  DigvijayPrivateSubnet:
    Type: 'AWS::EC2::Subnet'
    Properties:
      VpcId: !Ref DigvijayVPC
      CidrBlock: '10.0.2.0/24'
      AvailabilityZone: !Select [ 0, !GetAZs 'ap-northeast-1' ]
      Tags:
        - Key: 'Name'
          Value: 'Digvijay'
        - Key: 'Purpose'
          Value: 'cloudformation-exercise'
  # Public Route Table
  DigvijayPublicRouteTable:
    Type: 'AWS::EC2::RouteTable'
    Properties:
      VpcId: !Ref DigvijayVPC
      Tags:
        - Key: 'Name'
          Value: 'Digvijay'
        - Key: 'Purpose'
          Value: 'cloudformation-exercise'
  # Public Route - Directs Internet Traffic via IGW
  DigvijayPublicRoute:
    Type: 'AWS::EC2::Route'
    DependsOn: DigvijayIGWAttachment
    Properties:
      RouteTableId: !Ref DigvijayPublicRouteTable
      DestinationCidrBlock: '0.0.0.0/0'
      GatewayId: !Ref DigvijayIGW
  # Public Subnet Route Table Association
  DigvijayPublicRouteAssociation:
    Type: 'AWS::EC2::SubnetRouteTableAssociation'
    Properties:
      SubnetId: !Ref DigvijayPublicSubnet
      RouteTableId: !Ref DigvijayPublicRouteTable
  # Elastic IP for NAT Gateway
  DigvijayNatEIP:
    Type: 'AWS::EC2::EIP'
    Properties:
      Domain: vpc
  # NAT Gateway in Public Subnet
  DigvijayNatGateway:
    Type: 'AWS::EC2::NatGateway'
    Properties:
      AllocationId: !GetAtt DigvijayNatEIP.AllocationId
      SubnetId: !Ref DigvijayPublicSubnet
      Tags:
        - Key: 'Name'
          Value: 'Digvijay'
        - Key: 'Purpose'
          Value: 'cloudformation-exercise'
  # Private Route Table
  DigvijayPrivateRouteTable:
    Type: 'AWS::EC2::RouteTable'
    Properties:
      VpcId: !Ref DigvijayVPC
      Tags:
        - Key: 'Name'
          Value: 'Digvijay'
        - Key: 'Purpose'
          Value: 'cloudformation-exercise'
  # Private Route - Direct Internet Traffic via NAT Gateway
  DigvijayPrivateRoute:
    Type: 'AWS::EC2::Route'
    Properties:
      RouteTableId: !Ref DigvijayPrivateRouteTable
      DestinationCidrBlock: '0.0.0.0/0'
      NatGatewayId: !Ref DigvijayNatGateway
  # Private Subnet Route Table Association
  DigvijayPrivateRouteAssociation:
    Type: 'AWS::EC2::SubnetRouteTableAssociation'
    Properties:
      SubnetId: !Ref DigvijayPrivateSubnet
      RouteTableId: !Ref DigvijayPrivateRouteTable
Outputs:
  VPCId:
    Description: 'VPC ID'
    Value: !Ref DigvijayVPC
  PublicSubnetId:
    Description: 'Public Subnet ID'
    Value: !Ref DigvijayPublicSubnet
  PrivateSubnetId:
    Description: 'Private Subnet ID'
    Value: !Ref DigvijayPrivateSubnet
  InternetGatewayId:
    Description: 'Internet Gateway ID'
    Value: !Ref DigvijayIGW
  NatGatewayId:
    Description: 'NAT Gateway ID'
    Value: !Ref DigvijayNatGateway
Editor is loading...
Leave a Comment