Ditch Your VPN Subscription: Create Your Own Pay-As-You-Go VPN on GCP in Minutes!
Klemens
Posted on October 31, 2023
Introduction
This guide walks you through the process of setting up a Virtual Private Server (VPS) with OpenVPN on Google Cloud Platform (GCP) using Terraform. Unlike traditional VPN services like NordVPN that require a monthly subscription, this setup allows you to pay only for the minutes you actually use. Plus, you can easily tear down and spin up your VPN server as needed, offering unparalleled flexibility.
Why Choose This Approach?
No Monthly Subscription: Only pay for what you use, down to the minute.
Quick Setup and Teardown: Easily spin up or tear down your VPN server whenever you need it.
Full Control: You have complete control over the server, its security settings, and its location.
Pre-requisites
Terraform installed on your machine.
A Google Cloud Platform (GCP) account with necessary permissions to create resources.
Git (Optional, for cloning the repository)
Step 1: Clone the Repository
First, clone the repository containing the Terraform scripts.
git clone https://github.com/kwisser/create-cloud-compute-engine-ovpn-server
cd create-cloud-compute-engine-ovpn-server/infrastructure
Step 2: Choose a Zone for Your VPN Location
Select a suitable zone for deploying the VM instance. The choice of zone can affect the latency and speed of your VPN. You can find a list of available regions and zones on GCP here.
Step 3: Execute Terraform Scripts
Navigate to the infrastructure directory and initialize Terraform. This will download the necessary provider plugins.
cd infrastructure
terraform init
Now, plan and apply the Terraform configuration. This will show the resources that will be created and apply the changes, respectively. You will have to enter the following variables:
project_id: Your GCP project ID
name: Name of your VM instance
machine_type: Machine type (e.g., f1-micro)
zone: Zone (e.g., us-central1-a)
vm_username: Your username
terraform plan
terraform apply
Upon successful execution, a client.ovpn file will be generated in the user directory. This file can be used to connect to the VPN server from a client machine.
This guide walks through the process of setting up a Virtual Private Server (VPS) with OpenVPN on Google Cloud Platform (GCP) using Terraform. The provided Terraform script will automate the provisioning of a Google Compute Engine instance, and the installation of OpenVPN server on it. Upon successful execution, a client.ovpn configuration file will be generated in the user directory, which can be used to connect to the VPN server from a client machine.