Deploying Sourcegraph on EC2
This Terraform plan deploys Sourcegraph to an EC2 instance with SSL using a self-signed certificate.
This plan will create:
- An EC2 instance
- Security group with inbound ports
22,80, and443 - IAM role and and IAM instance profile
- Depending upon configuration, a
key pair(see plan configuration)
See how it works by watching this screencast on Vimeo.com.
Prerequisites
- Make (installed if you're macOS and Linux)
- Terraform
- mkcert (optional but required for self-signed cert validation)
NOTE: A basic level of knowledge and experience using AWS IAM and Terraform is required.
Terraform AWS authentication
You can authenticate with AWS using one of the methods described in the Terraform AWS authentication docs.
If you haven't done this before, using environment vars is recommended.
Terraform plan configuration
The existence of a terraform.tfvars file is required. To create it, copy the contents of terraform.tfvars.sample to a new terraform.tfvars file and review to see which variables you'd like to set.
You'll likely set key_name (if you already have a key pair), or public_key and key_name which if both specified, will create the key . If neither are these are set, you can still deploy Sourcegraph, but you'll be unable to SSH to the instance.
NOTE: If the region does not have a default VPC,
vpc_idvariable must be set in theterraform.tfvarsfile.
Commands
The Makefile has commands to cover the most common use-cases. The easiest way to create your Droplet is to run:
make deployThis will create all resources and and poll the server to let you know when Sourcegraph is ready.
Other commands include:
make init: Download the required Terraform provider packagesmake plan: Anything to add, remove or change?make apply: Create the EC2 instance and other required resourcesmake sourcegraph: Wait for Sourcegraph to be ready to accept connectionsmake output: Display the same output as whenmake applycompletesmake destroy: Removes all created from resources
WARNING:
make destroywill destroy the Droplet so back-up the/etc/sourcegraphand/var/opt/sourcegraphdirectories first.
Upgrading Sourcegraph
To upgrade Sourcegraph:
- SSH into the EC2 instance
- Run
./sourcegraph-upgrade
The newer Docker image will be pulled and Sourcegraph will be restarted.
Troubleshooting
Default VPC error
If you get:
Error: Error refreshing state: 1 error(s) occurred:
* data.aws_vpc.default: 1 error(s) occurred:
* data.aws_vpc.default: data.aws_vpc.default: no matching VPC found
It means you don't have a default VPC in the currently specified region. Either choose a different region that has a default VPC or provide a vpc_id value in terraform.tfvars.
No public IP or hostname assigned
If the instance has no public IP address, get the subnet id the instance belongs to, then in the AWS console:
- VPC
- Subnets
- Select the subnet
- Actions: Modify auto-assign IP settings
- check "Auto-assign IPv4" and save
- Run
make destroyto remove the current instance - Run
make deployagain to get a public hostname and IP

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

