-
-
Save danielfrg/8db7f72d79694da60edb4f5b8d17e1e4 to your computer and use it in GitHub Desktop.
terraform gravitational template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "aws_access_key_id" {} | |
variable "aws_secret_access_key" {} | |
variable "aws_region" {} | |
variable "key_pair" { | |
default = "adam" | |
} | |
variable "cluster_name" { | |
default = "daniel-ae5" | |
} | |
variable "nodes" { | |
default = 2 | |
} | |
variable "instance_type" { | |
default = "c4.8xlarge" | |
} | |
variable "ami" { | |
default = "ami-0ddc3060" | |
} | |
provider "aws" { | |
access_key = "${var.aws_access_key_id}" | |
secret_key = "${var.aws_secret_access_key}" | |
region = "${var.aws_region}" | |
} | |
output "private_ips" { | |
value = "${join(" ", aws_instance.node.*.private_ip)}" | |
} | |
output "public_ips" { | |
value = "${join(" ", aws_instance.node.*.public_ip)}" | |
} | |
resource "aws_placement_group" "cluster" { | |
name = "${var.cluster_name}" | |
strategy = "cluster" | |
} | |
# ALL UDP and TCP traffic is allowed within the security group | |
resource "aws_security_group" "cluster" { | |
tags { | |
Name = "${var.cluster_name}" | |
} | |
# Admin gravity site for testing | |
ingress { | |
from_port = 32009 | |
to_port = 32009 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
# SSH access from anywhere | |
ingress { | |
from_port = 22 | |
to_port = 22 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
# install wizard | |
ingress { | |
from_port = 61009 | |
to_port = 61009 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
ingress { | |
from_port = 0 | |
to_port = 65535 | |
protocol = "tcp" | |
self = true | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
ingress { | |
from_port = 0 | |
to_port = 65535 | |
protocol = "udp" | |
self = true | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
egress { | |
from_port = 0 | |
to_port = 0 | |
protocol = "-1" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
} | |
resource "aws_instance" "node" { | |
ami = "${var.ami}" | |
instance_type = "${var.instance_type}" | |
associate_public_ip_address = true | |
source_dest_check = "false" | |
ebs_optimized = true | |
security_groups = ["${aws_security_group.cluster.name}"] | |
key_name = "${var.key_pair}" | |
placement_group = "${aws_placement_group.cluster.id}" | |
count = "${var.nodes}" | |
tags { | |
Name = "${var.cluster_name}" | |
} | |
volume_tags { | |
Name = "${var.cluster_name}" | |
} | |
user_data = <<EOF | |
#!/bin/bash | |
umount /dev/xvdb | |
mkfs.ext4 /dev/xvdb | |
mkfs.ext4 /dev/xvdf | |
sed -i.bak '/xvdb/d' /etc/fstab | |
echo -e '/dev/xvdb\t/var/lib/gravity\text4\tdefaults\t0\t2' >> /etc/fstab | |
echo -e '/dev/xvdf\t/var/lib/gravity/planet/etcd\text4\tdefaults\t0\t2' >> /etc/fstab | |
mkdir -p /var/lib/gravity | |
mount /var/lib/gravity | |
mkdir -p /var/lib/gravity/planet/etcd | |
mount /var/lib/gravity/planet/etcd | |
chown -R 1000:1000 /var/lib/gravity /var/lib/gravity/planet/etcd | |
EOF | |
root_block_device { | |
volume_type = "io1" | |
volume_size = "500" | |
iops = 1000 | |
delete_on_termination = true | |
} | |
# /var/lib/gravity device with all the stuff (docker, etc) | |
ebs_block_device = { | |
volume_type = "io1" | |
volume_size = "200" | |
device_name = "/dev/xvdb" | |
iops = 1500 | |
delete_on_termination = true | |
} | |
# etcd device on a separate disk, so it's not too flaky | |
ebs_block_device = { | |
volume_size = "100" | |
volume_type = "io1" | |
device_name = "/dev/xvdf" | |
iops = 1500 | |
delete_on_termination = true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment