Skip to content

Commit 0d7968f

Browse files
authored
feat: Add tags to listener and listener rules (#199)
1 parent 36350e8 commit 0d7968f

File tree

5 files changed

+55
-3
lines changed

5 files changed

+55
-3
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,13 @@ module "lb" {
293293
| Name | Version |
294294
|------|---------|
295295
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
296-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.27 |
296+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.40 |
297297

298298
## Providers
299299

300300
| Name | Version |
301301
|------|---------|
302-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.27 |
302+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.40 |
303303

304304
## Modules
305305

@@ -329,8 +329,11 @@ No modules.
329329
| <a name="input_enable_http2"></a> [enable\_http2](#input\_enable\_http2) | Indicates whether HTTP/2 is enabled in application load balancers. | `bool` | `true` | no |
330330
| <a name="input_extra_ssl_certs"></a> [extra\_ssl\_certs](#input\_extra\_ssl\_certs) | A list of maps describing any extra SSL certificates to apply to the HTTPS listeners. Required key/values: certificate\_arn, https\_listener\_index (the index of the listener within https\_listeners which the cert applies toward). | `list(map(string))` | `[]` | no |
331331
| <a name="input_http_tcp_listeners"></a> [http\_tcp\_listeners](#input\_http\_tcp\_listeners) | A list of maps describing the HTTP listeners or TCP ports for this ALB. Required key/values: port, protocol. Optional key/values: target\_group\_index (defaults to http\_tcp\_listeners[count.index]) | `any` | `[]` | no |
332+
| <a name="input_http_tcp_listeners_tags"></a> [http\_tcp\_listeners\_tags](#input\_http\_tcp\_listeners\_tags) | A map of tags to add to all tcp listeners | `map(string)` | `{}` | no |
332333
| <a name="input_https_listener_rules"></a> [https\_listener\_rules](#input\_https\_listener\_rules) | A list of maps describing the Listener Rules for this ALB. Required key/values: actions, conditions. Optional key/values: priority, https\_listener\_index (default to https\_listeners[count.index]) | `any` | `[]` | no |
334+
| <a name="input_https_listener_rules_tags"></a> [https\_listener\_rules\_tags](#input\_https\_listener\_rules\_tags) | A map of tags to add to all https listener rules | `map(string)` | `{}` | no |
333335
| <a name="input_https_listeners"></a> [https\_listeners](#input\_https\_listeners) | A list of maps describing the HTTPS listeners for this ALB. Required key/values: port, certificate\_arn. Optional key/values: ssl\_policy (defaults to ELBSecurityPolicy-2016-08), target\_group\_index (defaults to https\_listeners[count.index]) | `any` | `[]` | no |
336+
| <a name="input_https_listeners_tags"></a> [https\_listeners\_tags](#input\_https\_listeners\_tags) | A map of tags to add to all https listeners | `map(string)` | `{}` | no |
334337
| <a name="input_idle_timeout"></a> [idle\_timeout](#input\_idle\_timeout) | The time in seconds that the connection is allowed to be idle. | `number` | `60` | no |
335338
| <a name="input_internal"></a> [internal](#input\_internal) | Boolean determining if the load balancer is internal or externally facing. | `bool` | `false` | no |
336339
| <a name="input_ip_address_type"></a> [ip\_address\_type](#input\_ip\_address\_type) | The type of IP addresses used by the subnets for your load balancer. The possible values are ipv4 and dualstack. | `string` | `"ipv4"` | no |

examples/complete-alb/main.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,18 @@ module "alb" {
328328
target_group_tags = {
329329
MyGlobalTargetGroupTag = "bar"
330330
}
331+
332+
https_listener_rules_tags = {
333+
MyLoadBalancerHTTPSListenerRule = "bar"
334+
}
335+
336+
https_listeners_tags = {
337+
MyLoadBalancerHTTPSListener = "bar"
338+
}
339+
340+
http_tcp_listeners_tags = {
341+
MyLoadBalancerTCPListener = "bar"
342+
}
331343
}
332344

333345
#########################

main.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,12 @@ resource "aws_lb_listener_rule" "https_listener_rule" {
347347
}
348348
}
349349
}
350+
351+
tags = merge(
352+
var.tags,
353+
var.https_listener_rules_tags,
354+
lookup(var.https_listener_rules[count.index], "tags", {}),
355+
)
350356
}
351357

352358
resource "aws_lb_listener" "frontend_http_tcp" {
@@ -389,6 +395,12 @@ resource "aws_lb_listener" "frontend_http_tcp" {
389395
}
390396
}
391397
}
398+
399+
tags = merge(
400+
var.tags,
401+
var.http_tcp_listeners_tags,
402+
lookup(var.http_tcp_listeners[count.index], "tags", {}),
403+
)
392404
}
393405

394406
resource "aws_lb_listener" "frontend_https" {
@@ -477,6 +489,12 @@ resource "aws_lb_listener" "frontend_https" {
477489
target_group_arn = aws_lb_target_group.main[lookup(default_action.value, "target_group_index", count.index)].id
478490
}
479491
}
492+
493+
tags = merge(
494+
var.tags,
495+
var.https_listeners_tags,
496+
lookup(var.https_listeners[count.index], "tags", {}),
497+
)
480498
}
481499

482500
resource "aws_lb_listener_certificate" "https_listener" {

variables.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,25 @@ variable "target_group_tags" {
148148
default = {}
149149
}
150150

151+
variable "https_listener_rules_tags" {
152+
description = "A map of tags to add to all https listener rules"
153+
type = map(string)
154+
default = {}
155+
}
156+
157+
variable "https_listeners_tags" {
158+
description = "A map of tags to add to all https listeners"
159+
type = map(string)
160+
default = {}
161+
}
162+
163+
variable "http_tcp_listeners_tags" {
164+
description = "A map of tags to add to all tcp listeners"
165+
type = map(string)
166+
default = {}
167+
}
168+
169+
151170
variable "security_groups" {
152171
description = "The security groups to attach to the load balancer. e.g. [\"sg-edcd9784\",\"sg-edcd9785\"]"
153172
type = list(string)

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ terraform {
22
required_version = ">= 0.13.1"
33

44
required_providers {
5-
aws = ">= 3.27"
5+
aws = ">= 3.40"
66
}
77
}

0 commit comments

Comments
 (0)