LoginSignup
0
0

More than 1 year has passed since last update.

[ネタ]半年前の自分と比べてみた

Last updated at Posted at 2021-10-10

EC2を作成するcfnを半年前の自分と比べてみた

自分が担当してたプロジェクトの環境構築で、納期的に追い込まれてて
EC2の作成をコード化できなかったと思い、今日書いてみた。

そして、書いたあとに半年以上前に自分でEC2のcfn書いていたことに気付き、比較してみた。

半年以上前の自分が書いたcfn


AWSTemplateFormatVersion: "2010-09-09"

Description: Template generated by rain

Resources:
  MyInstance:
    Type: AWS::EC2::Instance
    Properties:
      KeyName: Secret-key
      AvailabilityZone: ap-northeast-1a
      ImageId: ami-0f27d081df46f326c
      InstanceType: t2.micro
      NetworkInterfaces:
        - AssociatePublicIpAddress: true
          #DeleteOnTermination: false # Optional
          #Description: CHANGEME # Optional
          DeviceIndex: "0"
          GroupSet:
            - !ImportValue TEST-SGfromCF
          SubnetId: subnet-068305cddc05d01bd
      #SecurityGroupIds:
        #- !ImportValue TEST-SGfromCF
      #SecurityGroups:
        #- !ImportValue TEST-SGfromCF
      #SubnetId: subnet-068305cddc05d01bd
      Tags:
        - Key: Name
          Value: TEST-EC2_fromCF

今日書いたcfn

AWSTemplateFormatVersion: 2010-09-09
Description: create ec2
# ------------------------------------------------------------#
# Input Parameters
# ------------------------------------------------------------#
Parameters:
  InstanceType:
    Description: Input an Instance type.
    Type: String
    Default: t2.micro
  KeyPair:
    Description: Select your key pair.
    Type: "AWS::EC2::KeyPair::KeyName"
  InstanceName:
    Description: Input a instance name.
    Type: String
    Default: test-ec2
  MyhomeIP:
    Description: IP address allowed to access EC2
    Type: String
Resources:
# ------------------------------------------------------------#
# EC2
# ------------------------------------------------------------#
  MyInstance:
    Type: AWS::EC2::Instance
    Properties: 
     AvailabilityZone: ap-northeast-1a
     BlockDeviceMappings:
      - DeviceName: /dev/xvda
        Ebs:
         VolumeType: gp2
         VolumeSize: '8'
     ImageId: ami-0701e21c502689c31
     InstanceType: !Ref InstanceType
     KeyName: !Ref KeyPair
     SecurityGroupIds: 
      - !Ref ServerSecurityGroup
     SubnetId: !ImportValue NetworkStackPublicSubnetA
     Tags:
      - Key: Name
        Value: !Sub test-ec2
     UserData:
      Fn::Base64: |
        #!/bin/bash
        sudo yum update -y

# ------------------------------------------------------------#
# EIP
# ------------------------------------------------------------#
  EC2EIP:
    Type: AWS::EC2::EIP
    Properties:
     Domain: vpc

# ------------------------------------------------------------#
# EIP Association
# ------------------------------------------------------------#
  EIPAssociationEC2:
   Type: AWS::EC2::EIPAssociation
   Properties:
    InstanceId: !Ref MyInstance
    AllocationId: !GetAtt EC2EIP.AllocationId

# ------------------------------------------------------------#
# SecurityGroup
# ------------------------------------------------------------#
  ServerSecurityGroup:
   Type: AWS::EC2::SecurityGroup
   Properties:
    GroupDescription: allow connections from specified CIDR ranges
    VpcId: !ImportValue NetworkStackVPC
    SecurityGroupIngress:
     - IpProtocol: tcp
       FromPort: 22
       ToPort: 22
       CidrIp: !Ref MyhomeIP

# ------------------------------------------------------------#
# Output Parameters
# ------------------------------------------------------------#
#Outputs:

変わっていた点

  • AmazonLinuxのImageId変わった?
  • Inputパラメータを使うようになった
  • 自動割り当てパブリックIPからEIPにしてた
  • EBSのサイズや種類を入れていた
  • 半年前はセキュリティグループ全開放だったけど、今回は自宅のグローバルIPを作成時に入力するようにして、そのIPのみに絞っていた
  • EC2につけるセキュリティグループの定義の仕方が変わっていた(今回もはまったw)
  • ユーザデータを定義していた

 最後に一言

成長しているのか、成長していないのか微妙だ・・・

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0