Upgrade to Pro — share decks privately, control downloads, hide ads and more …

実践!CloudFormation Best Practice ~CloudFormationで始める組織改革~

urmot
February 23, 2019

実践!CloudFormation Best Practice ~CloudFormationで始める組織改革~

urmot

February 23, 2019
Tweet

More Decks by urmot

Other Decks in Technology

Transcript

  1. 複数サービスのリソースが混在 ServiceA ELB ServiceB ELB ServiceA EC2 ServiceB EC2 ServiceA

    S3 ServiceB EC2 ServiceC EC2 ServiceA EC2 VPC PrivateA Subnet PublicC Subnet
  2. あらゆるリソースが依存関係を持っていた ServiceA ELB ServiceB ELB ServiceA EC2 ServiceB EC2 ServiceA

    S3 ServiceB EC2 ServiceC EC2 ServiceA EC2 VPC PrivateA Subnet PublicC Subnet
  3. 変更時の影響が把握しづらい ServiceA ELB ServiceB ELB ServiceA EC2 ServiceB EC2 ServiceA

    S3 ServiceB EC2 ServiceC EC2 ServiceA EC2 VPC PrivateA Subnet PublicC Subnet 変更したら どうなるんだ...
  4. 毎回恐る恐る更新 ServiceA ELB ServiceB ELB ServiceA EC2 ServiceB EC2 ServiceA

    S3 ServiceB EC2 ServiceC EC2 ServiceA EC2 VPC PrivateA Subnet PublicC Subnet 変更したら どうなるんだ... 更新ボタンを 押したくない...
  5. もうやだ... ServiceA ELB ServiceB ELB ServiceA EC2 ServiceB EC2 ServiceA

    S3 ServiceB EC2 ServiceC EC2 ServiceA EC2 VPC PrivateA Subnet PublicC Subnet 変更したら どうなるんだ... 更新ボタンを 押したくない...
  6. 最終的に3000行のTemplateに 1 --- 2 AWSTemplateFormatVersion: '2010-09-09' 3 Description: 'My CloudFormation'

    4 2459 ServiceCSqs: 2560 Type: AWS::CloudFormation::Stack 2561 Properties: 2562 Parameters:
  7. 1 --- 2 AWSTemplateFormatVersion: '2010-09-09' 3 Description: 'My CloudFormation' 4

    2459 ServiceCSqs: 2560 Type: AWS::CloudFormation::Stack 2561 Properties: 2562 Parameters: どこを変更すれば良いかわからない どこを変更すれば 良いの...?
  8. 1 --- 2 AWSTemplateFormatVersion: '2010-09-09' 3 Description: 'My CloudFormation' 4

    2459 ServiceCSqs: 2560 Type: AWS::CloudFormation::Stack 2561 Properties: 2562 Parameters: インフラ担当に依頼するしかない インフラ担当が 全部管理 どこを変更すれば 良いの...?
  9. 1 --- 2 AWSTemplateFormatVersion: '2010-09-09' 3 Description: 'My CloudFormation' 4

    2459 ServiceCSqs: 2560 Type: AWS::CloudFormation::Stack 2561 Properties: 2562 Parameters: インフラ担当に負荷が集中 インフラ担当が ボトルネックに... どこを変更すれば 良いの...?
  10. 1 --- 2 AWSTemplateFormatVersion: '2010-09-09' 3 Description: 'My CloudFormation' 4

    2459 ServiceCSqs: 2560 Type: AWS::CloudFormation::Stack 2561 Properties: 2562 Parameters: 申し訳ない... インフラ担当が ボトルネックに... どこを変更すれば 良いの...?
  11. 複数環境に対応しようとしていた 43 --- 44 Parameters: 45 EnvType: 46 Type: String

    151 Conditions: 152 IsProd: !Equals [!Ref EnvType, Prod] 153 IsStag: !Equals [!Ref EnvType, Stag] 154
  12. 43 --- 44 Parameters: 45 EnvType: 46 Type: String 151

    Conditions: 152 IsProd: !Equals [!Ref EnvType, Prod] 153 IsStag: !Equals [!Ref EnvType, Stag] 154 環境の差分を把握するのが困難 これを変えると どうなるの?
  13. 43 --- 44 Parameters: 45 EnvType: 46 Type: String 151

    Conditions: 152 IsProd: !Equals [!Ref EnvType, Prod] 153 IsStag: !Equals [!Ref EnvType, Stag] 154 環境ごとの違いを吸収しなければならない 記述が複雑に...
  14. 43 --- 44 Parameters: 45 EnvType: 46 Type: String 151

    Conditions: 152 IsProd: !Equals [!Ref EnvType, Prod] 153 IsStag: !Equals [!Ref EnvType, Stag] 154 何も考えたくない...
  15. 3. キャンペーン用リソースをピックアップ WebSite ELB WebSite EC2 RDS S3 WebSite Stack

    Campaign ELB Campaign EC2 使ったリソースを ピックアップ
  16. 4. リソース削除による影響範囲を調査 WebSite ELB WebSite EC2 RDS S3 WebSite Stack

    Campaign ELB Campaign EC2 このリソースの 影響範囲は...
  17. 5. WebSiteにも影響を与えそうなりソースを発見 WebSite ELB WebSite EC2 RDS S3 WebSite Stack

    Campaign ELB Campaign EC2 WebSiteでも S3使ってる... このリソースの 影響範囲は...
  18. ELBの SecurityGroupを 変更したい 1. DBチームとWebチームが同時に変更要望を出す ELB EC2 RDS Security Group

    Parameter Group Security Group Service Stack Webチーム RDSの SecurityGroupを 変更したい DBチーム
  19. 2. 更新タイミングの調整, 影響範囲の確認が必要になる ELB EC2 RDS Security Group Parameter Group

    Security Group Service Stack 影響範囲の調査 更新タイミング の調整
  20. ELBの SecurityGroup を変更したい 1. DBチームとWebチームが同時に変更要望を出す ELB EC2 Security Group Web

    Stack RDS Security Group Parameter Group DB Stack Webチーム RDSの SecurityGroup を変更したい DBチーム
  21. 2. 各チームのタイミングで変更してリリース ELB EC2 Security Group Web Stack RDS Security

    Group Parameter Group DB Stack 今日変更して 今日リリース!! Webチーム 今日変更して 明日リリース!! DBチーム
  22. 更新タイミングの調整が不要 ELB EC2 Security Group Web Stack RDS Security Group

    Parameter Group DB Stack 更新タイミング の調整は不要
  23. 影響範囲も確認しやすい ELB EC2 Security Group Web Stack RDS Security Group

    Parameter Group DB Stack 更新タイミング の調整は不要 Stack内の 影響範囲を 確認すればOK
  24. ハッピー ELB EC2 Security Group Web Stack RDS Security Group

    Parameter Group DB Stack 更新タイミング の調整は不要 Stack内の 影響範囲を 確認すればOK
  25. # MyVpc.yaml Outputs: VpcId: Value: !Ref Vpc Export: Name: MyVpc-Id

    1. MyVpcでVPC IDをExport リージョン内で一意である 必要がある
  26. # MyApp.yaml Resources: MyAppSubnet: Type: AWS::EC2::Subnet Properties: VpcId: !ImportValue MyVpc-Id

    2. MyAppでMyVpcの値をImport !ImportValueで MyVpc-Idを指定
  27. # MyVpc.yaml Outputs: VpcId: Value: !GetAtt Vpc.CidrBlock Export: Name: MyVpc-Id

    VPC IDから CIDR Blockに変更 3. Exportの値を変更してみる
  28. # MyVpc.yaml Outputs: VpcId: Value: !GetAtt Vpc.CidrBlock Export: Name: MyVpc-Id

    VPC IDから CIDR Blockに変更 4. 変更をMyVpc Stackに適応
  29. # MyVpc.yaml Outputs: VpcId: Value: !GetAtt Vpc.CidrBlock Export: Name: MyVpc-Id

    5. エラーが発生し変更がロールバック 参照されているExportの 値は変更できない
  30. 2. 各Stackの管理者にIP追加を依頼 ELB EC2 Security Group ServiceA Stack ELB Security

    Group EC2 ServiceB Stack 支店のIPを SecurityGroup に追加してー
  31. 3. Stackの管理者はIPを確認しSecurityGroupに追加 ELB EC2 Security Group ServiceA Stack ELB Security

    Group EC2 ServiceB Stack ServiceAに 支店のIPを追加 ServiceBに 支店のIPを追加
  32. SecurityGroupが二重管理 ELB EC2 Security Group ServiceA Stack ELB Security Group

    EC2 ServiceB Stack 同じ設定を 2箇所で管理 2つだけなら まだいいけど...
  33. 3. 各Stackにネストされたスタックとして作成 ELB EC2 Company SG ServiceA Stack ELB Company

    SG EC2 ServiceB Stack Company SG 各Stackで 同じTemplate を参照
  34. 3. 各Stackを更新 ELB EC2 Company SG ServiceA Stack ELB Company

    SG EC2 ServiceB Stack Company SG 変更を 加えずに更新
  35. • 1Templateの行数: 3000行 → 200行 • Parametersの数: 20個 → 2〜5個

    Templateの記述がかなりシンプルになった Stack分割で1Templateがミニマム化
  36. • 1Templateの行数: 3000行 → 200行 • Parametersの数: 20個 → 2〜5個

    よっしゃ! Stack分割で1Templateが小さくなった