Advanced Ludwig

The Advanced Ludwig guide offers a deeper dive into the Ludwig language. Here, you’ll find information about advanced syntax and grammar, along with details about the Ludwig Compiler and the Ludwig Documentation Generator.

For a basic introduction to the language, see Writing Compositions. For details on the rules of writing Ludwig see Ludwig Grammar and Ludwig Syntax.

For at-a-glance information about the Fugue Standard Library, see the Fugue Standard Library Reference.

Note

Sometimes an image or diagram can really help. Why not check out the Fugue Composer for a handy visualization of your infrastructure that you can explore and modify in real-time?

An Example of Ludwig

Ludwig offers simple and powerful expressions of infrastructure in the cloud. This basic example instructs Fugue to build and monitor an AWS Virtual Private Cloud (VPC), complete with public subnets, in just a few lines.

exampleNetwork: Network.new {
  name: "Example VPC",
  region: exampleRegion,
  cidr: "10.0.0.0/16",
  publicSubnets: [
    (examplePrimaryAz, "10.0.1.0/24"),
    (exampleSecondaryAz, "10.0.2.0/24")
  ],
  privateSubnets: []
}

To summarize, this example creates:

  • A VPC Network space;
    • With a given name, which displays as normal in the AWS console or CLI;
    • In a particular region, given in a binding (see Ludwig Syntax for details, but think of “binding” as short for “immutable variable”) called exampleRegion, which in turn refers to one of an enumeration of valid AWS regions, and;
    • With a given CIDR block (in the cidr property) of IP addresses which is validated at compile time.
  • Two publicSubnets within that VPC;
    • Each in a particular availability zone, again using a binding (examplePrimaryAz and exampleSecondaryAz) that references a valid AWS availability zone, and;
    • With a given CIDR block of IP addresses which is also validated at compile time, including validating whether or not they can fit within that VPC.

This code and outline illustrate some important aspects of Ludwig. As you can see, Ludwig syntax is familiar. It’s also declarative, as in Ludwig you focus on telling fugue what you want, and far less on how to do it. And of course, all of the code here – as well as the Ludwig code that provides the Network abstraction – is validated by a compiler before it reaches Fugue’s Conductor, so that you get feedback much faster.

Why Ludwig?

Fugue provides simplification of your life on the cloud through abstractions. Abstractions can be expressed in one of two ways; as black boxes, or as language. Fugue puts as much into language as we can, so that you can do things with it that we didn’t predict.

Black boxes are easier for a platform builder to make, because they do things in one particular way. They are also less flexible for the user, because they do things in one particular way, which may not be the way the user needs or prefers.

As users, we prefer flexibility and access, so we prefer languages to black boxes. We made Fugue to be something we would enjoy using, so we decided to express a lot of the system as a language. Since we knew we wanted to go down the language path, we first looked to see if there was something out there that would be a good choice, based on our criteria. These are:

  • Doing typical things on the cloud should be easy, and not feel like programming. That’s why Ludwig uses syntax familiar from data formats like JSON, and not more complex programming language syntax.
  • Users should get great error messages, fast. That’s why Ludwig performs static analysis with a compiler.
  • If the program compiles, it should almost always work when operating against the cloud. That’s why Ludwig has a strong type system.
  • Doing sophisticated things should be possible, in a safe and predictable way. That’s why Ludwig can be extended with new types, functions, and libraries.
  • Doing sophisticated things once should turn them into shareable, easy things. That’s why Ludwig can be shared and easily reused.

Note

Did you know that Fugue offers editor plug-ins so you can read and write Ludwig in your editor/IDE of choice? All plug-ins include Ludwig syntax highlighting, and some have additional features. See ludwig-mode for Emacs, ludwig-vim for vim, vscode-language-ludwig for VSCode, and language-ludwig for Atom.