This repository is no longer a supported Sourcegraph deployment method. If you'd like to deploy Sourcegraph, please see our Deployment Documentation to learn about our supported deployment methods.
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.
- 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.
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.
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_id
variable must be set in theterraform.tfvars
file.
The Makefile
has commands to cover the most common use-cases. The easiest way to create your Droplet is to run:
make deploy
This 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 apply
completesmake destroy
: Removes all created from resources
WARNING:
make destroy
will destroy the Droplet so back-up the/etc/sourcegraph
and/var/opt/sourcegraph
directories first.
To upgrade Sourcegraph:
- SSH into the EC2 instance
- Run
./sourcegraph-upgrade
The newer Docker image will be pulled and Sourcegraph will be restarted.
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
.
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 destroy
to remove the current instance - Run
make deploy
again to get a public hostname and IP