" />

スポンサーリンク

AWS

AWS CloudformationでVPCを構築する

更新日:

VPCのみ構築するテンプレート

AWSTemplateFormatVersion: 2010-09-09
Description:
  "This create only VPC."

Parameters:
  ProjectName:
    Type: String

Resources:
  VPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 10.0.0.0/24
      EnableDnsSupport: true
      EnableDnsHostnames: true
      InstanceTenancy: default
      Tags:
        - Key: Name
          Value: !Sub "${ProjectName}-vpc"
        - Key: ProjectName
          Value: !Sub "${ProjectName}-vpc"
    DeletionPolicy: Retain

VPCにインターネットゲートウェイをアタッチするテンプレート

AWSTemplateFormatVersion: 2010-09-09
Description:
  "This create only VPC."

Parameters:
  ProjectName:
    Type: String

Resources:
  VPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 10.0.0.0/24
      EnableDnsSupport: true
      EnableDnsHostnames: true
      InstanceTenancy: default
      Tags:
        - Key: Name
          Value: !Sub "${ProjectName}-vpc"
    DeletionPolicy: Retain

  InternetGateway:
    Type: "AWS::EC2::InternetGateway"
    Properties:
      Tags:
        - Key: Name
          Value: !Sub "${ProjectName}-igw"

  InternetGatewayAttachment:
    Type: "AWS::EC2::VPCGatewayAttachment"
    Properties:
      InternetGatewayId: !Ref InternetGateway
      VpcId: !Ref VPC

VPCにパブリックサブネットとプライベートサブネットを設置するテンプレート

AWSTemplateFormatVersion:     2010-09-09
Description:
  "This create only VPC."

Parameters:
  ProjectName:
    Type:                     String

Resources:
  #=======================
  # VPCを作成し、IGをアタッチ
  #=======================
  VPC:
    Type:                     AWS::EC2::VPC
    Properties:
      CidrBlock:              10.0.0.0/16
      EnableDnsSupport:       true
      EnableDnsHostnames:     true
      InstanceTenancy:        default
      Tags:
        - Key:                Name
          Value:              !Sub "${ProjectName}-vpc"
    DeletionPolicy:           Retain

  InternetGateway:
    Type:                     "AWS::EC2::InternetGateway"
    Properties:
      Tags:
        - Key:                Name
          Value:              !Sub "${ProjectName}-igw"

  InternetGatewayAttachment:
    Type:                     "AWS::EC2::VPCGatewayAttachment"
    Properties:
      InternetGatewayId:      !Ref InternetGateway
      VpcId:                  !Ref VPC

  #=========================
  # VPCにPublicサブネットを設置
  #=========================
  PublicSubnet1a:
    Type:                     "AWS::EC2::Subnet"
    Properties:
      VpcId:                  !Ref VPC
      AvailabilityZone:       "ap-northeast-1a"
      CidrBlock:              10.0.1.0/24
      Tags:
      - Key:                  Name
        Value:                !Sub "${ProjectName}-public-subnet1a"

  RouteTable1:
    Type:                     "AWS::EC2::RouteTable"
    Properties:
      VpcId:                  !Ref VPC
      Tags:
      - Key:                  Name
        Value:                !Sub "${ProjectName}-rt"

  RouteTable01Route1:
    Type:                     "AWS::EC2::Route"
    Properties:
      RouteTableId:           !Ref RouteTable1
      DestinationCidrBlock:   0.0.0.0/0
      GatewayId:              !Ref InternetGateway

  RouteTableAssociation1:
    Type:                     "AWS::EC2::SubnetRouteTableAssociation"
    Properties:
      RouteTableId:           !Ref RouteTable1
      SubnetId:               !Ref PublicSubnet1a

  #==========================
  # VPCにPrivateサブネットを設置
  #==========================
  PrivateSubnet1a:
    Type:                     "AWS::EC2::Subnet"
    Properties:
      VpcId:                  !Ref VPC
      AvailabilityZone:       "ap-northeast-1a"
      CidrBlock:              10.0.2.0/24
      Tags:
      - Key:                  Name
        Value:                !Sub "${ProjectName}-private-subnet1a"

スポンサーリンク

-AWS

Copyright© ノリックジオグラフィック for Webエンジニア , 2022 All Rights Reserved Powered by AFFINGER5.