Here is some information about this architecture.
Here are the steps you can follow to build this solution on your own.
You now have some basic experience with Terraform. However, so far you’ve followed instructions given to you.
This is ok to start, but our goal is to teach you how to write your own Terraform code. This lesson will help you reach that goal.
Complete the following lab challenges as best you can.
You can use the same directory and main.tf
file for all lessons in this lab. Create the directory now. Then, create the main.tf
file in it with the following code.
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.42"
}
}
required_version = ">= 0.15.3"
}
provider "aws" {
profile = "skillmix-lab"
region = "us-west-2"
}
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.
Your first challenge is to create an S3 bucket. Use the S3 Docs to learn how to create a bucket with the following attributes:
Name:
ACL: create the ACL resource
Append this code to the main.tf
file. Then, complete the bucket configuration.
# ...previous code above
resource "aws_s3_bucket_acl" "my_bucket_acl" {
# configure the acl here
}
resource "aws_s3_bucket" "my_bucket" {
# configure the bucket here
}
Next, use the Terraform CLI commands to test your work:
# terraform initialize
$ terraform init
# plan
$ terraform plan
# apply
$ terraform apply
In this challenge your goal is to create an IAM Group and User, and then add the user to the group. You can refer to the docs to get the attribute names.
Group Config (docs)
Name: Pick a name
User Config (docs)
Name: Pick a name
Note: There are three resources you need to complete. The last one puts the user into the group.
# ...previous code above
resource "aws_iam_group" "admins" {
# add the relevant attributes
}
resource "aws_iam_user" "boss" {
# add the relevant attributes
}
resource "aws_iam_user_group_membership" "add_boss" {
# add the relevant attributes
}
Next, use the Terraform CLI commands to test your work:
# terraform initialize
$ terraform init
# plan
$ terraform plan
# apply
$ terraform apply
For this challenge, your goal is to create a new VPC and subnet. Use the settings below.
VPC Config (docs)
CIDR Block: 10.0.0.0/16
Subnet Config (docs)
VPC ID: Refer to the VPC ID that you created
CIDR Block: 10.0.1.0/24
# ...previous code above
resource "aws_vpc" "main" {
# add the relevant attributes
}
resource "aws_subnet" "private" {
# add the relevant attributes
}
Next, use the Terraform CLI commands to test your work:
# terraform initialize
$ terraform init
# plan
$ terraform plan
# apply
$ terraform apply
This challenge is going to be harder than the others. Your task is to create an EC2 instance resource that uses the following configuration:
AMI ID: Get the latest Ubuntu Linux AMI ID (it must be Amazon Linux)
Instance Type: t2.micro
VPC: Launch into the VPC and subnet that you created in Challenge #3
You can use these docs to learn how to complete this task. Add the code to main.tf you’ve been building, and use the Terraform CLI commands to apply your work.
AWS Instance
Next, use the Terraform CLI commands to test your work:
# terraform initialize
$ terraform init
# plan
$ terraform plan
# apply
$ terraform apply
You can compare your work with the answers here.
After you’ve completed this lab, run terraform destroy
to remove all of the resources you created.