Skip to content

Commit

Permalink
terraform fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
iuriaranda committed Jun 26, 2017
1 parent c90ea1b commit a8b44db
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 148 deletions.
80 changes: 40 additions & 40 deletions blue-green/main.tf
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
module "blue" {
source = "../single-stack"
color = "blue"
max_size = "${var.blue_max_size}"
min_size = "${var.blue_min_size}"
source = "../single-stack"
color = "blue"
max_size = "${var.blue_max_size}"
min_size = "${var.blue_min_size}"
desired_capacity = "${var.blue_desired_capacity}"
ami = "${var.blue_ami}"
ami = "${var.blue_ami}"

loadbalancers = "${var.loadbalancers}"
project = "${var.project}"
name = "${var.name}"
environment = "${var.environment}"
instance_type = "${var.instance_type}"
key_name = "${var.key_name}"
security_groups = "${var.security_groups}"
iam_instance_profile = "${var.iam_instance_profile}"
loadbalancers = "${var.loadbalancers}"
project = "${var.project}"
name = "${var.name}"
environment = "${var.environment}"
instance_type = "${var.instance_type}"
key_name = "${var.key_name}"
security_groups = "${var.security_groups}"
iam_instance_profile = "${var.iam_instance_profile}"
associate_public_ip_address = "${var.associate_public_ip_address}"
user_data = "${var.user_data}"
disk_volume_size = "${var.disk_volume_size}"
disk_volume_type = "${var.disk_volume_type}"
subnets = "${var.subnets}"
health_check_grace_period = "${var.health_check_grace_period}"
termination_policies = ["${var.termination_policies}"]
target_group_arns = "${var.target_group_arns}"
user_data = "${var.user_data}"
disk_volume_size = "${var.disk_volume_size}"
disk_volume_type = "${var.disk_volume_type}"
subnets = "${var.subnets}"
health_check_grace_period = "${var.health_check_grace_period}"
termination_policies = ["${var.termination_policies}"]
target_group_arns = "${var.target_group_arns}"
}

module "green" {
source = "../single-stack"
color = "green"
max_size = "${var.green_max_size}"
min_size = "${var.green_min_size}"
source = "../single-stack"
color = "green"
max_size = "${var.green_max_size}"
min_size = "${var.green_min_size}"
desired_capacity = "${var.green_desired_capacity}"
ami = "${var.green_ami}"
ami = "${var.green_ami}"

loadbalancers = "${var.loadbalancers}"
project = "${var.project}"
name = "${var.name}"
environment = "${var.environment}"
instance_type = "${var.instance_type}"
key_name = "${var.key_name}"
security_groups = "${var.security_groups}"
iam_instance_profile = "${var.iam_instance_profile}"
loadbalancers = "${var.loadbalancers}"
project = "${var.project}"
name = "${var.name}"
environment = "${var.environment}"
instance_type = "${var.instance_type}"
key_name = "${var.key_name}"
security_groups = "${var.security_groups}"
iam_instance_profile = "${var.iam_instance_profile}"
associate_public_ip_address = "${var.associate_public_ip_address}"
user_data = "${var.user_data}"
disk_volume_size = "${var.disk_volume_size}"
disk_volume_type = "${var.disk_volume_type}"
subnets = "${var.subnets}"
health_check_grace_period = "${var.health_check_grace_period}"
termination_policies = ["${var.termination_policies}"]
target_group_arns = "${var.target_group_arns}"
user_data = "${var.user_data}"
disk_volume_size = "${var.disk_volume_size}"
disk_volume_type = "${var.disk_volume_type}"
subnets = "${var.subnets}"
health_check_grace_period = "${var.health_check_grace_period}"
termination_policies = ["${var.termination_policies}"]
target_group_arns = "${var.target_group_arns}"
}
54 changes: 37 additions & 17 deletions blue-green/variables.tf
Original file line number Diff line number Diff line change
@@ -1,92 +1,112 @@
variable "project" {
description = "Project name to use"
}

variable "name" {
description = "Name of the stack"
}

variable "environment" {
description = "Environment to deploy on"
}

variable "blue_ami" {
description = "(Required) The EC2 image ID to launch in the blue autoscaling group"
}

variable "green_ami" {
description = "(Required) The EC2 image ID to launch in the green autoscaling group"
}

variable "instance_type" {
description = "(Required) The size of instance to launch"
}

variable "key_name" {
description = "(Optional) The key name that should be used for the instance"
default = ""
default = ""
}

variable "loadbalancers" {
type = "list"
type = "list"
description = "(Optional) A list of load balancer names to add to the autoscaling groups"
default = []
default = []
}

variable "security_groups" {
type = "list"
type = "list"
description = "(Optional) A list of associated security group IDS"
default = []
default = []
}

variable "iam_instance_profile" {
description = "(Optional) The IAM instance profile to associate with launched instances"
default = ""
default = ""
}

variable "associate_public_ip_address" {
description = "(Optional) Associate a public ip address with an instance in a VPC"
default = false
default = false
}

variable "user_data" {
description = "(Optional) The user data to provide when launching the instance"
default = ""
default = ""
}

variable "disk_volume_size" {
description = "(Optional) The size of the volume in gigabytes"
default = "8"
default = "8"
}

variable "disk_volume_type" {
description = "(Optional) The type of the volume. Default is standard"
default = "standard"
default = "standard"
}

variable "subnets" {
description = "(Optional) A list of subnet IDs to launch resources in"
type = "list"
default = []
type = "list"
default = []
}

variable "blue_max_size" {
description = "(Required) The maximum size of the blue autoscaling group"
}

variable "blue_min_size" {
description = "(Required) The minimum size of the blue autoscaling group"
}

variable "blue_desired_capacity" {
description = "(Required) The number of Amazon EC2 instances that should be running in the blue autoscaling roup"
}

variable "green_max_size" {
description = "(Required) The maximum size of the green autoscaling group"
}

variable "green_min_size" {
description = "(Required) The minimum size of the green autoscaling group"
}

variable "green_desired_capacity" {
description = "(Required) The number of Amazon EC2 instances that should be running in the green autoscaling roup"
}

variable "health_check_grace_period" {
description = "(Optional, Default: 300) Time (in seconds) after instance comes into service before checking health"
default = "300"
default = "300"
}

variable "termination_policies" {
description = "(Optional, Default: ['Default']) Order in termination policies to apply when choosing instances to terminate."
type = "list"
default = ["Default"]
type = "list"
default = ["Default"]
}

variable "target_group_arns" {
type = "list"
type = "list"
description = "A list of aws_alb_target_group ARNs, for use with Application Load Balancing"
default = []
default = []
}
64 changes: 34 additions & 30 deletions cpu-scaling/main.tf
Original file line number Diff line number Diff line change
@@ -1,53 +1,57 @@
resource "aws_cloudwatch_metric_alarm" "alarm-cpu-down" {
count = "${var.num_asg}"
alarm_name = "${var.environment}-${var.project}-${var.name}-cpu-down${count.index}"
count = "${var.num_asg}"
alarm_name = "${var.environment}-${var.project}-${var.name}-cpu-down${count.index}"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = "${var.evaluation_periods}"
metric_name = "CPUUtilization"
namespace = "${var.namespace}"
period = "${var.period_down}"
statistic = "${var.statistic}"
threshold = "${var.threshold_down}"
evaluation_periods = "${var.evaluation_periods}"
metric_name = "CPUUtilization"
namespace = "${var.namespace}"
period = "${var.period_down}"
statistic = "${var.statistic}"
threshold = "${var.threshold_down}"

dimensions {
AutoScalingGroupName = "${var.autoscaling_group_name[count.index]}"
}

alarm_description = "This metric monitors CPU utilization down"
alarm_actions = ["${aws_autoscaling_policy.down-cpu.*.arn}"]
alarm_actions = ["${aws_autoscaling_policy.down-cpu.*.arn}"]
}

resource "aws_cloudwatch_metric_alarm" "alarm-cpu-up" {
count = "${var.num_asg}"
alarm_name = "${var.environment}-${var.project}-${var.name}-cpu-up${count.index}"
count = "${var.num_asg}"
alarm_name = "${var.environment}-${var.project}-${var.name}-cpu-up${count.index}"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "${var.evaluation_periods}"
metric_name = "CPUUtilization"
namespace = "${var.namespace}"
period = "${var.period_up}"
statistic = "${var.statistic}"
threshold = "${var.threshold_up}"
evaluation_periods = "${var.evaluation_periods}"
metric_name = "CPUUtilization"
namespace = "${var.namespace}"
period = "${var.period_up}"
statistic = "${var.statistic}"
threshold = "${var.threshold_up}"

dimensions {
AutoScalingGroupName = "${var.autoscaling_group_name[count.index]}"
}

alarm_description = "This metric monitors CPU utilization up"
alarm_actions = ["${aws_autoscaling_policy.up-cpu.*.arn}"]
alarm_actions = ["${aws_autoscaling_policy.up-cpu.*.arn}"]
}

resource "aws_autoscaling_policy" "up-cpu" {
count = "${var.num_asg}"
name = "${var.environment}-${var.project}-${var.name}-cpu-up${count.index}"
count = "${var.num_asg}"
name = "${var.environment}-${var.project}-${var.name}-cpu-up${count.index}"
autoscaling_group_name = "${var.autoscaling_group_name[count.index]}"
adjustment_type = "ChangeInCapacity"
policy_type = "${var.policy_type}"
cooldown = "${var.cooldown_up}"
scaling_adjustment = "${var.adjustment_up}"
adjustment_type = "ChangeInCapacity"
policy_type = "${var.policy_type}"
cooldown = "${var.cooldown_up}"
scaling_adjustment = "${var.adjustment_up}"
}

resource "aws_autoscaling_policy" "down-cpu" {
count = "${var.num_asg}"
name = "${var.environment}-${var.project}-${var.name}-cpu-down${count.index}"
count = "${var.num_asg}"
name = "${var.environment}-${var.project}-${var.name}-cpu-down${count.index}"
autoscaling_group_name = "${var.autoscaling_group_name[count.index]}"
adjustment_type = "ChangeInCapacity"
policy_type = "${var.policy_type}"
cooldown = "${var.cooldown_down}"
scaling_adjustment = "${var.adjustment_down}"
adjustment_type = "ChangeInCapacity"
policy_type = "${var.policy_type}"
cooldown = "${var.cooldown_down}"
scaling_adjustment = "${var.adjustment_down}"
}
Loading

0 comments on commit a8b44db

Please sign in to comment.