Are you fed up with trying to awkwardly develop on a windows machine, tried WSL2 and woke up one day to it being totally bawked by Windows 11? Fear not - Your free-tier AWS dev environment is here! This is a slight extension of Derek Morgan's course that teaches you how to build a dev instance in AWS using terraform.
This repo is based on infrastructure deployed in Derek Morgan's course "Build a Dev Environment with AWS and Terraform". If you want to understand the underlying terraform code and what it's doing I really recommend taking the time to go through Derek's awesome content.
After running through this readme you will have a way to spin up a development instance in AWS at will. It will be accessible from your local machine over SSH using the native plugin for VScode. Your Dev instance will:
- Be running Ubuntu
- Have python3 installled
- Have Docker installed
- Have Terraform installed
- Have an IAM role attached with Admin access to your AWS account
So, what are you waiting for!? Clone this repo and let's do it.
- A Windows machine
- A working installation of vscode
- Chocolatey package manager for Windows - Not essential but helps!
- Creating an AWS account
- Creating Terraform credentials in AWS
- Creating an SSH key
- Installing terraform
- Deploying your dev instance
- Connect to your instance
Follow this guide to create and secure a new AWS account.
- Log into your AWS account using the IAM user created in step 4 of the creating an AWS account video guide linked in the previous step.
- Create a new user with programatic access only and save the Access and Secret keys somewhere safe!
- Run
.\scripts\aws_setup.ps1
to generate an AWS credentials file (assuming you don't have one already). This will give Terraform what it needs to create resources in your account.
- In a PowerShell window enter the command
ssh-keygen -t ed25519
to create your keypair. - Copy your public key to the root directory of this repo.
cp ~/.ssh/awsDevInstanceKey.pub .
you'll need it later!
- If you already have Chocolatey installed then simply run
choco install terraform
- If you're unable to install chocolatey then follow these steps to get terraform installed.
- Firstly generate your tfvars file by running
.\scripts\generate_tfvars.ps1
- This script will pull your public IP from whatsmyip.com and also set the local_development variable to true
- Run
terraform init
to initialise the directory - Run
terraform apply
. Terraform will output a list of things that will happen, i.e stuff that will be created in your AWS account. Like this:
- Type
yes
and hit enter. - Terraform will now go off and create the below infra in your account
Remember in an earlier section when I said to copy your public key as you'll need it later? This is that time!
Firstly we need to add that SSH key to Github, so copy the contents of your public key to your clipboard and follow the guide here
- Copy the name of your SSH key to your clipboard
awsDevInstanceKey
if you followed these instructions exactly. - Run
./scripts/github_setup.ps1
and paste your keyname in.
-
The script will grab the SSH key you've specified and copy it to the remote host. It will also copy an SSH config file telling the remote host to use that key for github access.
-
If you didn't follow exactly, or would like to use a different SSH key for github access. Then all you need to do is edit the below line in
./scripts/config
to reflect the correct key name.
Host github.com
HostName github.com
IdentityFile ~/.ssh/awsDevInstanceKey <-- THIS ONE!!
- Once your terraform completes, you will see an output that looks like this:
ssh_config_info = <<EOT
Host 3.8.2.100
HostName 3.8.2.100
User ubuntu
IdentityFile ~/.ssh/devInstanceKey
EOT
- This is the SSH information for your brand new EC2 dev instance
- Run
.\scripts\add_to_ssh_config.ps1
to add the SSH information to your config file and allow you to connect. - Install the SSH extension to vscode
- Click on Extensions
(ctrl+shift+x)
typessh
into the search box and installRemote - SSH
by Microsoft.
- Click on Extensions
- Press ctrl+shift+p to open the command pallet and type
ssh
clickRemote-SSH: Connect to host...
- The FIRST IP address in the list will be your AWS instance, as the script will always place the latest IP address at the top of the config file. Click on it!
- Click on Linux
- Click on continue
- press
ctrl + '
to open a terminal window and runchmod 600 ~/.ssh/awsDevInstanceKey
(or your custom key name) - Your instance is now ready to use and has permissions to your AWS account via an instance role as well as github access.