Creating an RStudio Server using Terraform on AWS

terraform

I’ve created a set of Terraform files to quickly provision an RStudio server on AWS using one of the great ami’s from Louis Aslett http://www.louisaslett.com/RStudio_AMI/

The files contain the following variables:

  • local_ip – the local IP address to be given SSH access
  • region – the aws region for the deployment
  • instance_type – the type of instance to create. see: https://aws.amazon.com/ec2/instance-types/
    zone – the availability zone the server should be created in
  • disk_size – the size of the EBS volume to provision
  • keep_data – whether the EBS volume should be kept on server termination
  • keypair_name – the pre-created key pair name to use
  • private_key – the private key to use to connect via ssh, i.e. the key from the key pair
  • rstudio_password – the password to set for RStudio server

There is also a privision.sh and libraries.R scripts that can be modified to setup the server and install addtional R libraries once its created.

The code is available on github here: https://github.com/ginocoates/rstudio-server-terraform

To provision a server, create a variables.tfvars file, and use terraform to do the grunt work. e.g. create a tfvars file as follows:

"local_ip" = "[your local ip address]"

"region" = "ap-southeast-2"

"instance_type" = "t2.micro"

"zone" = "ap-southeast-2a"

"keypair_name" = "datascience"

"private_key" = "~/.ssh/datascience.pem"

"rstudio_password" = "verysecurepassword"

"disk_size" = "100"

"keep_data" = "false"

Then provision the server as follows

terraform plan -out=terraform.plan -var-file=variables.tfvars

...

terraform apply terraform.plan

Terraform should report as output the public IP and DNS of the newly created server.
Navigate to the IP and the RStudio prompt should be displayed.

 

 

Learn Terraform and RStudio Server…