brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Oct 01. 2021

20탄-2. CF - pub2, pri2

테스트 환경을 구축하기 위해 Cloudformation을 공부해보자

실무에서도 빠르게 인프라를 구축하기 위해 많이 사용한다.


<1> 요청 사항 - Pub2 , Pri2 Subnet 

<2> Cloudformation 코드에 들어가야 하는것

<3> Cloudformation 내용

<4> 다른 Cloudformation 파일 보기



<1> 요청 사항 - Pub2 , Pri2 Subnet 


VPC 1개

Public Subnet 2개

Private Sunet 2개 구성이다.



<2> Cloudformation 코드에 들어가야 하는것


pub관련 - 6개

PublicSubnet1 

PublicSubnet2

PublicRouteTable 테이블

PublicRoute  0.0.0.0

PublicSubnetRouteTableAssociation1

PublicSubnetRouteTableAssociation2



private 관련  - 5개

PrivateSubnet1

PrivateSubnet2

PrivateRouteTable:  테이블

PrivateSubnetRouteTableAssociation1: 

PrivateSubnetRouteTableAssociation2: 


// private는  라우팅 테이블 없는것.

// 나중에 nat가 생기면 라우팅 테이블이 있음.


공통

 VPC

InternetGateway

VPCGatewayAttachment




<3> Cloudformation 내용


AWSTemplateFormatVersion: 2010-09-09

Description: Deploy a VPC


Resources:

  VPC:

    Type: AWS::EC2::VPC

    Properties:

      CidrBlock: 10.0.0.0/16

      EnableDnsHostnames: true

      Tags:

      - Key: Name

        Value: Lab VPC


  InternetGateway:

    Type: AWS::EC2::InternetGateway

    Properties:

      Tags:

      - Key: Name

        Value: Lab Internet Gateway


  AttachGateway:

    Type: AWS::EC2::VPCGatewayAttachment

    Properties:

      VpcId: !Ref VPC

      InternetGatewayId: !Ref InternetGateway


  PublicSubnet1:

    Type: AWS::EC2::Subnet

    Properties:

      VpcId: !Ref VPC

      CidrBlock: 10.0.0.0/24

      AvailabilityZone: !Select 

        - '0'

        - !GetAZs ''

      Tags:

        - Key: Name

          Value: Public Subnet 1


  PrivateSubnet1:

    Type: AWS::EC2::Subnet

    Properties:

      VpcId: !Ref VPC

      CidrBlock: 10.0.1.0/24

      AvailabilityZone: !Select 

        - '0'

        - !GetAZs ''

      Tags:

        - Key: Name

          Value: Private Subnet 1


  PublicSubnet2:

    Type: AWS::EC2::Subnet

    Properties:

      VpcId: !Ref VPC

      CidrBlock: 10.0.2.0/24

      AvailabilityZone: !Select 

        - '1'

        - !GetAZs ''

      Tags:

        - Key: Name

          Value: Public Subnet 2


  PrivateSubnet2:

    Type: AWS::EC2::Subnet

    Properties:

      VpcId: !Ref VPC

      CidrBlock: 10.0.3.0/24

      AvailabilityZone: !Select 

        - '1'

        - !GetAZs ''

      Tags:

        - Key: Name

          Value: Private Subnet 2


  PublicRouteTable:

    Type: AWS::EC2::RouteTable

    Properties:

      VpcId: !Ref VPC

      Tags:

        - Key: Name

          Value: Public Route Table


  PublicRoute:

    Type: AWS::EC2::Route

    Properties:

      RouteTableId: !Ref PublicRouteTable

      DestinationCidrBlock: 0.0.0.0/0

      GatewayId: !Ref InternetGateway


  PublicSubnetRouteTableAssociation1:

    Type: AWS::EC2::SubnetRouteTableAssociation

    Properties:

      SubnetId: !Ref PublicSubnet1

      RouteTableId: !Ref PublicRouteTable


  PublicSubnetRouteTableAssociation2:

    Type: AWS::EC2::SubnetRouteTableAssociation

    Properties:

      SubnetId: !Ref PublicSubnet2

      RouteTableId: !Ref PublicRouteTable


  PrivateRouteTable:

    Type: AWS::EC2::RouteTable

    Properties:

      VpcId: !Ref VPC

      Tags:

      - Key: Name

        Value: Private Route Table


  PrivateSubnetRouteTableAssociation1:

    Type: AWS::EC2::SubnetRouteTableAssociation

    Properties:

      SubnetId: !Ref PrivateSubnet1

      RouteTableId: !Ref PrivateRouteTable


  PrivateSubnetRouteTableAssociation2:

    Type: AWS::EC2::SubnetRouteTableAssociation

    Properties:

      SubnetId: !Ref PrivateSubnet2

      RouteTableId: !Ref PrivateRouteTable


Outputs:

  VPC:

    Description: VPC

    Value: !Ref VPC


  AZ1:

    Description: Availability Zone 1

    Value: !GetAtt

      - PublicSubnet1

      - AvailabilityZone


  AZ2:

    Description: Availability Zone 2

    Value: !GetAtt

      - PublicSubnet2

      - AvailabilityZone



<4> 다른 Cloudformation 파일 보기


https://brunch.co.kr/@topasvga/1781


브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari