Skip to content

Commit

Permalink
Merge pull request #13 from unifio/conditionals
Browse files Browse the repository at this point in the history
Updates & Conditional Logic
  • Loading branch information
blakeneyops committed May 16, 2016
2 parents 6ffc8ae + 7662865 commit 0bbc092
Show file tree
Hide file tree
Showing 38 changed files with 985 additions and 676 deletions.
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.3.0
24 changes: 21 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,30 @@

#### Consider Implementing:
* Added support for Autoscaling "StepScaling" policy.
* Expose `metrics_granularity`, `placement_group`?
* Expose `metrics_granularity`?
* Auto-scaling schedule examples/modules.
* De-duplicate similarities between basic and standard modules.
* Consider coding `ebs_optimized` against list of [ebs-optimized instances](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSOptimized.html).
* Expose ephemeral block device support

## 0.1.2 (Apr, 27, 2016)
## 0.2.0 (May 16, 2016)

#### BACKWARDS INCOMPATIBILITIES / NOTES:
* Resources names updated in several places for standardization. Will cause extra churn in existing environments.

#### IMPROVEMENTS:
* Introduced deterministic conditional logic for the following scenarios:
* Specification of an EBS snapshot to associate with the launch configuration.
* Specification of ELB(s) to associate with the auto scaling group.
* Specification of percentage based simple auto scaling policies.
* All variables explicitly typed per HashiCorp best practices.
* Added name prefixing to security group and launch configuration resources.
* Exposed `associate_public_ip_address` parameter on launch configuration.
* Exposed `placement_tenancy` parameter on launch configuration.
* Exposed root volume configuration parameters on launch configuration.
* Exposed EBS volume configuration parameters on launch configuration.
* Exposed `wait_for_capacity_timeout` parameter on auto scaling group.

## 0.1.2 (Apr 27, 2016)

#### BACKWARDS INCOMPATIBILITIES / NOTES:
* Changed the default value for `ebs_optimized` from `true` -> `false`. This setting is more compatible with the majority of instance types.
Expand Down
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
source "http://rubygems.org"

ruby '2.2.3'

gem "rake"
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GEM
remote: http://rubygems.org/
specs:
rake (10.4.2)
rake (11.1.2)

PLATFORMS
ruby
Expand All @@ -10,4 +10,4 @@ DEPENDENCIES
rake

BUNDLED WITH
1.10.6
1.11.2
342 changes: 178 additions & 164 deletions README.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require 'rake'

inputs = {
'stack_item_label' => 'tst',
'stack_item_fullname' => 'example',
'stack_item_label' => 'expl-tst',
'stack_item_fullname' => 'Example Stack',
'organization' => 'unifio',
'vpc_stack_name' => 'test-vpc',
'vpc_stack_name' => 'unifio/tst-vpc',
'region' => 'us-west-2',
'ami' => 'ami-xxxxxx',
'instance_type' => 't2.small',
Expand Down
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
machine:
environment:
TF_VERSION: 0.6.15
TF_VERSION: 0.6.16
TF_URL: https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_amd64.zip
dependencies:
pre:
Expand Down
37 changes: 26 additions & 11 deletions examples/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ provider "aws" {
region = "${var.region}"
}

provider "atlas" {
}
provider "atlas" {}

## Sources inputs from VPC remote state
resource "terraform_remote_state" "vpc" {
backend = "atlas"

config {
name = "${var.organization}/${var.vpc_stack_name}"
name = "${var.vpc_stack_name}"
}

lifecycle {
Expand All @@ -23,7 +22,7 @@ resource "terraform_remote_state" "vpc" {

## Creates IAM role
resource "aws_iam_role" "role" {
name = "${var.stack_item_label}-${var.region}-example"
name = "${var.stack_item_label}-${var.region}"
path = "/"

lifecycle {
Expand All @@ -47,15 +46,15 @@ EOF
}

resource "aws_iam_instance_profile" "instance_profile" {
name = "${var.stack_item_label}-${var.region}-example"
name = "${var.stack_item_label}-${var.region}"
roles = ["${aws_iam_role.role.name}"]

lifecycle {
create_before_destroy = true
}
}

resource "aws_iam_role_policy" "logs" {
resource "aws_iam_role_policy" "policy_monitoring" {
name = "monitoring"
role = "${aws_iam_role.role.id}"

Expand All @@ -80,7 +79,20 @@ EOF
}

## Adds security group rules
resource "aws_security_group_rule" "ssh" {
resource "aws_security_group_rule" "sg_asg_egress" {
type = "egress"
from_port = 0
to_port = 0
protocol = -1
cidr_blocks = ["0.0.0.0/0"]
security_group_id = "${module.example.sg_id}"

lifecycle {
create_before_destroy = true
}
}

resource "aws_security_group_rule" "sg_asg_ssh" {
type = "ingress"
from_port = 22
to_port = 22
Expand All @@ -98,7 +110,7 @@ resource "template_file" "user_data" {
template = "${file("../templates/user_data.tpl")}"

vars {
hostname = "${var.stack_item_label}-example"
hostname = "${var.stack_item_label}"
domain = "example.org"
region = "${var.region}"
}
Expand All @@ -110,7 +122,9 @@ resource "template_file" "user_data" {

## Provisions basic autoscaling group
module "example" {
source = "github.com/unifio/terraform-aws-asg//group/basic"
# Example GitHub source
#source = "github.com/unifio/terraform-aws-asg//group"
source = "../../group"

# Resource tags
stack_item_label = "${var.stack_item_label}"
Expand All @@ -127,8 +141,9 @@ module "example" {
instance_profile = "${aws_iam_instance_profile.instance_profile.id}"
user_data = "${template_file.user_data.rendered}"
key_name = "${var.key_name}"
ebs_snapshot_id = "expl-snap"

# ASG parameters
max_size = "${var.cluster_max_size}"
min_size = "${var.cluster_min_size}"
max_size = 1
min_size = 1
}
2 changes: 1 addition & 1 deletion examples/basic/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Output Variables
# Outputs

output "sg_id" {
value = "${module.example.sg_id}"
Expand Down
13 changes: 10 additions & 3 deletions examples/basic/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,44 @@

## Resource tags
variable "stack_item_label" {
type = "string"
}

variable "stack_item_fullname" {
type = "string"
}

## VPC parameters
variable "organization" {
}

variable "vpc_stack_name" {
type = "string"
}

variable "region" {
type = "string"
}

## LC parameters
variable "ami" {
type = "string"
}

variable "instance_type" {
type = "string"
}

variable "instance_profile" {
type = "string"
}

variable "key_name" {
type = "string"
}

## ASG parameters
variable "cluster_max_size" {
type = "string"
}

variable "cluster_min_size" {
type = "string"
}
63 changes: 41 additions & 22 deletions examples/standard/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ provider "aws" {
region = "${var.region}"
}

provider "atlas" {
}
provider "atlas" {}

## Sources inputs from VPC remote state
resource "terraform_remote_state" "vpc" {
backend = "atlas"

config {
name = "${var.organization}/${var.vpc_stack_name}"
name = "${var.vpc_stack_name}"
}

lifecycle {
Expand All @@ -23,7 +22,7 @@ resource "terraform_remote_state" "vpc" {

## Creates IAM role
resource "aws_iam_role" "role" {
name = "${var.stack_item_label}-${var.region}-example"
name = "${var.stack_item_label}-${var.region}"
path = "/"

lifecycle {
Expand All @@ -47,15 +46,15 @@ EOF
}

resource "aws_iam_instance_profile" "instance_profile" {
name = "${var.stack_item_label}-${var.region}-example"
name = "${var.stack_item_label}-${var.region}"
roles = ["${aws_iam_role.role.name}"]

lifecycle {
create_before_destroy = true
}
}

resource "aws_iam_role_policy" "logs" {
resource "aws_iam_role_policy" "policy_monitoring" {
name = "monitoring"
role = "${aws_iam_role.role.id}"

Expand All @@ -81,12 +80,12 @@ EOF

## Creates ELB security group
resource "aws_security_group" "sg_elb" {
name = "sg-${var.stack_item_label}-example"
name_prefix = "${var.stack_item_label}-elb-"
description = "Standard ASG example ELB"
vpc_id = "${terraform_remote_state.vpc.output.vpc_id}"

tags {
Name = "${var.stack_item_label}-example-elb"
Name = "${var.stack_item_label}-elb"
application = "${var.stack_item_fullname}"
managed_by = "terraform"
}
Expand Down Expand Up @@ -120,7 +119,7 @@ resource "aws_elb" "elb" {
connection_draining = "${var.connection_draining}"

tags {
Name = "${var.stack_item_label}-example"
Name = "${var.stack_item_label}"
application = "${var.stack_item_fullname}"
managed_by = "terraform"
}
Expand All @@ -146,7 +145,20 @@ resource "aws_elb" "elb" {
}

## Adds security group rules
resource "aws_security_group_rule" "elb" {
resource "aws_security_group_rule" "sg_asg_egress" {
type = "egress"
from_port = 0
to_port = 0
protocol = -1
cidr_blocks = ["0.0.0.0/0"]
security_group_id = "${module.example.sg_id}"

lifecycle {
create_before_destroy = true
}
}

resource "aws_security_group_rule" "sg_asg_elb" {
type = "ingress"
from_port = 22
to_port = 22
Expand All @@ -164,7 +176,7 @@ resource "template_file" "user_data" {
template = "${file("../templates/user_data.tpl")}"

vars {
hostname = "${var.stack_item_label}-example"
hostname = "${var.stack_item_label}"
domain = "example.org"
region = "${var.region}"
}
Expand All @@ -176,7 +188,9 @@ resource "template_file" "user_data" {

## Provisions basic autoscaling group
module "example" {
source = "github.com/unifio/terraform-aws-asg//group/standard"
# Example GitHub source
#source = "github.com/unifio/terraform-aws-asg//group"
source = "../../group"

# Resource tags
stack_item_label = "${var.stack_item_label}"
Expand All @@ -203,7 +217,9 @@ module "example" {

## Provisions autoscaling policies and associated resources
module "scale_up_policy" {
source = "github.com/unifio/terraform-aws-asg//policy/percentage"
# Example GitHub source
#source = "github.com/unifio/terraform-aws-asg//policy"
source = "../../policy"

# Resource tags
stack_item_label = "${var.stack_item_label}-up"
Expand All @@ -216,18 +232,21 @@ module "scale_up_policy" {
notifications = "autoscaling:EC2_INSTANCE_LAUNCH_ERROR,autoscaling:EC2_INSTANCE_TERMINATE_ERROR"

# Monitor parameters
scaling_adjustment = 30
cooldown = 300
min_adjustment_step = 2
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = 2
metric_name = "CPUUtilization"
period = 120
threshold = 10
adjustment_type = "PercentChangeInCapacity"
scaling_adjustment = 30
cooldown = 300
min_adjustment_magnitude = 2
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = 2
metric_name = "CPUUtilization"
period = 120
threshold = 10
}

module "scale_down_policy" {
source = "github.com/unifio/terraform-aws-asg//policy/absolute"
# Example GitHub source
#source = "github.com/unifio/terraform-aws-asg//policy"
source = "../../policy"

# Resource tags
stack_item_label = "${var.stack_item_label}-down"
Expand Down
Loading

0 comments on commit 0bbc092

Please sign in to comment.