Infrastructure as code using Terraform for Coder

Last week I came across the awesome Open Source solution called coder (https://coder.com) which allows you to host your own Visual Studio Code as a Web Application! I’ve spent very little time with this but am impressed on how quickly and easily this solution gets you up to speed … unlike the other solutions like Apache che for example…

At the same time, I have been trying to learn Terraform with aws as the provider…. So, I decided to make a new multi-tiered environment using Terraform with Coder getting auto deployed. To add a twist in the spec I wanted coder to be the online ssh terminal to administer the private servers. After a few experimentations I have now completed this and am sharing the code in https://github.com/julianfrank/coderonaws

Coder on AWS – Sample Design

The above diagram represents the environment generated… Interested?? If yes continue reading

Step 1: Clone the repo

git clone https://github.com/julianfrank/coderonaws
cd coderonaws

Step 2: Download and Install terraform

The terraform website has the details for each OS… https://learn.hashicorp.com/terraform/getting-started/install.html#installing-terraform

Step 3: Provide your aws details

You will find .tfvars files in each of the three directories (base, public and private)

Provide you aws account details

# Amazon AWS Access Key
aws_access_key = "<AWS account Key"
# Amazon AWS Secret Key
aws_secret_key = "AWS Secret Key"

You can change the other variables as well if you want .. To see a list of variables you can change check out the vardefs.tf file to see the list

Do not forget to rename the .tfvars.template files to .tfvars

mv *.tfvars.template *.tfvars

Step 4: Start Conjuring the environment creation

Change directory back to the coderonaws folder and fire up the start.bat if you are on windows

./start.bat

On other OS you would need to manually go to each folder and invoke terraform apply manually

cd base
terraform apply -auto-approve
cd public
terraform apply -auto-approve
cd private
terraform apply -auto-approve

If all went well, you should see a log file in the public and private folders with the url you can use to connect to your coder instance

…github.com\julianfrank\coderonaws> cat .\public\public.log
{public_ssh: ssh -i "###.pem" ec2-user@ec2-54-213-122-60.us-west-2.compute.amazonaws.com}
{coder_url: http://ec2-54-213-122-60.us-west-2.compute.amazonaws.com}
{nat_ssh: ssh -i "###.pem" ec2-user@ip-172-16-0-121.us-west-2.compute.internal}
…github.com\julianfrank\coderonaws> cat .\private\private.log
{public_ssh: ssh -i \"###.pem\" ec2-user@172.16.1.145}

Open the coder_url in your favorite modern browser (not ie9)… You should be welcomed with a Password challenge

By default I have used `PASSword’ as the password… To change this default password in the runcoder.sh file in the files folder and reconjure the environment…

Click on the ‘ENTER IDE’ button and you will be presented with the coder ui

Now control + ` to open the terminal

Now lookup the log files to see the command line for the server you want to access… and type it in the terminal to get ssh access… All Interactive TUI works perfectly fine in the terminal.

Cool right…

Step 5: Now to tear down the environment…

Back to the local cli and invoke the ./destroy.bat to destroy the entire vpc and instances cleanly from your account…

If you don’t destroy you may get billed on the instance usage….

Not bad right!

Just a cautionary note… Now the design in this repo is not really secure and ready for enterprise production use….So use with care

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s