Skip to content

Commit

Permalink
Refactor and extend to launch logsearch-workspace spot instance on AWS
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdavidlaing committed Aug 3, 2015
1 parent 33f7ec4 commit 0bb566d
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 33 deletions.
15 changes: 15 additions & 0 deletions _setup/terraform/aws-workspace/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

0. Setup your AWS credentials
```
export TF_VAR_access_key=$AWS_ACCESS_KEY_ID
export TF_VAR_secret_key=$AWS_SECRET_ACCESS_KEY
export TF_VAR_workspace_key_name="pcf"
export TF_VAR_workspace_subnet_id="subnet-fcd4838b" #pcf-public-az-a
export TF_VAR_workspace_security_group_id0="sg-2032c147" #workspace
export TF_VAR_workspace_security_group_id1="sg-6a1a080e" #stayup-pcf-VMs
export TF_VAR_workspace_security_group_id2="sg-65fa4302" #staff_office_ips
```
Make sure that you had `ssh-add`ed the key to your keychain

0. `/path/to/logsearch-workspace/_setup/terraform/aws-workspace$ terraform apply`
46 changes: 46 additions & 0 deletions _setup/terraform/aws-workspace/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
provider "aws" {
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
region = "us-east-1"
}

resource "aws_spot_instance_request" "workspace_instance" {
ami = "ami-3fee3b54" #BOSH lite 9000.38
instance_type = "m3.xlarge"
spot_price = "0.15"

wait_for_fulfillment = true
key_name = "${var.workspace_key_name}"
tags {
Name = "workspace_instance"
}

subnet_id = "${var.workspace_subnet_id}"

This comment has been minimized.

Copy link
@mrdavidlaing

mrdavidlaing Aug 3, 2015

Author Member

Looks like there is a bug in Terraform 0.6.1 that prevents starting a spot instance in a VPC subnet. hashicorp/terraform#2919

#vpc_security_group_ids = ["${var.workspace_security_group_id0}", "${var.workspace_security_group_id1}", "${var.workspace_security_group_id2}"]

root_block_device {
volume_type = "gp2"
volume_size = 100
}

provisioner "remote-exec" {
script = "provision.sh"
connection {
user = "ubuntu"
}
}
}

resource "aws_ebs_volume" "workspace_disk" {
availability_zone = "us-east-1a"
size = 40
tags {
Name = "workspace_disk"
}
}

resource "aws_volume_attachment" "workspace_ebs_att" {
device_name = "/dev/sdf"
volume_id = "${aws_ebs_volume.workspace_disk.id}"
instance_id = "${aws_spot_instance_request.workspace_instance.spot_instance_id}"
}
10 changes: 10 additions & 0 deletions _setup/terraform/aws-workspace/provision.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
echo "Provisioning!"

apt-get -y install git

exit 0

git clone https://github.com/logsearch/workspace /root/logsearch-workspace
cd /root/logsearch-workspace
_setup/runtime/install_dependancies
7 changes: 7 additions & 0 deletions _setup/terraform/aws-workspace/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
variable "access_key" {}
variable "secret_key" {}
variable "workspace_key_name" {}
variable "workspace_subnet_id" {}
variable "workspace_security_group_id0" {}
variable "workspace_security_group_id1" {}
variable "workspace_security_group_id2" {}
30 changes: 0 additions & 30 deletions _setup/terraform/bosh/bosh.tf

This file was deleted.

3 changes: 0 additions & 3 deletions _setup/terraform/bosh/variables.tf

This file was deleted.

0 comments on commit 0bb566d

Please sign in to comment.