Module #2 Challenge

Sign Up to Build

About this Architecture

Here is some information about this architecture.

How to Build This Solution

Here are the steps you can follow to build this solution on your own.

You’ve made it all the way to the module challenge! This is going to be a fun one.

In this challenge, your objective is to create a networking module and use it in a project. You must complete the following:

  1. Create a project and module directory

  2. Complete the networking module configuration

  3. Use the networking module configuration to launch an EC2 instance into its subnet

  4. Verify your work in the AWS Console

Let’s get started. We’ll go show the order you can approach this.

Get Your AWS Credentials

If you're using the Skillmix Labs feature, open the lab settings (the beaker icon) on the right side of the code editor. Then, click the Start Lab button to start hte lab environment.

Wait for the credentials to load. Then run this in the terminal.

Be sure to enter in your own access key and secret key and name your profile 'smx-lab'.

$ aws configure --profile smx-lab
AWS Access Key ID [None]: 
AWS Secret Access Key [None]: 
Default region name [None]: us-west-2
Default output format [None]: 

Note: If you're using your own AWS account you'll need to ensure that you've created and configured a named AWS CLI profile named smx-lab.

Create a project directory and main configuration files

Create a working directory. In that directory, create the,, and files.

Create the Networking Module

In the working directory, create the modules/networking directory. In the modules/networking directory, create a file named

In this module, create the following:

resource "aws_vpc" "my_vpc" {


resource "aws_subnet" "public_subnet" {


resource "aws_internet_gateway" "my_ig" {


resource "aws_route_table" "public_route" {


resource "aws_route_table_association" "public_rt_assoc" {


resource "aws_security_group" "web_sg" {


Finish the Networking Module Config

You may have noticed that the modules/networking/ file is not complete. The resource blocks are defined, but the arguments don’t exist!

Your first challenge is to add the missing arguments. Update the file with those arguments now.

Create the Network Module Outputs

You will need to output at least the subnet and security_group resources. Add the outputs blocks for these items to the modules/networking/ file.

Import the Networking Module

Next, update the root directory file to import the networking module.

Create an EC2 Instance

Finally, create an EC2 instance that uses the subnet and security group that was created. These values are outputs from the networking module.

Test Your Work

It’s time to test your work. Run through the following commands. If there is an error, see if you can fix it.

$ terraform init


$ terraform plan


$ terraform apply


Check Your Work

You can reference this repo to see how you did: