Ludwig Tutorial 6: Another 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!

We’ll begin with the work from the last tutorial.

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
}

Here, a second subnet is added. Note that the availability zone differs from the first subnet, so we can distribute our services across AZs. After the subnet, everything is the same as we had in the previous tutorial.

subnet2: EC2.Subnet.new {
  cidrBlock: '10.0.2.0/24',
  vpc: my-vpc,
  availabilityZone: AWS.B,
  mapPublicIpOnLaunch: True
}

my-igw: EC2.InternetGateway.new {
  vpc: my-vpc
}

route-table: EC2.RouteTable.new {
    vpc: my-vpc,
    routes: [
        EC2.Route.new {
            destinationCidrBlock: "0.0.0.0/0",
            target: EC2.GatewayTarget(my-igw)
        }
    ],
    associations: [subnet1]
}

my-instance: EC2.Instance.new {
    instanceType: EC2.T2_micro,
    subnet: subnet1,
    image: "ami-7172b611",
    securityGroups: [public-ec2-sg]
}

public-ec2-sg: EC2.SecurityGroup.new {
    description: "Allow traffic from the internet",
    ipPermissions: [
        EC2.IpPermission.http(EC2.IpPermission.Target.all)
    ],
    vpc: my-vpc
}

Running and Compiling the Composition

You can run this composition with the following command:

fugue run Tutorial6.lw

This will create the following infrastructure in your AWS account:

  • VPC
  • 2 subnets
  • Internet gateway
  • Route table
  • EC2 instance
  • Security group

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

fugue update [ALIAS or FID] Tutorial6.lw

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

lwc Tutorial6.lw