From 675f25b6db5681550432874653f39b9bcc0658c4 Mon Sep 17 00:00:00 2001 From: Danny Smith Date: Tue, 6 Oct 2020 14:26:30 +0100 Subject: [PATCH 1/3] Add toggle to stickiness due to TF/AWS API issues --- README.md | 11 +++++++++-- main.tf | 14 +++++++++++--- variables.tf | 2 ++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6f4b4c2..4d7466b 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,13 @@ module "nlb" { Using [aws-terraform-cloudwatch\_alarm](https://github.com/rackspace-infrastructure-automation/aws-terraform-cloudwatch_alarm) to create the following CloudWatch Alarms: - unhealthy\_host\_count\_alarm +## Requirements + +| Name | Version | +|------|---------| +| terraform | >= 0.12 | +| aws | >= 2.20 | + ## Providers | Name | Version | @@ -93,7 +100,7 @@ Using [aws-terraform-cloudwatch\_alarm](https://github.com/rackspace-infrastruct ## Inputs | Name | Description | Type | Default | Required | -|------|-------------|------|---------|:-----:| +|------|-------------|------|---------|:--------:| | create\_internal\_zone\_record | Create Route 53 internal zone record for the NLB. i.e true \| false | `bool` | `false` | no | | cross\_zone | configure cross zone load balancing | `bool` | `true` | no | | eni\_count | explicitly tell terraform how many subnets to expect | `number` | `0` | no | @@ -109,7 +116,7 @@ Using [aws-terraform-cloudwatch\_alarm](https://github.com/rackspace-infrastruct | rackspace\_managed | Boolean parameter controlling if instance will be fully managed by Rackspace support teams, created CloudWatch alarms that generate tickets, and utilize Rackspace managed SSM documents. | `bool` | `true` | no | | route\_53\_hosted\_zone\_id | the zone\_id in which to create our ALIAS | `string` | `""` | no | | subnet\_ids | list of subnet ids (1 per AZ only) to attach to this NLB | `list(string)` | n/a | yes | -| subnet\_map | **not implemented** subnet -> EIP mapping | `map(list(string))` |
{
"0": [
"eip-1",
"subnet-1"
]
}
| no | +| subnet\_map | \*\*not implemented\*\* subnet -> EIP mapping | `map(list(string))` |
{
"0": [
"eip-1",
"subnet-1"
]
}
| no | | tags | tags map | `map(string)` | `{}` | no | | tg\_map | target group map | `map(map(string))` | n/a | yes | | vpc\_id | VPC ID | `string` | n/a | yes | diff --git a/main.tf b/main.tf index b937894..1f1cfa5 100644 --- a/main.tf +++ b/main.tf @@ -162,9 +162,17 @@ resource "aws_lb_target_group" "tg" { "instance", ) - stickiness { - type = "lb_cookie" - enabled = false + dynamic "stickiness" { + for_each = lookup( + var.tg_map[element(local.tg_keys, count.index)], + "stickiness_placeholder", + false, + ) ? toset(["build"]) : toset([]) + + content { + enabled = false + type = "lb_cookie" + } } health_check { diff --git a/variables.tf b/variables.tf index 9a17b6d..d161dc5 100644 --- a/variables.tf +++ b/variables.tf @@ -145,6 +145,8 @@ tg_map = { "target_type" = "instance" } } + +N.B. if you receive an error `Network Load Balancers do not support Stickiness` then try adding a key to your problem target groups of `stickiness_placeholder = true` */ variable "tg_map" { description = "target group map" From c8a1566532baefda1a9102f8c09deb20467ca97d Mon Sep 17 00:00:00 2001 From: Danny Smith Date: Tue, 6 Oct 2020 14:29:07 +0100 Subject: [PATCH 2/3] Use correct version of terraform-docs --- README.md | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4d7466b..6f4b4c2 100644 --- a/README.md +++ b/README.md @@ -83,13 +83,6 @@ module "nlb" { Using [aws-terraform-cloudwatch\_alarm](https://github.com/rackspace-infrastructure-automation/aws-terraform-cloudwatch_alarm) to create the following CloudWatch Alarms: - unhealthy\_host\_count\_alarm -## Requirements - -| Name | Version | -|------|---------| -| terraform | >= 0.12 | -| aws | >= 2.20 | - ## Providers | Name | Version | @@ -100,7 +93,7 @@ Using [aws-terraform-cloudwatch\_alarm](https://github.com/rackspace-infrastruct ## Inputs | Name | Description | Type | Default | Required | -|------|-------------|------|---------|:--------:| +|------|-------------|------|---------|:-----:| | create\_internal\_zone\_record | Create Route 53 internal zone record for the NLB. i.e true \| false | `bool` | `false` | no | | cross\_zone | configure cross zone load balancing | `bool` | `true` | no | | eni\_count | explicitly tell terraform how many subnets to expect | `number` | `0` | no | @@ -116,7 +109,7 @@ Using [aws-terraform-cloudwatch\_alarm](https://github.com/rackspace-infrastruct | rackspace\_managed | Boolean parameter controlling if instance will be fully managed by Rackspace support teams, created CloudWatch alarms that generate tickets, and utilize Rackspace managed SSM documents. | `bool` | `true` | no | | route\_53\_hosted\_zone\_id | the zone\_id in which to create our ALIAS | `string` | `""` | no | | subnet\_ids | list of subnet ids (1 per AZ only) to attach to this NLB | `list(string)` | n/a | yes | -| subnet\_map | \*\*not implemented\*\* subnet -> EIP mapping | `map(list(string))` |
{
"0": [
"eip-1",
"subnet-1"
]
}
| no | +| subnet\_map | **not implemented** subnet -> EIP mapping | `map(list(string))` |
{
"0": [
"eip-1",
"subnet-1"
]
}
| no | | tags | tags map | `map(string)` | `{}` | no | | tg\_map | target group map | `map(map(string))` | n/a | yes | | vpc\_id | VPC ID | `string` | n/a | yes | From cf12ec83803c72ffe28fc8cfcb5e435bcefe756f Mon Sep 17 00:00:00 2001 From: Danny Smith Date: Sun, 25 Oct 2020 14:58:26 +0000 Subject: [PATCH 3/3] stickiness_placeholder added to tests --- tests/test1/main.tf | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/test1/main.tf b/tests/test1/main.tf index 5e4083f..161e0e5 100644 --- a/tests/test1/main.tf +++ b/tests/test1/main.tf @@ -139,9 +139,10 @@ module "external" { tg_map = { listener1 = { - dereg_delay = 300 - port = 80 - target_type = "instance" + dereg_delay = 300 + port = 80 + target_type = "instance" + stickiness_placeholder = true } } @@ -200,9 +201,10 @@ module "internal" { tg_map = { listener1 = { - dereg_delay = 300 - port = 80 - target_type = "instance" + dereg_delay = 300 + port = 80 + target_type = "instance" + stickiness_placeholder = true } } @@ -233,4 +235,3 @@ module "asg" { module.internal.target_group_arns, ) } -