├── README.md ├── aws-creds.tf ├── example_tfvars.png └── launch-jupyter.tf /README.md: -------------------------------------------------------------------------------- 1 | # Launch JupyterHub to AWS with Terraform 2 | 3 | This code makes it easy to launch [The Littlest JupyterHub](https://the-littlest-jupyterhub.readthedocs.io/en/latest/) to AWS using [Terraform](https://terraform.io) rather than doing the point-and-click installation. Terraform is an infrastructure as code software that lets you define and provision infrastructure in the public cloud. 4 | 5 | # Prerequisites 6 | 7 | This guide assumes you have: 8 | 9 | - Already downloaded Terraform. If not, you can download it [here](https://www.terraform.io/downloads.html). 10 | - Have an Amazon Web Services account. If not, you can create an account [here](https://aws.amazon.com/). 11 | - Have an AWS access key and secret key. If not, you can create your keys [here](https://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html). 12 | 13 | ## Steps 14 | 15 | 1. Download this repository. 16 | 17 | 2. In the folder, create a file called `terraform.tfvars`. That file should contain your AWS access and secret keys. Below is an example. 18 | 19 | ![alt text](example_tfvars.png) 20 | 21 | 3. In the file `aws-creds.tf`, you can change your AWS region, AMI, and instance size. The defaults are East-1, an Ubuntu Server 18.04 LTS (HVM), and t3.medium. You can learn more about instance sizes [here](https://aws.amazon.com/ec2/pricing/on-demand/). You probably will not change the region or AMI. 22 | 23 | 4. In your command line, navigate to the cloned repository on your computer (e.g., on a Mac in Terminal type `cd ~/Desktop/tf-jupyterhub-aws`). 24 | 25 | 5. The first time you run Terraform, type `terraform init`. 26 | 27 | 6. Then type `terraform apply`. You can review the plan of what Terraform will create. Then you can enter `yes`. 28 | 29 | 7. Terraform will then launch the AWS instance and print the public DNS so you can access the instance. 30 | 31 | 8. The Littlest JupyterHub is now installing in the background on your new server. It takes around 10 minutes for this installation to complete. 32 | 33 | 9. When the installation is complete, navigate to the public DNS and you should see a JupyterHub login page. 34 | 35 | 10. The first time you log in, you should log in using the username `admin` and a password you set. Use a strong password and write it down somewhere, since this will be the password for the admin user account. 36 | 37 | 11. You can check on the status of your instance at https://console.aws.amazon.com/ec2. 38 | 39 | 12. If you ever wish to stop the instance, just enter `terraform destroy` in your command line. This will delete the instance and all files associated with it. -------------------------------------------------------------------------------- /aws-creds.tf: -------------------------------------------------------------------------------- 1 | variable "access_key" {} 2 | 3 | variable "secret_key" {} 4 | 5 | variable "region" { 6 | default = "us-east-1" 7 | } 8 | 9 | variable "ami_id" { 10 | default = "ami-0ac019f4fcb7cb7e6" 11 | } 12 | 13 | variable "instance_type" { 14 | default = "t3.medium" 15 | } -------------------------------------------------------------------------------- /example_tfvars.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshuakalla/tf-jupyterhub-aws/9f1fc56cecea60bde3b693a9ec5c927f61cab0c6/example_tfvars.png -------------------------------------------------------------------------------- /launch-jupyter.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | access_key = "${var.access_key}" 3 | secret_key = "${var.secret_key}" 4 | region = "${var.region}" 5 | } 6 | 7 | # Allow incoming and outgoing traffic. 8 | resource "aws_security_group" "allow_all" { 9 | name = "allow_all" 10 | description = "Allow all inbound traffic" 11 | 12 | ingress { 13 | from_port = 0 14 | to_port = 0 15 | protocol = "-1" 16 | cidr_blocks = ["0.0.0.0/0"] 17 | } 18 | 19 | egress { 20 | from_port = 0 21 | to_port = 0 22 | protocol = "-1" 23 | cidr_blocks = ["0.0.0.0/0"] 24 | } 25 | } 26 | 27 | # Create the AWS Instance. 28 | resource "aws_instance" "jupyterhub" { 29 | ami = "${var.ami_id}" 30 | instance_type = "${var.instance_type}" 31 | tags { 32 | Name = "jupyterhub" 33 | } 34 | 35 | # Load JupyterHub on the instance. 36 | user_data = <