Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v1.0.0] initial module implementation #1

Merged
merged 1 commit into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ override.tf.json

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

.DS_Store

.terraform.lock.hcl
58 changes: 56 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,56 @@
# terraform-aws-alb-target-group
Terraform AWS Load balancer Target group
# Terraform AWS Load Balancer Target group module

## Basic Usage Example
```
module "target_group" {
source = "github.com/bryan-rhm/terraform-aws-alb-target-group?ref=v1.0.0"
name = "my-target"
vpc_id = var.vpc_id
target_type = "ip"
stickiness = {
type = "lb_cookie"
}
}
```
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.4 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.43.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | 3.71.0 |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [aws_lb_target_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb_target_group) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_health_check"></a> [health\_check](#input\_health\_check) | Health Check configuration block. | <pre>object({<br> path = string<br> timeout = number<br> matcher = optional(string)<br> interval = number<br> protocol = optional(string)<br> healthy_threshold = optional(number)<br> unhealthy_threshold = optional(number)<br> })</pre> | `null` | no |
| <a name="input_name"></a> [name](#input\_name) | (Optional, Forces new resource) Name of the target group. If omitted, Terraform will assign a random, unique name. | `string` | `null` | no |
| <a name="input_name_prefix"></a> [name\_prefix](#input\_name\_prefix) | (Optional, Forces new resource) Creates a unique name beginning with the specified prefix. Conflicts with name. Cannot be longer than 6 characters. | `string` | `null` | no |
| <a name="input_port"></a> [port](#input\_port) | Port on which targets receive traffic, unless overridden when registering a specific target. | `number` | `80` | no |
| <a name="input_protocol"></a> [protocol](#input\_protocol) | Should be one of GENEVE, HTTP, HTTPS, TCP, TCP\_UDP, TLS, or UDP | `string` | `"HTTP"` | no |
| <a name="input_stickiness"></a> [stickiness](#input\_stickiness) | Stickiness configuration block. | <pre>object({<br> type = string # The only current possible values are lb_cookie, app_cookie for ALBs, and source_ip for NLBs.<br> cookie_name = optional(string) # Only needed when type is app_cookie.<br> cookie_duration = optional(number) # Only used when the type is lb_cookie. Default value 86400<br> })</pre> | `null` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to assign to the target group. If configured with a provider default\_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level. | `map(any)` | `null` | no |
| <a name="input_target_type"></a> [target\_type](#input\_target\_type) | Type of target that you must specify when registering targets with this target group. Valid values: ip\|instance\|lambda | `string` | `"instance"` | no |
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | Identifier of the VPC in which to create the target group. Required when target\_type is instance or ip | `string` | `null` | no |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_output"></a> [output](#output\_output) | Target group attributes |
32 changes: 32 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
resource "aws_lb_target_group" "this" {
name = var.name
name_prefix = substr(var.name_prefix,0,6)
port = var.port
protocol = var.protocol
vpc_id = var.vpc_id
target_type = var.target_type

dynamic "health_check" {
for_each = var.health_check != null ? [1] : []
content {
path = try(var.health_check.path, null)
timeout = var.health_check.timeout
matcher = try(var.health_check.matcher, null)
interval = var.health_check.interval
protocol = try(var.health_check.protocol, null)
healthy_threshold = try(var.health_check.healthy_threshold, null)
unhealthy_threshold = try(var.health_check.unhealthy_threshold, null)
}
}

dynamic "stickiness" {
for_each = var.stickiness != null ? [1] : []
content {
type = var.stickiness.type
cookie_name = try(var.stickiness.cookie_name, null)
cookie_duration = try(var.stickiness.cookie_duration, null)
}
}

tags = var.tags
}
4 changes: 4 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "output" {
description = "Target group attributes"
value = aws_lb_target_group.this
}
73 changes: 73 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
variable "name" {
description = "(Optional, Forces new resource) Name of the target group. If omitted, Terraform will assign a random, unique name."
default = null
type = string
}

variable "name_prefix" {
description = "(Optional, Forces new resource) Creates a unique name beginning with the specified prefix. Conflicts with name. Cannot be longer than 6 characters."
default = null
type = string
}

variable "port" {
description = "Port on which targets receive traffic, unless overridden when registering a specific target."
default = 80
type = number
}

variable "protocol" {
description = "Should be one of GENEVE, HTTP, HTTPS, TCP, TCP_UDP, TLS, or UDP"
default = "HTTP"
type = string
}

variable "vpc_id" {
description = "Identifier of the VPC in which to create the target group. Required when target_type is instance or ip"
default = null
type = string
}

variable "target_type" {
description = "Type of target that you must specify when registering targets with this target group. Valid values: ip|instance|lambda"
default = "instance"
type = string
}

variable "health_check" {
description = "Health Check configuration block."
default = null
type = object({
path = string
timeout = number
matcher = optional(string)
interval = number
protocol = optional(string)
healthy_threshold = optional(number)
unhealthy_threshold = optional(number)
})
# Example:
# path = "/"
# timeout = 10
# matcher = "200-399"
# interval = 15
# protocol = "HTTP"
# healthy_threshold = 2
# unhealthy_threshold = 2
}

variable "stickiness" {
description = "Stickiness configuration block."
default = null
type = object({
type = string # The only current possible values are lb_cookie, app_cookie for ALBs, and source_ip for NLBs.
cookie_name = optional(string) # Only needed when type is app_cookie.
cookie_duration = optional(number) # Only used when the type is lb_cookie. Default value 86400
})
}

variable "tags" {
type = map(any)
default = null
description = "A map of tags to assign to the target group. If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level."
}
10 changes: 10 additions & 0 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 1.0.4"
experiments = [module_variable_optional_attrs]
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.43.0"
}
}
}