Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vpc #12

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions bastion/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
variable "environment" {}
variable "subnet_id" {}
variable "key_name" {}
variable "sg_id" {}

resource "aws_instance" "bastion_instance" {
ami = "ami-5189a661"
instance_type = "t2.micro"
vpc_security_group_ids = ["${var.sg_id}"]
subnet_id = "${var.subnet_id}"
key_name = "${var.key_name}"

associate_public_ip_address = true
source_dest_check = false

tags {
Name = "${var.environment}-bastion"
}
}
18 changes: 2 additions & 16 deletions database/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,9 @@ variable "username" {}
variable "password" {}
variable "port" {}
variable "subnet_group_name" {}
variable "vpc_id" {}
variable "main_host_security_group_id" {}
variable "security_group_id" {}
variable "instance_class" {}

resource "aws_security_group" "database_sg" {
name = "${var.environment}-database-sg"
description = "Allow inbound traffic from main host to DB port"
vpc_id = "${var.vpc_id}"

ingress {
from_port = 5432
to_port = 5432
protocol = "tcp"
security_groups = ["${var.main_host_security_group_id}"]
}
}

resource "aws_db_instance" "main_postgres_db" {
allocated_storage = 10
engine = "postgres"
Expand All @@ -30,6 +16,6 @@ resource "aws_db_instance" "main_postgres_db" {
password = "${var.password}"
port = "${var.port}"
db_subnet_group_name = "${var.subnet_group_name}"
vpc_security_group_ids = ["${aws_security_group.database_sg.id}"]
vpc_security_group_ids = ["${var.security_group_id}"]
skip_final_snapshot = true
}
10 changes: 2 additions & 8 deletions environments/runnable-on-prem.example.tfvars
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
# All variables in this document should match
domain = ""
github_org_id = ""
public_key = ""
db_username = "" # Must start with a letter
db_password = ""
db_subnet_group_name = ""
main_host_vpc_id = ""
main_host_subnet_id = ""
main_host_private_ip = "10.4.0.100"
dock_subnet_id = ""
github_org_id = ""
key_name = ""
lc_user_data_file_location = "~/dock-runnable-on-prem.sh"
bastion_sg_id = ""
environment = "runnable-on-prem"
aws_region = "us-west-2"
185 changes: 0 additions & 185 deletions instances-and-security-groups/main.tf

This file was deleted.

85 changes: 85 additions & 0 deletions instances/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
variable "environment" {}
variable "main_host_subnet_id" {}
variable "main_host_instance_type" {}
variable "dock_subnet_id" {}
variable "dock_instance_type" {}
variable "private_ip" {}
variable "github_org_id" {}
variable "lc_user_data_file_location" {}
variable "key_name" {}
variable "main_sg_id" {}
variable "dock_sg_id" {}

# Changing AMI forces new resource and will delete all everything in main host
# Ovewrite this variable with previous AMI if update is pushed
variable "main_host_ami" {
default = "ami-5fa7353f" # singe-host-ami-build-v0.0.4
}

variable "dock_ami" {
default = "ami-557dee35" # dock-ami-build-v.0.0.8
}

resource "aws_instance" "main_instance" {
ami = "${var.main_host_ami}"
instance_type = "${var.main_host_instance_type}"
associate_public_ip_address = true
private_ip = "${var.private_ip}"
vpc_security_group_ids = ["${var.main_sg_id}"]
subnet_id = "${var.main_host_subnet_id}"
key_name = "${var.key_name}"

tags {
Name = "${var.environment}-main"
}
}

resource "aws_launch_configuration" "dock_lc" {
name_prefix = "${var.environment}-dock-lc-"
image_id = "${var.dock_ami}"
instance_type = "${var.dock_instance_type}"
user_data = "${file("${var.lc_user_data_file_location}")}"
key_name = "${var.key_name}"
security_groups = ["${var.dock_sg_id}"]

root_block_device {
volume_size = 10
}

ebs_block_device {
device_name = "/dev/sdb"
snapshot_id = "snap-c77705e9"
volume_size = 50
}

lifecycle {
create_before_destroy = true
}
}

resource "aws_autoscaling_group" "dock_auto_scaling_group" {
name = "asg-${var.environment}-${var.github_org_id}"
max_size = 30
min_size = 2
health_check_grace_period = 300
health_check_type = "EC2"
desired_capacity = 2 # Start off with 0 and increase manually when main host is running
vpc_zone_identifier = ["${var.dock_subnet_id}"]
launch_configuration = "${aws_launch_configuration.dock_lc.name}"

lifecycle {
create_before_destroy = true
}

tag {
key = "org"
value = "${var.github_org_id}"
propagate_at_launch = true
}

tag {
key = "enviroment"
value = "${var.environment}"
propagate_at_launch = true
}
}
12 changes: 12 additions & 0 deletions keypair/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
variable "public_key" {}
variable "environment" {}

resource "aws_key_pair" "main_key" {
key_name = "${var.environment}-key-pair"
public_key = "${var.public_key}"
}

output "key_pair_name" {
value = "${aws_key_pair.main_key.key_name}"
}

Loading