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

Add examples for nlb #23

Merged
merged 1 commit into from
Feb 17, 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
5 changes: 3 additions & 2 deletions examples/gwlb-with-instance-target-group/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ data "aws_subnet" "default" {

module "gwlb" {
source = "tedilabs/load-balancer/aws//modules/gwlb"
version = "~> 0.1.0"
version = "~> 0.2.0"

name = "tedilabs-gwlb-instance"
network_mapping = {
Expand All @@ -31,6 +31,7 @@ module "gwlb" {
}
}

## Attributes
cross_zone_load_balancing_enabled = true
deletion_protection_enabled = false

Expand All @@ -51,7 +52,7 @@ module "gwlb" {

module "target_group" {
source = "tedilabs/load-balancer/aws//modules/gwlb-instance-target-group"
version = "~> 0.1.0"
version = "~> 0.2.0"

name = "tedilabs-gwlb-instance-tg"

Expand Down
7 changes: 4 additions & 3 deletions examples/gwlb-with-ip-target-group/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ data "aws_subnet" "default" {

module "gwlb" {
source = "tedilabs/load-balancer/aws//modules/gwlb"
version = "~> 0.1.0"
version = "~> 0.2.0"

name = "tedilabs-gwlb-ip"
network_mapping = {
Expand All @@ -31,6 +31,7 @@ module "gwlb" {
}
}

## Attributes
cross_zone_load_balancing_enabled = true
deletion_protection_enabled = false

Expand All @@ -46,12 +47,12 @@ module "gwlb" {


###################################################
# Instance Target Group for Gateway Load Balancer
# IP Target Group for Gateway Load Balancer
###################################################

module "target_group" {
source = "tedilabs/load-balancer/aws//modules/gwlb-ip-target-group"
version = "~> 0.1.0"
version = "~> 0.2.0"

name = "tedilabs-gwlb-ip-tg"

Expand Down
93 changes: 93 additions & 0 deletions examples/nlb-with-instance-target-group/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
provider "aws" {
region = "us-east-1"
}


data "aws_vpc" "default" {
default = true
}

data "aws_subnet" "default" {
for_each = toset(["use1-az1", "use1-az2"])

availability_zone_id = each.key
default_for_az = true
}


###################################################
# Network Load Balancer
###################################################

module "nlb" {
source = "tedilabs/load-balancer/aws//modules/nlb"
version = "~> 0.2.0"

name = "tedilabs-nlb-instance"

is_public = false
ip_address_type = "IPV4"
network_mapping = {
for az, subnet in data.aws_subnet.default :
az => {
subnet_id = subnet.id
}
}

## Attributes
cross_zone_load_balancing_enabled = true
deletion_protection_enabled = false

listeners = [{
port = 80
protocol = "TCP"
target_group = module.target_group.arn
}]

access_log_enabled = false
access_log_s3_bucket = "my-bucket"
access_log_s3_key_prefix = "/tedilabs-nlb-instance/"

tags = {
"project" = "terraform-aws-load-balancer-examples"
}
}


###################################################
# Instance Target Group for Network Load Balancer
###################################################

module "target_group" {
source = "tedilabs/load-balancer/aws//modules/nlb-instance-target-group"
version = "~> 0.2.0"

name = "tedilabs-nlb-instance-tg"

vpc_id = data.aws_vpc.default.id

port = 80
protocol = "TCP"

## Attributes
terminate_connection_on_deregistration = false
deregistration_delay = 300
preserve_client_ip = true
proxy_protocol_v2 = false

targets = [
# {
# instance = "i-xxxx"
# },
]

health_check = {
port = 80
protocol = "HTTP"
interval = 10
timeout = 5
healthy_threshold = 3
unhealthy_threshold = 3
path = "/health"
}
}
7 changes: 7 additions & 0 deletions examples/nlb-with-instance-target-group/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "nlb" {
value = module.nlb
}

output "target_group" {
value = module.target_group
}
10 changes: 10 additions & 0 deletions examples/nlb-with-instance-target-group/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = "~> 1.1"

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
}
97 changes: 97 additions & 0 deletions examples/nlb-with-ip-target-group/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
provider "aws" {
region = "us-east-1"
}


data "aws_vpc" "default" {
default = true
}

data "aws_subnet" "default" {
for_each = toset(["use1-az1", "use1-az2"])

availability_zone_id = each.key
default_for_az = true
}


###################################################
# Network Load Balancer
###################################################

module "nlb" {
source = "tedilabs/load-balancer/aws//modules/nlb"
version = "~> 0.2.0"

name = "tedilabs-nlb-ip"

is_public = false
ip_address_type = "IPV4"
network_mapping = {
for az, subnet in data.aws_subnet.default :
az => {
subnet_id = subnet.id
}
}

## Attributes
cross_zone_load_balancing_enabled = true
deletion_protection_enabled = false

listeners = [{
port = 80
protocol = "TCP"
target_group = module.target_group.arn
}]

access_log_enabled = false
access_log_s3_bucket = "my-bucket"
access_log_s3_key_prefix = "/tedilabs-nlb-ip/"

tags = {
"project" = "terraform-aws-load-balancer-examples"
}
}


###################################################
# IP Target Group for Network Load Balancer
###################################################

module "target_group" {
source = "tedilabs/load-balancer/aws//modules/nlb-ip-target-group"
version = "~> 0.2.0"

name = "tedilabs-nlb-ip-tg"

vpc_id = data.aws_vpc.default.id

port = 80
protocol = "TCP"

## Attributes
terminate_connection_on_deregistration = false
deregistration_delay = 300
preserve_client_ip = true
proxy_protocol_v2 = false

targets = [
{
ip_address = "10.123.123.234"
},
{
ip_address = "10.0.103.34"
port = 999
},
]

health_check = {
port = 80
protocol = "HTTP"
interval = 10
timeout = 5
healthy_threshold = 3
unhealthy_threshold = 3
path = "/health"
}
}
7 changes: 7 additions & 0 deletions examples/nlb-with-ip-target-group/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "nlb" {
value = module.nlb
}

output "target_group" {
value = module.target_group
}
10 changes: 10 additions & 0 deletions examples/nlb-with-ip-target-group/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = "~> 1.1"

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
}
5 changes: 5 additions & 0 deletions modules/alb-lambda-target-group/variables.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
variable "name" {
description = "(Required) Name of the target group."
type = string

validation {
condition = length(var.name) <= 32
error_message = "The name can have a maximum of 32 characters, must contain only alphanumeric characters or hyphens, and must not begin or end with a hyphen."
}
}

variable "target_lambda" {
Expand Down
2 changes: 1 addition & 1 deletion modules/gwlb-instance-target-group/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ No modules.
| <a name="input_name"></a> [name](#input\_name) | (Required) Name of the target group. A maximum of 32 alphanumeric characters including hyphens are allowed, but the name must not begin or end with a hyphen. | `string` | n/a | yes |
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | (Required) The ID of the VPC which the target group belongs to. | `string` | n/a | yes |
| <a name="input_deregistration_delay"></a> [deregistration\_delay](#input\_deregistration\_delay) | (Optional) The time to wait for in-flight requests to complete while deregistering a target. During this time, the state of the target is draining. | `number` | `300` | no |
| <a name="input_health_check"></a> [health\_check](#input\_health\_check) | (Optional) Health Check configuration block. The associated load balancer periodically sends requests to the registered targets to test their status. `health_check` block as defined below.<br> (Optional) `port` - The port the load balancer uses when performing health checks on targets. The default is the port on which each target receives traffic from the load balancer. Valid values are either ports 1-65535.<br> (Optional) `protocol` - Protocol to use to connect with the target. The possible values are `TCP`, `HTTP` and `HTTPS`. Defaults to `TCP`.<br> (Optional) `healthy_threshold` - The number of consecutive health checks successes required before considering an unhealthy target healthy. Valid value range is 2 - 10. Defaults to `3`.<br> (Optional) `unhealthy_threshold` - The number of consecutive health check failures required before considering a target unhealthy. Valid value range is 2 - 10. Defaults to `3`.<br> (Optional) `interval` - Approximate amount of time, in seconds, between health checks of an individual target. Valid value range is 5 - 300. Defaults to `10`.<br> (Optional) `timeout` - The amount of time, in seconds, during which no response means a failed health check. Valid value range is 2 - 120. Defaults to `5`. | `any` | `{}` | no |
| <a name="input_health_check"></a> [health\_check](#input\_health\_check) | (Optional) Health Check configuration block. The associated load balancer periodically sends requests to the registered targets to test their status. `health_check` block as defined below.<br> (Optional) `port` - The port the load balancer uses when performing health checks on targets. The default is the port on which each target receives traffic from the load balancer. Valid values are either ports 1-65535.<br> (Optional) `protocol` - Protocol to use to connect with the target. The possible values are `TCP`, `HTTP` and `HTTPS`. Defaults to `TCP`.<br> (Optional) `healthy_threshold` - The number of consecutive health checks successes required before considering an unhealthy target healthy. Valid value range is 2 - 10. Defaults to `3`.<br> (Optional) `unhealthy_threshold` - The number of consecutive health check failures required before considering a target unhealthy. Valid value range is 2 - 10. Defaults to `3`.<br> (Optional) `interval` - Approximate amount of time, in seconds, between health checks of an individual target. Valid value range is 5 - 300. Defaults to `10`.<br> (Optional) `timeout` - The amount of time, in seconds, during which no response means a failed health check. Valid value range is 2 - 120. Defaults to `5`.<br> (Optional) `path` - Use the default path of `/` to ping the root, or specify a custom path if preferred. Only valid if the `protocol` is `HTTP` or `HTTPS`. | `any` | `{}` | no |
| <a name="input_module_tags_enabled"></a> [module\_tags\_enabled](#input\_module\_tags\_enabled) | (Optional) Whether to create AWS Resource Tags for the module informations. | `bool` | `true` | no |
| <a name="input_resource_group_description"></a> [resource\_group\_description](#input\_resource\_group\_description) | (Optional) The description of Resource Group. | `string` | `"Managed by Terraform."` | no |
| <a name="input_resource_group_enabled"></a> [resource\_group\_enabled](#input\_resource\_group\_enabled) | (Optional) Whether to create Resource Group to find and group AWS resources which are created by this module. | `bool` | `true` | no |
Expand Down
1 change: 1 addition & 0 deletions modules/gwlb-instance-target-group/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ variable "health_check" {
(Optional) `unhealthy_threshold` - The number of consecutive health check failures required before considering a target unhealthy. Valid value range is 2 - 10. Defaults to `3`.
(Optional) `interval` - Approximate amount of time, in seconds, between health checks of an individual target. Valid value range is 5 - 300. Defaults to `10`.
(Optional) `timeout` - The amount of time, in seconds, during which no response means a failed health check. Valid value range is 2 - 120. Defaults to `5`.
(Optional) `path` - Use the default path of `/` to ping the root, or specify a custom path if preferred. Only valid if the `protocol` is `HTTP` or `HTTPS`.
EOF
type = any
default = {}
Expand Down
2 changes: 1 addition & 1 deletion modules/gwlb-ip-target-group/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ No modules.
| <a name="input_name"></a> [name](#input\_name) | (Required) Name of the target group. A maximum of 32 alphanumeric characters including hyphens are allowed, but the name must not begin or end with a hyphen. | `string` | n/a | yes |
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | (Required) The ID of the VPC which the target group belongs to. | `string` | n/a | yes |
| <a name="input_deregistration_delay"></a> [deregistration\_delay](#input\_deregistration\_delay) | (Optional) The time to wait for in-flight requests to complete while deregistering a target. During this time, the state of the target is draining. | `number` | `300` | no |
| <a name="input_health_check"></a> [health\_check](#input\_health\_check) | (Optional) Health Check configuration block. The associated load balancer periodically sends requests to the registered targets to test their status. `health_check` block as defined below.<br> (Optional) `port` - The port the load balancer uses when performing health checks on targets. The default is the port on which each target receives traffic from the load balancer. Valid values are either ports 1-65535.<br> (Optional) `protocol` - Protocol to use to connect with the target. The possible values are `TCP`, `HTTP` and `HTTPS`. Defaults to `TCP`.<br> (Optional) `healthy_threshold` - The number of consecutive health checks successes required before considering an unhealthy target healthy. Valid value range is 2 - 10. Defaults to `3`.<br> (Optional) `unhealthy_threshold` - The number of consecutive health check failures required before considering a target unhealthy. Valid value range is 2 - 10. Defaults to `3`.<br> (Optional) `interval` - Approximate amount of time, in seconds, between health checks of an individual target. Valid value range is 5 - 300. Defaults to `10`.<br> (Optional) `timeout` - The amount of time, in seconds, during which no response means a failed health check. Valid value range is 2 - 120. Defaults to `5`. | `any` | `{}` | no |
| <a name="input_health_check"></a> [health\_check](#input\_health\_check) | (Optional) Health Check configuration block. The associated load balancer periodically sends requests to the registered targets to test their status. `health_check` block as defined below.<br> (Optional) `port` - The port the load balancer uses when performing health checks on targets. The default is the port on which each target receives traffic from the load balancer. Valid values are either ports 1-65535.<br> (Optional) `protocol` - Protocol to use to connect with the target. The possible values are `TCP`, `HTTP` and `HTTPS`. Defaults to `TCP`.<br> (Optional) `healthy_threshold` - The number of consecutive health checks successes required before considering an unhealthy target healthy. Valid value range is 2 - 10. Defaults to `3`.<br> (Optional) `unhealthy_threshold` - The number of consecutive health check failures required before considering a target unhealthy. Valid value range is 2 - 10. Defaults to `3`.<br> (Optional) `interval` - Approximate amount of time, in seconds, between health checks of an individual target. Valid value range is 5 - 300. Defaults to `10`.<br> (Optional) `timeout` - The amount of time, in seconds, during which no response means a failed health check. Valid value range is 2 - 120. Defaults to `5`.<br> (Optional) `path` - Use the default path of `/` to ping the root, or specify a custom path if preferred. Only valid if the `protocol` is `HTTP` or `HTTPS`. | `any` | `{}` | no |
| <a name="input_module_tags_enabled"></a> [module\_tags\_enabled](#input\_module\_tags\_enabled) | (Optional) Whether to create AWS Resource Tags for the module informations. | `bool` | `true` | no |
| <a name="input_resource_group_description"></a> [resource\_group\_description](#input\_resource\_group\_description) | (Optional) The description of Resource Group. | `string` | `"Managed by Terraform."` | no |
| <a name="input_resource_group_enabled"></a> [resource\_group\_enabled](#input\_resource\_group\_enabled) | (Optional) Whether to create Resource Group to find and group AWS resources which are created by this module. | `bool` | `true` | no |
Expand Down
1 change: 1 addition & 0 deletions modules/gwlb-ip-target-group/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ variable "health_check" {
(Optional) `unhealthy_threshold` - The number of consecutive health check failures required before considering a target unhealthy. Valid value range is 2 - 10. Defaults to `3`.
(Optional) `interval` - Approximate amount of time, in seconds, between health checks of an individual target. Valid value range is 5 - 300. Defaults to `10`.
(Optional) `timeout` - The amount of time, in seconds, during which no response means a failed health check. Valid value range is 2 - 120. Defaults to `5`.
(Optional) `path` - Use the default path of `/` to ping the root, or specify a custom path if preferred. Only valid if the `protocol` is `HTTP` or `HTTPS`.
EOF
type = any
default = {}
Expand Down