Skip to content

Commit

Permalink
feat: additional target group attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
joshsizer committed Feb 9, 2024
1 parent 3e9c6cb commit 893a811
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ No modules.
| [aws_lb_listener_certificate.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb_listener_certificate) | resource |
| [aws_lb_listener_rule.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb_listener_rule) | resource |
| [aws_lb_target_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb_target_group) | resource |
| [aws_lb_target_group_attachment.additional_target_group_attachments](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb_target_group_attachment) | resource |
| [aws_lb_target_group_attachment.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb_target_group_attachment) | resource |
| [aws_route53_record.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
| [aws_security_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) | resource |
Expand All @@ -384,6 +385,7 @@ No modules.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_access_logs"></a> [access\_logs](#input\_access\_logs) | Map containing access logging configuration for load balancer | `map(string)` | `{}` | no |
| <a name="input_additional_target_group_attachments"></a> [additional\_target\_group\_attachments](#input\_additional\_target\_group\_attachments) | Map of additional target group attchments to create | `any` | `{}` | no |
| <a name="input_associate_web_acl"></a> [associate\_web\_acl](#input\_associate\_web\_acl) | Indicates whether a Web Application Firewall (WAF) ACL should be associated with the load balancer | `bool` | `false` | no |
| <a name="input_connection_logs"></a> [connection\_logs](#input\_connection\_logs) | Map containing access logging configuration for load balancer | `map(string)` | `{}` | no |
| <a name="input_create"></a> [create](#input\_create) | Controls if resources should be created (affects nearly all resources) | `bool` | `true` | no |
Expand Down
1 change: 1 addition & 0 deletions examples/complete-alb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Note that this example may create resources which cost money. Run `terraform des
| [aws_cognito_user_pool.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cognito_user_pool) | resource |
| [aws_cognito_user_pool_client.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cognito_user_pool_client) | resource |
| [aws_cognito_user_pool_domain.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cognito_user_pool_domain) | resource |
| [aws_instance.other](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance) | resource |
| [aws_instance.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance) | resource |
| [null_resource.download_package](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
Expand Down
15 changes: 15 additions & 0 deletions examples/complete-alb/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,15 @@ module "alb" {
}
}

additional_target_group_attachments = {
ex-instance-other = {
target_group = "ex-instance"
target_type = "instance"
target_id = aws_instance.other.id
port = "80"
}
}

# Route53 Record(s)
route53_records = {
A = {
Expand Down Expand Up @@ -530,6 +539,12 @@ resource "aws_instance" "this" {
subnet_id = element(module.vpc.private_subnets, 0)
}

resource "aws_instance" "other" {
ami = data.aws_ssm_parameter.al2.value
instance_type = "t3.nano"
subnet_id = element(module.vpc.private_subnets, 0)
}

##################################################################
# AWS Cognito User Pool
##################################################################
Expand Down
11 changes: 11 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,17 @@ resource "aws_lb_target_group_attachment" "this" {
depends_on = [aws_lambda_permission.this]
}

resource "aws_lb_target_group_attachment" "additional_target_group_attachments" {
for_each = { for k, v in var.additional_target_group_attachments : k => v if local.create }

target_group_arn = aws_lb_target_group.this[each.value.target_group].arn
target_id = each.value.target_id
port = try(each.value.target_type, null) == "lambda" ? null : try(each.value.port, var.default_port)
availability_zone = try(each.value.availability_zone, null)

depends_on = [aws_lambda_permission.this]
}

################################################################################
# Lambda Permission
################################################################################
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ variable "target_groups" {
default = {}
}

variable "additional_target_group_attachments" {
description = "Map of additional target group attchments to create"
type = any
default = {}
}

################################################################################
# Security Group
################################################################################
Expand Down
1 change: 1 addition & 0 deletions wrappers/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module "wrapper" {
for_each = var.items

access_logs = try(each.value.access_logs, var.defaults.access_logs, {})
additional_target_group_attachments = try(each.value.additional_target_group_attachments, var.defaults.additional_target_group_attachments, {})
associate_web_acl = try(each.value.associate_web_acl, var.defaults.associate_web_acl, false)
connection_logs = try(each.value.connection_logs, var.defaults.connection_logs, {})
create = try(each.value.create, var.defaults.create, true)
Expand Down

0 comments on commit 893a811

Please sign in to comment.