Terraform Cloud Project Bootcamp with Andrew Brown — 2.0.0 Setting up Terratowns Mock Web Server
This article is part of my Terraform journey with Terraform Bootcamp by Andrew Brown and Andrew Bayko with Chris Williams and Shala.
My wild career adventure into Cloud Computing continues with Andrews, and I highly, highly recommend you to come join us if you are interested. Check out Andrews’ free youtube learning contents. You can also buy some paid courses here to support their good cause.
Agenda
Video here: 2 0 0 Setting up Terratowns Mock Web Server
Issue #42 Goals
- ✅ 1) Download Terratowns mock server into our repo
Workflow
- ✅ 1) Initial Setup
- ✅ 2) Run, understand & document server.rb
- ✅ 3) Test if endpoints work correctly
1. Initial Setup
git clone https://github.com/ExamProCo/terratowns_mock_server.git
cd terratowns_mock_server
ls -la
# We should remove the .git tracker.
# Make sure that you are inside the terratowns_mock_server directory.
# Otherwise you can just blow away your own repo and the whole work.
rm -rf .git
Now, move the sinatra server setup from ./terratowns_mock_server/gitpod.yaml
to gitpod.yaml
at root.
- name: sinatra
before: |
cd $PROJECT_ROOT
cd terratowns_mock_server
bundle install
bundle exec ruby server.rb
Then change the name of the bin
directory in terratowns_mock_server
to terratowns
, then move it to our bin
directory at root.
Now, commit the code so that we can launch a new gitpod workspace to test if the Ruby server runs correctly on launch.
2. Run, understand & document server.rb
Andrew prepared in advance the ruby server code we will use for building our TerraHouses. A good part of this video tutorial is dedicated to understanding what this server code does and documenting comments on what each line does. I’m not going to paste it here. You can find the code here instead.
3. Test if endpoints work correctly
You really have to follow the video hands-on as Andrew makes minor changes and tweaks around the code here and there for endpoints testing.
In the sinatra server terminal, you can interact with the server directly. Try running the following commands:
home
home.domain_name
payload
home
$home[:domain_name]
While working through the server modification, we use the following commands to verify if the endpoints do what they are intended to do:
./bin/terratowns/create
./bin/terratowns/read [UUID]
./bin/terratowns/update [UUID]
./bin/terratowns/delete [UUID]
Andrew modifies the #DELETE operation code to print the UUID that is deleted.
# delete from mock database
- uuid = $home['uuid']
+ uuid = $home[:uuid]
$home = {}
- { message: "House deleted successfully" }.to_json
+ { uuid: uuid }.to_json
end
Now that the Mock Server is ready, we will move on to building our own custom provider in the next session.
Notes
$variable
in Ruby (dollar sign + variable name) means it’s a global variable.- The PUT method in web servers typically updates an existing resource.
bundle install
command installs packages for Ruby.
Resources
Bootcamp
- Video: 2 0 0 Setting up Terratowns Mock Web Server
- ExamProCo Terratowns Mock Server Repo
- My feature branch: 45-terratowns-mock-server
- My complete Learning Journal