Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix computed count issue #2

Merged
merged 5 commits into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ module "blog_service" {
| `namespace` | `` | Namespace (e.g. `cp` or `cloudposse`) | Yes |
| `stage` | `` | Stage (e.g. `prod`, `dev`, `staging`) | Yes |
| `name` | `` | Name (e.g. `app` or `cluster`) | Yes |
| `vpc_id` | `` | The VPC ID where generated ALB target group (if target_group_arn not set) | Yes |
| `target_group_arn` | `` | ALB target group ARN, if this is an empty string a new one will be generated | No |
| `listener_arns` | `[]` | A list of ALB listener ARNs to attach ALB listener rule to | No |
| `listener_arns_len` | `0` | The number of elements in the listener_arns list | No |
| `deregistration_delay` | `15` | The amount of time to wait in seconds while deregistering target | No |
| `health_check_path` | `/` | The destination for the health check request | No |
| `health_check_timeout` | `10` | The amount of time to wait in seconds before failing a health check request | No |
Expand All @@ -72,9 +74,8 @@ module "blog_service" {
| `priority` | `100` | The priority for the rule between 1 and 50000 (1 being highest priority) | No |
| `port` | `80` | The port for generated ALB target group (if target_group_arn not set) | No |
| `protocol` | `HTTP` | The protocol for generated ALB target group (if target_group_arn not set) | No |
| `vpc_id` | `` | The VPC ID where generated ALB target group (if target_group_arn not set) | No |
| `paths` | `[]` | Path pattern to match (a maximum of 1 can be defined) | No |
| `hosts` | `[]` | Hosts to match in Hosts header | No |
| `paths` | `[]` | Path pattern to match (a maximum of 1 can be defined), required if hosts not set | No |
| `hosts` | `[]` | Hosts to match in Hosts header, required if paths not set | No |
| `attributes` | `[]` | Additional attributes (e.g. `1`) | No |
| `tags` | `{}` | Additional tags (e.g. `map("BusinessUnit","XYZ")` | No |
| `delimiter` | `-` | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | No |
Expand Down Expand Up @@ -168,4 +169,4 @@ or [hire us][hire] to help build your next cloud platform.
[igor_img]: http://s.gravatar.com/avatar/bc70834d32ed4517568a1feb0b9be7e2?s=144
[igor_web]: https://github.com/goruha/
[sarkis_img]: https://avatars3.githubusercontent.com/u/42673?s=144&v=4
[sarkis_web]: https://github.com/sarkis/
[sarkis_web]: https://github.com/sarkis/
6 changes: 3 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ resource "aws_lb_target_group" "default" {
}

resource "aws_lb_listener_rule" "paths" {
count = "${length(var.paths) > 0 && length(var.hosts) == 0 ? length(var.listener_arns) : 0}"
count = "${length(var.paths) > 0 && length(var.hosts) == 0 ? var.listener_arns_len : 0}"
listener_arn = "${var.listener_arns[count.index]}"
priority = "${var.priority + count.index}"

Expand All @@ -58,7 +58,7 @@ resource "aws_lb_listener_rule" "paths" {
}

resource "aws_lb_listener_rule" "hosts" {
count = "${length(var.hosts) > 0 && length(var.paths) == 0 ? length(var.listener_arns) : 0}"
count = "${length(var.hosts) > 0 && length(var.paths) == 0 ? var.listener_arns_len : 0}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use _count for consistency with our other modules

listener_arn = "${var.listener_arns[count.index]}"
priority = "${var.priority + count.index}"

Expand All @@ -74,7 +74,7 @@ resource "aws_lb_listener_rule" "hosts" {
}

resource "aws_lb_listener_rule" "hosts_paths" {
count = "${length(var.paths) > 0 && length(var.hosts) > 0 ? length(var.listener_arns) : 0}"
count = "${length(var.paths) > 0 && length(var.hosts) > 0 ? var.listener_arns_len : 0}"
listener_arn = "${var.listener_arns[count.index]}"
priority = "${var.priority + count.index}"

Expand Down
22 changes: 19 additions & 3 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
variable "namespace" {
type = "string"
description = "Namespace, which could be your organization name, e.g. `cp` or `cloudposse`"
}

variable "stage" {
type = "string"
description = "Stage, e.g. `prod`, `staging`, `dev`, or `test`"
}

variable "name" {
type = "string"
description = "Solution name, e.g. `app`"
}

Expand All @@ -29,6 +32,7 @@ variable "tags" {
}

variable "target_group_arn" {
type = "string"
default = ""
description = "ALB target group ARN, if this is an empty string a new one will be generated"
}
Expand All @@ -39,37 +43,50 @@ variable "listener_arns" {
description = "A list of ALB listener ARNs to attach ALB listener rule to"
}

variable "listener_arns_len" {
type = "string"
default = "0"
description = "The number of ARNs in listener_arns, this is necessary to work around a limitation in Terraform where counts cannot be computed"
}

variable "deregistration_delay" {
type = "string"
default = "15"
description = "The amount of time to wait in seconds while deregistering target"
}

variable "health_check_path" {
type = "string"
default = "/"
description = "The destination for the health check request"
}

variable "health_check_timeout" {
type = "string"
default = "10"
description = "The amount of time to wait in seconds before failing a health check request"
}

variable "health_check_healthy_threshold" {
type = "string"
default = "2"
description = "The number of consecutive health checks successes required before healthy"
}

variable "health_check_unhealthy_threshold" {
type = "string"
default = "2"
description = "The number of consecutive health check failures required before unhealthy"
}

variable "health_check_interval" {
type = "string"
default = "15"
description = "The duration in seconds in between health checks"
}

variable "health_check_matcher" {
type = "string"
default = "200-399"
description = "The HTTP response codes to indicate a healthy check"
}
Expand Down Expand Up @@ -99,18 +116,17 @@ variable "target_type" {

variable "vpc_id" {
type = "string"
default = ""
description = "The VPC ID where generated ALB target group will be provisioned (if target_group_arn not set)"
}

variable "hosts" {
type = "list"
default = []
description = "Hosts to match in Hosts header"
description = "Hosts to match in Hosts header, at least one of hosts or paths must be set"
}

variable "paths" {
type = "list"
default = []
description = "Path pattern to match (a maximum of 1 can be defined)"
description = "Path pattern to match (a maximum of 1 can be defined), at least one of hosts or paths must be set"
}