LoginSignup
9
3

More than 5 years have passed since last update.

Scalaによるtype-safeなCloudFormation DSL

Last updated at Posted at 2018-04-03
1 / 17

自己紹介

渋谷 充宏 @m4buya

  • 株式会社オプト テクノロジー開発部 チームマネージャー
  • Ruby / Scala / インフラ
  • https://github.com/mshibuya
  • RailsAdmin/CarrierWave committer
  • ADPLAN SREチームリーダー(New!)

SREチームを立ち上げました

が、人が足りてません…

株式会社オプトではSREを含めエンジニアを積極採用中です!


アジェンダ

  • 前提知識
  • ScalaMatsuriへの応募内容
  • cloudformal
    • 特長
    • 実際のコード
  • 今後の展望
  • まとめ

前提知識

  • CloudFormationとは

JSON(やYAML)でAWSインフラが作れるやつです!


LoadBalancerを作る

"Resources" : {
  "ApplicationLoadBalancer" : {
    "Type" : "AWS::ElasticLoadBalancingV2::LoadBalancer",
    "Properties" : {
      "Subnets" : {
        "Ref" : "Subnets"
      }
    }
  }
}

条件分岐

"Size" : {
  "Fn::If" : [
    "CreateLargeSize",
    "100",
    "10"
  ]},

これ、つらくない…?

生で書くと死ぬやつなので、いろんなDSLがあります

  • kumogata
  • troposphere
  • cloudformation-template-generator
  • cloudform

ScalaMatsuriへの応募内容

cfp.png


cloudformal


特長

  • CloudFormationの更新に簡単に追従
  • 静的な型チェック
  • Object-Orientedなモデリング

CloudFormationの更新に簡単に追従

Cloudformalのコードの大半はAWSが公開しているCloudFormation Resource Specificationより自動生成されており、コマンド一発で追従できます。


静的な型チェック

def blockDeviceMappings: Property[Seq[BlockDeviceMapping]] = Empty
def creditSpecification: Property[CreditSpecification] = Empty
def disableApiTermination: Property[Boolean] = Empty
def ebsOptimized: Property[Boolean] = Empty
def elasticGpuSpecifications: Property[Seq[ElasticGpuSpecification]] = Empty

Object-Orientedなモデリング

trait ServerInstance extends aws.ec2.Instance {
  def image: AMIImage
  def imageId: String = image.id
}

case class BatchServerInstance(
  image: BatchServerImage
) extends ServerInstance

case class WebServerInstance(
  image: WebServerImage
) extends ServerInstance

今後の展望

  • CLIが全然しょぼいので整備したい
  • テストコード書きたい
  • ドキュメント整備したい

まとめ

  • インフラ×型安全、意外といけるのでは
  • とはいえ実用はこれから
  • 可能性を感じていただけたら、ぜひ使ってみてください!

最後に

Starお待ちしてます★

9
3
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
9
3