Skip to content

Commit

Permalink
feat: Add more specific tags (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
quentin9696 authored Apr 13, 2020
1 parent 9240edc commit 607b8b2
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ module "lb" {
| idle\_timeout | The time in seconds that the connection is allowed to be idle. | `number` | `60` | no |
| internal | Boolean determining if the load balancer is internal or externally facing. | `bool` | `false` | no |
| 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 |
| lb\_tags | A map of tags to add to load balancer | `map(string)` | `{}` | no |
| listener\_ssl\_policy\_default | The security policy if using HTTPS externally on the load balancer. [See](https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-security-policy-table.html). | `string` | `"ELBSecurityPolicy-2016-08"` | no |
| load\_balancer\_create\_timeout | Timeout value when creating the ALB. | `string` | `"10m"` | no |
| load\_balancer\_delete\_timeout | Timeout value when deleting the ALB. | `string` | `"10m"` | no |
Expand All @@ -256,7 +257,8 @@ module "lb" {
| subnet\_mapping | A list of subnet mapping blocks describing subnets to attach to network load balancer | `list(map(string))` | `[]` | no |
| subnets | A list of subnets to associate with the load balancer. e.g. ['subnet-1a2b3c4d','subnet-1a2b3c4e','subnet-1a2b3c4f'] | `list(string)` | `null` | no |
| tags | A map of tags to add to all resources | `map(string)` | `{}` | no |
| target\_groups | A list of maps containing key/value pairs that define the target groups to be created. Order of these maps is important and the index of these are to be referenced in listener definitions. Required key/values: name, backend\_protocol, backend\_port. Optional key/values are in the target\_groups\_defaults variable. | `any` | `[]` | no |
| target\_group\_tags | A map of tags to add to all target groups | `map(string)` | `{}` | no |
| target\_groups | A list of maps containing key/value pairs that define the target groups to be created. Order of these maps is important and the index of these are to be referenced in listener definitions. Required key/values: name, backend\_protocol, backend\_port | `any` | `[]` | no |
| vpc\_id | VPC id where the load balancer and other resources will be deployed. | `string` | `null` | no |

## Outputs
Expand Down
11 changes: 11 additions & 0 deletions examples/complete-alb/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ module "alb" {
protocol = "HTTP"
matcher = "200-399"
}
tags = {
InstanceTargetGroupTag = "baz"
}
},
{
name_prefix = "l1-"
Expand All @@ -204,4 +207,12 @@ module "alb" {
tags = {
Project = "Unknown"
}

lb_tags = {
MyLoadBalancer = "foo"
}

target_group_tags = {
MyGlobalTargetGroupTag = "bar"
}
}
3 changes: 3 additions & 0 deletions examples/complete-nlb/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ module "nlb" {
backend_protocol = "TCP_UDP"
backend_port = 81
target_type = "instance"
tags = {
tcp_udp = true
}
},
{
name_prefix = "u1-"
Expand Down
3 changes: 3 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ resource "aws_lb" "this" {

tags = merge(
var.tags,
var.lb_tags,
{
Name = var.name != null ? var.name : var.name_prefix
},
Expand Down Expand Up @@ -94,6 +95,8 @@ resource "aws_lb_target_group" "main" {

tags = merge(
var.tags,
var.target_group_tags,
lookup(var.target_groups[count.index], "tags", {}),
{
"Name" = lookup(var.target_groups[count.index], "name", lookup(var.target_groups[count.index], "name_prefix", ""))
},
Expand Down
14 changes: 13 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,26 @@ variable "tags" {
default = {}
}

variable "lb_tags" {
description = "A map of tags to add to load balancer"
type = map(string)
default = {}
}

variable "target_group_tags" {
description = "A map of tags to add to all target groups"
type = map(string)
default = {}
}

variable "security_groups" {
description = "The security groups to attach to the load balancer. e.g. [\"sg-edcd9784\",\"sg-edcd9785\"]"
type = list(string)
default = []
}

variable "target_groups" {
description = "A list of maps containing key/value pairs that define the target groups to be created. Order of these maps is important and the index of these are to be referenced in listener definitions. Required key/values: name, backend_protocol, backend_port. Optional key/values are in the target_groups_defaults variable."
description = "A list of maps containing key/value pairs that define the target groups to be created. Order of these maps is important and the index of these are to be referenced in listener definitions. Required key/values: name, backend_protocol, backend_port"
type = any
default = []
}
Expand Down

0 comments on commit 607b8b2

Please sign in to comment.