Ludwig Tutorial 2: Subnet

This tutorial is actually a Ludwig composition. You can download it here and fugue run it like you would any other composition. You can use lwc, the Ludwig compiler, to compile the composition.

If you’re interested in text editor plug-ins, you can find them here. Click here to return to the Tutorial table of contents.

Ready?

Let’s Go!

First, here’s the Ludwig from the previous step that provides a VPC.

composition

import Fugue.AWS as AWS
import Fugue.AWS.EC2 as EC2

my-vpc: EC2.Vpc.new {
  cidrBlock: "10.0.0.0/16",
  region: AWS.Us-west-2
}

A VPC isn’t much use without subnets. This declaration adds one. Most of this should be familiar from the previous tutorial composition.

subnet1: EC2.Subnet.new {

Strings can be in either double quotes or single quotes.

cidrBlock: '10.0.1.0/24',

This is a reference. Values can, in fact, be the names of other bindings.

  vpc: my-vpc,
  availabilityZone: AWS.A,
  mapPublicIpOnLaunch: True
}

Here’s the finished product.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
composition

import Fugue.AWS as AWS
import Fugue.AWS.EC2 as EC2

my-vpc: EC2.Vpc.new {
  cidrBlock: "10.0.0.0/16",
  region: AWS.Us-west-2
}
subnet1: EC2.Subnet.new {
  cidrBlock: '10.0.1.0/24',
  vpc: my-vpc,
  availabilityZone: AWS.A,
  mapPublicIpOnLaunch: True
}

Running and Compiling the Composition

You can run this composition with the following command:

fugue run Tutorial2.lw

This will create a VPC and subnet in your AWS account.

Optionally, if you have a process running from the previous tutorial, you can simply update the process like this:

fugue update [ALIAS or FID] Tutorial2.lw

To just check compilation, invoke lwc, the Ludwig compiler:

lwc Tutorial2.lw