Skip to content

Commit

Permalink
Merge pull request #20 from unifio/dbi-ease-refactor
Browse files Browse the repository at this point in the history
Added ability to override suffix/prefix for stack_item_label in asg/lc
  • Loading branch information
disaac authored May 4, 2017
2 parents 7563032 + c1b7362 commit e0aaa8b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
8 changes: 4 additions & 4 deletions group/asg/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ resource "aws_autoscaling_group" "asg" {
max_size = "${var.max_size}"
metrics_granularity = "${var.metrics_granularity}"
min_size = "${var.min_size}"
name = "${var.stack_item_label}"
name = "${length(var.asg_name_override) > 0 ? var.asg_name_override : var.stack_item_label}"
placement_group = "${var.placement_group}"
protect_from_scale_in = "${var.protect_from_scale_in}"
suspended_processes = ["${compact(var.suspended_processes)}"]
Expand All @@ -31,7 +31,7 @@ resource "aws_autoscaling_group" "asg" {

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

Expand All @@ -57,7 +57,7 @@ resource "aws_autoscaling_group" "asg_elb" {
metrics_granularity = "${var.metrics_granularity}"
min_elb_capacity = "${length(var.min_elb_capacity) > 0 ? var.min_elb_capacity : "0"}"
min_size = "${var.min_size}"
name = "${var.stack_item_label}"
name = "${length(var.asg_name_override) > 0 ? var.asg_name_override : var.stack_item_label}"
placement_group = "${var.placement_group}"
protect_from_scale_in = "${var.protect_from_scale_in}"
suspended_processes = ["${compact(var.suspended_processes)}"]
Expand All @@ -75,7 +75,7 @@ resource "aws_autoscaling_group" "asg_elb" {

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

Expand Down
6 changes: 6 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"
}

## Allow override of resource naming
variable "asg_name_override" {
type = "string"
}

## VPC parameters
variable "subnets" {
type = "list"
Expand All @@ -20,6 +25,7 @@ variable "lc_id" {
}

## ASG parameters

variable "default_cooldown" {
type = "string"
}
Expand Down
4 changes: 2 additions & 2 deletions group/lc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
## Creates security group
resource "aws_security_group" "sg_asg" {
description = "${var.stack_item_fullname} security group"
name_prefix = "${var.stack_item_label}-asg-"
name_prefix = "${length(var.lc_sg_name_prefix_override) > 0 ? format("%s-", var.lc_sg_name_prefix_override) : format("%s-asg-", var.stack_item_label)}"
vpc_id = "${var.vpc_id}"

tags {
application = "${var.stack_item_fullname}"
managed_by = "terraform"
Name = "${var.stack_item_label}-asg"
Name = "${length(var.lc_sg_name_prefix_override) > 0 ? var.lc_sg_name_prefix_override : format("%s-asg", var.stack_item_label)}"
}

lifecycle {
Expand Down
5 changes: 5 additions & 0 deletions group/lc/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ variable "stack_item_label" {
type = "string"
}

## Allow override of resource naming
variable "lc_sg_name_prefix_override" {
type = "string"
}

## VPC parameters
variable "vpc_id" {
type = "string"
Expand Down
6 changes: 4 additions & 2 deletions group/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ module "lc" {
source = "lc"

### Resource labels
stack_item_fullname = "${var.stack_item_fullname}"
stack_item_label = "${var.stack_item_label}"
stack_item_fullname = "${var.stack_item_fullname}"
stack_item_label = "${var.stack_item_label}"
lc_sg_name_prefix_override = "${var.lc_sg_name_prefix_override}"

### VPC parameters
vpc_id = "${var.vpc_id}"
Expand Down Expand Up @@ -96,6 +97,7 @@ module "asg" {
### Resource tags
stack_item_label = "${var.stack_item_label}"
stack_item_fullname = "${var.stack_item_fullname}"
asg_name_override = "${var.asg_name_override}"

### VPC parameters
subnets = ["${var.subnets}"]
Expand Down
12 changes: 12 additions & 0 deletions group/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ variable "stack_item_label" {
description = "Short form identifier for this stack. This value is used to create the 'Name' resource tag for resources created by this stack item, and also serves as a unique key for re-use."
}

variable "asg_name_override" {
type = "string"
description = "A string to override the ASG name"
default = ""
}

variable "lc_sg_name_prefix_override" {
type = "string"
description = "A string to override the ASG name"
default = ""
}

## VPC parameters
variable "subnets" {
type = "list"
Expand Down

0 comments on commit e0aaa8b

Please sign in to comment.