Skip to content

Commit

Permalink
Merge pull request #28 from unifio/yl-wip
Browse files Browse the repository at this point in the history
Ability to extend asg tags at both group and group/asg levels
  • Loading branch information
yuhunglin authored Aug 3, 2018
2 parents 1afc960 + 2535707 commit db81d6c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
56 changes: 22 additions & 34 deletions group/asg/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
# AWS Auto Scaling Group

## Creates auto scaling group
locals {
default_asg_tags = [
{
key = "application"
value = "${var.stack_item_fullname}"
propagate_at_launch = true
},
{
key = "Name"
value = "${length(var.asg_name_override) > 0 ? var.asg_name_override : var.stack_item_label}"
propagate_at_launch = "${var.propagate_name_at_launch}"
},
{
key = "managed_by"
value = "terraform"
propagate_at_launch = true
},
]
}

resource "aws_autoscaling_group" "asg" {
count = "${length(var.min_elb_capacity) > 0 || length(var.wait_for_elb_capacity) > 0 ? 0 : 1}"

Expand All @@ -23,23 +43,7 @@ resource "aws_autoscaling_group" "asg" {
vpc_zone_identifier = ["${compact(var.subnets)}"]
wait_for_capacity_timeout = "${length(var.wait_for_capacity_timeout) > 0 ? var.wait_for_capacity_timeout : "10m"}"

tag {
key = "application"
value = "${var.stack_item_fullname}"
propagate_at_launch = true
}

tag {
key = "Name"
value = "${length(var.asg_name_override) > 0 ? var.asg_name_override : var.stack_item_label}"
propagate_at_launch = "${var.propagate_name_at_launch}"
}

tag {
key = "managed_by"
value = "terraform"
propagate_at_launch = true
}
tags = "${concat(local.default_asg_tags, var.additional_asg_tags)}"
}

resource "aws_autoscaling_group" "asg_elb" {
Expand Down Expand Up @@ -67,21 +71,5 @@ resource "aws_autoscaling_group" "asg_elb" {
wait_for_capacity_timeout = "${length(var.wait_for_capacity_timeout) > 0 ? var.wait_for_capacity_timeout : "10m"}"
wait_for_elb_capacity = "${length(var.wait_for_elb_capacity) > 0 ? var.wait_for_elb_capacity : "0"}"

tag {
key = "application"
value = "${var.stack_item_fullname}"
propagate_at_launch = true
}

tag {
key = "Name"
value = "${length(var.asg_name_override) > 0 ? var.asg_name_override : var.stack_item_label}"
propagate_at_launch = "${var.propagate_name_at_launch}"
}

tag {
key = "managed_by"
value = "terraform"
propagate_at_launch = true
}
tags = "${concat(local.default_asg_tags, var.additional_asg_tags)}"
}
5 changes: 5 additions & 0 deletions group/asg/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ variable "stack_item_label" {
type = "string"
}

variable "additional_asg_tags" {
type = "list"
default = []
}

## Allow override of resource naming
variable "asg_name_override" {
type = "string"
Expand Down
1 change: 1 addition & 0 deletions group/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ module "asg" {
suspended_processes = ["${var.suspended_processes}"]
termination_policies = ["${var.termination_policies}"]
wait_for_capacity_timeout = "${var.wait_for_capacity_timeout}"
additional_asg_tags = "${var.additional_asg_tags}"

### ELB parameters
load_balancers = ["${var.load_balancers}"]
Expand Down
6 changes: 6 additions & 0 deletions group/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ variable "user_data" {
}

## ASG parameters
variable "additional_asg_tags" {
type = "list"
description = "Additional tags to apply at the ASG level, if any"
default = []
}

variable "default_cooldown" {
type = "string"
description = "The amount of time, in seconds, after a scaling activity completes before another scaling activity can start."
Expand Down

0 comments on commit db81d6c

Please sign in to comment.