Skip to content

Instantly share code, notes, and snippets.

@chrisferry
Created April 2, 2015 21:54
Show Gist options
  • Save chrisferry/f74d57c091f712afef36 to your computer and use it in GitHub Desktop.
Save chrisferry/f74d57c091f712afef36 to your computer and use it in GitHub Desktop.
module "inf-consul" {
source = "../../terraform-modules/asg_elb"
asg_name = "inf_consul_asg"
lc_name = "inf_consul_lc"
ami_id = "${var.ubuntu_amis.us-east-1-hvm}"
instance_type = "t2.medium"
iam_instance_profile = "bootstrap"
key_name = "inf"
security_group = "${aws_security_group.use1-inf.id}"
load_balancers = "inf-consul-elb"
elb_security_group = "${aws_security_group.use1-inf-consul-elb.id}"
elb_listen_port = 8500
vpc_id = "${aws_vpc.us-east-1-vpc.id}"
chef_environment = "inf"
chef_role = "consul-server"
asg_number_of_instances = 5
asg_minimum_number_of_instances = 5
azs = "us-east-1a,us-east-1c,us-east-1d,us-east-1e"
subnet_azs = "${aws_subnet.us-east-1a-private.id},${aws_subnet.us-east-1c-private.id},${aws_subnet.us-east-1d-private.id},${aws_subnet.us-east-1e-private.id}"
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
region = "${var.region}"
}
//
// Module: asg_elb
//
// This template creates the following resources
// - A launch configuration
// - A auto-scaling group
// -
// Provider specific configs
provider "aws" {
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
region = "${var.region}"
}
/* -- THis totally does not work :( -
There's an open issue to create a new resource for ingress/egress rules
Leaving this here as a place holder.
resource "aws_security_group" "use1-inf" {
name = "use1-inf"
description = "US-East-1 Consul ELB Security Group"
ingress {
from_port = "${var.elb_listen_port}"
to_port = "${var.elb_listen_port}"
protocol = "tcp"
security_groups = ["${var.elb_security_group}"]
}
vpc_id = "${var.vpc_id}"
} */
resource "aws_launch_configuration" "launch_config" {
name = "${var.lc_name}"
image_id = "${var.ami_id}"
instance_type = "${var.instance_type}"
iam_instance_profile = "${var.iam_instance_profile}"
key_name = "${var.key_name}"
security_groups = ["${var.security_group}"]
user_data = "${var.user_data}"
}
resource "aws_autoscaling_group" "main_asg" {
//We want this to explicitly depend on the launch config above
depends_on = ["aws_launch_configuration.launch_config"]
//Assumes we want to use the first two ASz of the region
availability_zones = ["${split(",", var.azs)}"]
name = "${var.asg_name}"
// Uses the ID from the launch config created above
launch_configuration = "${aws_launch_configuration.launch_config.id}"
max_size = "${var.asg_number_of_instances}"
min_size = "${var.asg_minimum_number_of_instances}"
desired_capacity = "${var.asg_number_of_instances}"
health_check_grace_period = "${var.health_check_grace_period}"
health_check_type = "${var.health_check_type}"
load_balancers = ["${split(",", var.load_balancers)}"]
// Takes a list of VPC subnet IDS, we assume two, for the two AZs
vpc_zone_identifier = ["${split(",", var.subnet_azs)}"]
tag {
key = "Name"
value = "${var.chef_environment}_${var.chef_role}"
propagate_at_launch = true
}
tag {
key = "Role"
value = "${var.chef_role}"
propagate_at_launch = true
}
tag {
key = "Environment"
value = "${var.chef_environment}"
propagate_at_launch = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment