Create a cheap http-proxy on GCP with terraform ( tutorial )

Ion Utale
3 min readNov 11, 2021

Sometime is very useful to have a private, high performance.
This this terraform script you can easily create one ready to use. And when you’re done, just “terraform destroy” to stop paying for it.

Create a VM with centOS 8

The script is almost identical to the VM+Docker.

Let’s write down the essentials:

  1. First we need to declare the provider, in our case the “google

2. Provide the GCP Project ID, region and zone to where you want the VM to run on:

Get project id from “Select a Project” window
Provide the project ID and the region for the Google Cloud Compute Virtual Machine

3. Create a Google Cloud VM (optionally with static ip address)

— Will “inject” a SSH public key from the .ssh folder so that you can connect in SSH from your terminal.
It will add a static address to the VM.
— It will load the script.sh (just create an empty file), after the machine has started. We will use the script to install the squid proxy server.

Create a static ip address, GCP will pick one for you bases on the availability in the cloud. You can create one separately.

Finally create the network that will handle the VM networking and attach the static IP.

Create the firewall resources that will open the connections on some specific ports. For SSH PORT 22 and for the proxy the PORT 3128 (squid default port configuration).

Add installation commands to the script.sh file

In the script above we:
— Update the yum packages
— Install squid
— Replace the “http_access deny all” text in the configuration file squid.conf with “http_access allow all”
— Open the linux firewall rule for the port 3128
— Create an certificate for ssl (https)
— Create an folder for squid certificates
— Move the certificate to the certificates folder
— Change ownership of the certificate to squid
— Log the squid configurations to the console
— Confirm the config is okay
— Create the SSL database
— Make sure the squid user can access it
— Enable the squid service
— Start squid
— Confirm it’s running

Congratulations

You now have a proxy server ready on PORT 3128

Troubleshooting

Sometimes the squid is not being installed on the VM, this looks like an terraform issue, to overcome this unpleasant experience please SSH into the machine, paste the entire script to install it manually. Here is the GitHub Repository in case you need it or you want to create a pull-request.

Thank you for reading and if you like-it please leave some “claps”, it really helps me a lot

--

--