diff --git a/README.md b/README.md index 176477a..b614c5f 100644 --- a/README.md +++ b/README.md @@ -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 | @@ -384,6 +385,7 @@ No modules. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | [access\_logs](#input\_access\_logs) | Map containing access logging configuration for load balancer | `map(string)` | `{}` | no | +| [additional\_target\_group\_attachments](#input\_additional\_target\_group\_attachments) | Map of additional target group attchments to create | `any` | `{}` | no | | [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 | | [connection\_logs](#input\_connection\_logs) | Map containing access logging configuration for load balancer | `map(string)` | `{}` | no | | [create](#input\_create) | Controls if resources should be created (affects nearly all resources) | `bool` | `true` | no | diff --git a/examples/complete-alb/README.md b/examples/complete-alb/README.md index 8845abe..48b80e3 100644 --- a/examples/complete-alb/README.md +++ b/examples/complete-alb/README.md @@ -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 | diff --git a/examples/complete-alb/main.tf b/examples/complete-alb/main.tf index 27e47cf..8360f96 100644 --- a/examples/complete-alb/main.tf +++ b/examples/complete-alb/main.tf @@ -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 = { @@ -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 ################################################################## diff --git a/main.tf b/main.tf index 144437e..717464f 100644 --- a/main.tf +++ b/main.tf @@ -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 ################################################################################ diff --git a/variables.tf b/variables.tf index 9cf497d..124e80c 100644 --- a/variables.tf +++ b/variables.tf @@ -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 ################################################################################ diff --git a/wrappers/main.tf b/wrappers/main.tf index 3434221..f277c22 100644 --- a/wrappers/main.tf +++ b/wrappers/main.tf @@ -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)