Here is some information about this architecture.
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:
Create a project and module directory
Complete the networking module configuration
Use the networking module configuration to launch an EC2 instance into its subnet
Verify your work in the AWS Console
Let’s get started. We’ll go show the order you can approach this.
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 working directory. In that directory, create the main.tf
, variables.tf
, and outputs.tf
files.
In the working directory, create the modules/networking
directory. In the modules/networking
directory, create a file named main.tf
.
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" {
}
You may have noticed that the modules/networking/main.tf
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 main.tf file
with those arguments now.
You will need to output at least the subnet
and security_group
resources. Add the outputs blocks for these items to the modules/networking/outputs.tf
file.
Next, update the root directory main.tf
file to import the networking module.
Finally, create an EC2 instance that uses the subnet and security group that was created. These values are outputs from the networking module.
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
...output
$ terraform plan
...output
$ terraform apply
...output
You can reference this repo to see how you did: https://github.com/tabdon/terraform_module_2_challenge