CloudFormationのサンプルを公開します。
このシリーズでは私が勉強がてら書いたサンプルだけ載せます。 書き方とか解説はしないです。
今回は以下構成。
シンプル過ぎますけど最初なので。
VPC作ってサブネット切ってT3インスタンスだけ立ててます。 踏み台インスタンスだけ用意しました。みたいなやつです。
AWSTemplateFormatVersion: '2010-09-09' Description: aiueo-test Parameters: # SSH用キーペアの指定 KeyPair: Description: test Type: AWS::EC2::KeyPair::KeyName Mappings: StackConfig: EC2: ImageId: 'ami-0f9ae750e8274075b' Resources: aiueoVPC: Type: AWS::EC2::VPC Properties: CidrBlock: 10.0.0.0/21 EnableDnsSupport: 'true' EnableDnsHostnames: 'true' Tags: - Key: Name Value: aiueo-VPC InternetGateway: Type: AWS::EC2::InternetGateway Properties: Tags: - Key: Name Value: aiueo-VPC-IGW AttachGateway: Type: AWS::EC2::VPCGatewayAttachment Properties: VpcId: !Ref aiueoVPC InternetGatewayId: !Ref InternetGateway FrontendRouteTable: Type: AWS::EC2::RouteTable DependsOn: AttachGateway Properties: VpcId: !Ref aiueoVPC Tags: - Key: Name Value: aiueo-VPC-FrontendRoute FrontendRoute: Type: AWS::EC2::Route DependsOn: AttachGateway Properties: RouteTableId: !Ref FrontendRouteTable DestinationCidrBlock: 0.0.0.0/0 GatewayId: !Ref InternetGateway FrontendSubnet: Type: AWS::EC2::Subnet DependsOn: AttachGateway Properties: CidrBlock: 10.0.1.0/24 MapPublicIpOnLaunch: 'false' VpcId: !Ref aiueoVPC Tags: - Key: Name Value: aiueo-VPC-FrontendSubnet FrontendSubnetRouteTableAssociation: Type: AWS::EC2::SubnetRouteTableAssociation Properties: SubnetId: !Ref FrontendSubnet RouteTableId: !Ref FrontendRouteTable bastionSecurityGroup: Type: "AWS::EC2::SecurityGroup" Properties: GroupDescription: Bastion-SG VpcId: !Ref aiueoVPC Tags: - Key: 'Name' Value: 'bastionSG' SecurityGroupIngress: - IpProtocol: tcp FromPort: '22' ToPort: '22' CidrIp: 210.172.143.100/32 bastionEC2: Type: 'AWS::EC2::Instance' Properties: # EBS設定 BlockDeviceMappings: - DeviceName: '/dev/xvda' Ebs: VolumeType: 'gp2' VolumeSize: 8 ImageId: !FindInMap [ StackConfig, EC2, ImageId ] # シャットダウン時の動作 InstanceInitiatedShutdownBehavior: 'stop' # インスタンスタイプ InstanceType: 't3.nano' # キーペア KeyName: !Ref KeyPair # 詳細モニタリング設定 Monitoring: false # セキュリティグループ SecurityGroupIds: - !GetAtt bastionSecurityGroup.GroupId # サブネット SubnetId: !Ref FrontendSubnet # テナンシー Tenancy: 'default' # バースト無制限の無効化 CreditSpecification: CPUCredits: 'standard' UserData: Fn::Base64: !Sub | #!/bin/bash yum -y update timedatectl set-timezone Asia/Tokyo localectl set-locale LANG=ja_JP.UTF-8 localectl set-keymap jp106 # タグ Tags: - Key: 'Name' Value: 'aiueo-bastion' bastionEIP: Type: "AWS::EC2::EIP" Properties: Domain: vpc bastionEIPAssociate: Type: AWS::EC2::EIPAssociation Properties: AllocationId: !GetAtt bastionEIP.AllocationId InstanceId: !Ref bastionEC2
ElasticIPってタグ付けできなかったけ??
もうちょっと調べておきます。
以上