MakisDSL

Installation & Usage

Get started with MakisDSL by setting up the library and creating your first multi-cloud infrastructure template.

🔗 Prerequisites

Before using MakisDSL, ensure you have the following installed:

🔗 Installation

MakisDSL is distributed as a Scala library. Add it to your project's dependencies:

Add to build.sbt

ThisBuild / scalaVersion := "3.7.1"

libraryDependencies ++= Seq(
  "io.github.finochiom" %% "makisdsl" % "0.1.0",
  "io.circe" %% "circe-core" % "0.14.6",
  "io.circe" %% "circe-parser" % "0.14.6"
)

Create a new project

If starting from scratch:

mkdir my-infrastructure
cd my-infrastructure
sbt new scala/scala3.g8

Then add the MakisDSL dependency to your build.sbt file.

🔗 Basic Usage

MakisDSL uses a fluent DSL syntax to define cloud resources. Here are the basic imports and patterns:

Required Imports

import cloud.*
import cloud.CloudProvider.*
import cloud.syntax.*

Basic Pattern

val myApp = cloudApp(provider = AWS) {
  // Define your cloud resources here
}

Supported Cloud Providers

🔗 Your First Template

Let's create a simple infrastructure template with storage, compute, and database components:

1. Define Infrastructure

import cloud.*
import cloud.CloudProvider.*
import cloud.syntax.*
import cloud.providers.aws.CloudFormationGenerator
import io.circe.parser.*

val myApp = cloudApp(provider = AWS) {
  // Create an S3 bucket for storage
  val storage = objectStorage("my-data-bucket")
    .withVersioning(true)
    .withPublicAccess(false)

  // Create a Lambda function
  val function = serverlessFunction("my-api-handler")
    .withRuntime("nodejs18.x")
    .withHandler("index.handler")
    .withCode("exports.handler = async (event) => { return { statusCode: 200, body: 'Hello World!' }; }")
    .build

  // Create a DynamoDB table
  val database = noSqlTable("my-users-table")
    .withHashKey("userId", "S")
    .build
}

2. Generate CloudFormation Template

// Generate AWS CloudFormation template
val cfTemplate = CloudFormationGenerator.generate(myApp)
val jsonString = cfTemplate.spaces2

println("Generated CloudFormation Template:")
println(jsonString)

3. Generate Azure ARM Template

import cloud.providers.azure.ARMGenerator

// Same infrastructure, different provider
val azureApp = cloudApp(provider = Azure) {
  // ... same resource definitions
}

val armTemplate = ARMGenerator.generate(azureApp)
val azureJson = armTemplate.spaces2

4. Generate GCP Template

import cloud.providers.gcp.DeploymentManagerGenerator

// Same infrastructure, different provider
val gcpApp = cloudApp(provider = GCP) {
  // ... same resource definitions
}

val gcpTemplate = DeploymentManagerGenerator.generate(gcpApp)
val gcpJson = gcpTemplate.spaces2

Complete Example

object InfrastructureExample extends App {
  import cloud.*
  import cloud.CloudProvider.*
  import cloud.syntax.*
  import cloud.providers.aws.CloudFormationGenerator

  val myApp = cloudApp(provider = AWS) {
    val bucket = objectStorage("my-code-bucket")
      .withVersioning(true)

    val function = serverlessFunction("my-api-handler")
      .withRuntime("nodejs18.x")
      .withHandler("index.handler")
      .withCode(bucket.reference)
      .dependsOn(bucket)
      .build

    val table = noSqlTable("my-users-table")
      .withHashKey("userId", "S")
      .dependsOn(function)
      .build
  }

  // Generate and print template
  val template = CloudFormationGenerator.generate(myApp)
  println(template.spaces2)
}

🔗 Next Steps

Now that you have MakisDSL set up and working, explore more advanced features:

Development Note: MakisDSL is in active development. Check the GitHub repository for the latest updates and features.