Skip to content

Commit 1e37439

Browse files
Nlb module (#376)
1 parent 2793698 commit 1e37439

File tree

5 files changed

+196
-0
lines changed

5 files changed

+196
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
## Requirements
2+
3+
No requirements.
4+
5+
## Providers
6+
7+
| Name | Version |
8+
|------|---------|
9+
| <a name="provider_aws"></a> [aws](#provider\_aws) | n/a |
10+
11+
## Modules
12+
13+
No modules.
14+
15+
## Resources
16+
17+
| Name | Type |
18+
|------|------|
19+
| [aws_lb.nlb](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb) | resource |
20+
21+
## Inputs
22+
23+
| Name | Description | Type | Default | Required |
24+
|------|-------------|------|---------|:--------:|
25+
| <a name="input_access_logs_s3_bucket_name"></a> [access\_logs\_s3\_bucket\_name](#input\_access\_logs\_s3\_bucket\_name) | The name to use for the S3 bucket where the NLB access logs will be stored. If you set this to null, a name will be generated automatically based on var.nlb\_name. | `string` | `null` | no |
26+
| <a name="input_custom_nlb_access_logs_s3_prefix"></a> [custom\_nlb\_access\_logs\_s3\_prefix](#input\_custom\_nlb\_access\_logs\_s3\_prefix) | Prefix to use for access logs to create a sub-folder in S3 Bucket name where NLB logs should be stored. Only used if var.enable\_custom\_nlb\_access\_logs\_s3\_prefix is true. | `string` | `null` | no |
27+
| <a name="input_enable_cross_zone_load_balancing"></a> [enable\_cross\_zone\_load\_balancing](#input\_enable\_cross\_zone\_load\_balancing) | Set enable\_cross\_zone\_load\_balancing | `bool` | `false` | no |
28+
| <a name="input_enable_custom_nlb_access_logs_s3_prefix"></a> [enable\_custom\_nlb\_access\_logs\_s3\_prefix](#input\_enable\_custom\_nlb\_access\_logs\_s3\_prefix) | Set to true to use the value of nlb\_access\_logs\_s3\_prefix for access logs prefix. If false, the nlb\_name will be used. This is useful if you wish to disable the S3 prefix. Only used if var.enable\_nlb\_access\_logs is true. | `bool` | `false` | no |
29+
| <a name="input_enable_deletion_protection"></a> [enable\_deletion\_protection](#input\_enable\_deletion\_protection) | Enable deletion protection | `bool` | `false` | no |
30+
| <a name="input_enable_http2"></a> [enable\_http2](#input\_enable\_http2) | enable\_http2 | `bool` | `false` | no |
31+
| <a name="input_enable_internal"></a> [enable\_internal](#input\_enable\_internal) | Enable internal load balancer | `bool` | `true` | no |
32+
| <a name="input_enable_nlb_access_logs"></a> [enable\_nlb\_access\_logs](#input\_enable\_nlb\_access\_logs) | This is Optional, Only used to output the NLB logs to S3. we need to input bucket\_name and bucket\_prefix to the list. if left empty it will not output the logs to S3 | `list(any)` | `[]` | no |
33+
| <a name="input_force_destroy"></a> [force\_destroy](#input\_force\_destroy) | A boolean that indicates whether the access logs bucket should be destroyed, even if there are files in it, when you run Terraform destroy. Unless you are using this bucket only for test purposes, you'll want to leave this variable set to false. | `bool` | `false` | no |
34+
| <a name="input_nlb_access_logs_s3_bucket_name"></a> [nlb\_access\_logs\_s3\_bucket\_name](#input\_nlb\_access\_logs\_s3\_bucket\_name) | The S3 Bucket name where NLB logs should be stored. If left empty, no NLB logs will be captured. Tip: It's easiest to create the S3 Bucket using the Gruntwork Module https://github.com/gruntwork-io/terraform-aws-monitoring/tree/master/modules/logs/load-balancer-access-logs. | `string` | `null` | no |
35+
| <a name="input_nlb_access_logs_s3_prefix"></a> [nlb\_access\_logs\_s3\_prefix](#input\_nlb\_access\_logs\_s3\_prefix) | nlb\_access\_logs\_s3\_prefix | `string` | `null` | no |
36+
| <a name="input_nlb_name"></a> [nlb\_name](#input\_nlb\_name) | The name of the NLB. Do not include the environment name since this module will automatically append it to the value of this variable. | `string` | n/a | yes |
37+
| <a name="input_nlb_s3_bucket_name"></a> [nlb\_s3\_bucket\_name](#input\_nlb\_s3\_bucket\_name) | nlb\_s3\_bucket\_name | `string` | `null` | no |
38+
| <a name="input_nlb_subnets"></a> [nlb\_subnets](#input\_nlb\_subnets) | NLB Subnets | `list(string)` | n/a | yes |
39+
| <a name="input_nlb_tags"></a> [nlb\_tags](#input\_nlb\_tags) | Tags | `map(any)` | <pre>{<br> "appname": "nlb"<br>}</pre> | no |
40+
| <a name="input_num_days_after_which_archive_log_data"></a> [num\_days\_after\_which\_archive\_log\_data](#input\_num\_days\_after\_which\_archive\_log\_data) | After this number of days, log files should be transitioned from S3 to Glacier. Enter 0 to never archive log data. | `number` | n/a | yes |
41+
| <a name="input_num_days_after_which_delete_log_data"></a> [num\_days\_after\_which\_delete\_log\_data](#input\_num\_days\_after\_which\_delete\_log\_data) | After this number of days, log files should be deleted from S3. Enter 0 to never delete log data. | `number` | n/a | yes |
42+
| <a name="input_should_create_access_logs_bucket"></a> [should\_create\_access\_logs\_bucket](#input\_should\_create\_access\_logs\_bucket) | If true, create a new S3 bucket for access logs with the name in var.access\_logs\_s3\_bucket\_name. If false, assume the S3 bucket for access logs with the name in var.access\_logs\_s3\_bucket\_name already exists, and don't create a new one. Note that if you set this to false, it's up to you to ensure that the S3 bucket has a bucket policy that grants Elastic Load Balancing permission to write the access logs to your bucket. | `bool` | `true` | no |
43+
44+
## Outputs
45+
46+
No outputs.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# ---------------------------------------------------------------------------------------------------------------------
2+
# LOCAL VALUES USED THROUGHOUT THE MODULE
3+
# ---------------------------------------------------------------------------------------------------------------------
4+
5+
locals {
6+
7+
nlb_access_logs_s3_prefix = (
8+
var.enable_custom_nlb_access_logs_s3_prefix
9+
? var.custom_nlb_access_logs_s3_prefix
10+
: var.nlb_name
11+
)
12+
13+
}

terraform-modules/aws/nlb/main.tf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
resource "aws_lb" "nlb" {
2+
name = var.nlb_name
3+
internal = var.enable_internal
4+
load_balancer_type = "network"
5+
subnets = var.nlb_subnets
6+
7+
enable_deletion_protection = var.enable_deletion_protection
8+
9+
dynamic "access_logs" {
10+
# The contents of the list is irrelevant. The only important thing is whether or not to create this block.
11+
for_each = var.enable_nlb_access_logs
12+
content {
13+
bucket = access_logs.value["bucket_name"]
14+
prefix = access_logs.value["bucket_prefix"]
15+
enabled = true
16+
}
17+
}
18+
19+
20+
enable_cross_zone_load_balancing = var.enable_cross_zone_load_balancing
21+
22+
enable_http2 = var.enable_http2
23+
24+
tags = var.nlb_tags
25+
}

terraform-modules/aws/nlb/output.tf

Whitespace-only changes.
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
variable "enable_deletion_protection" {
2+
type = bool
3+
description = "Enable deletion protection"
4+
default = false
5+
}
6+
7+
variable "enable_internal" {
8+
type = bool
9+
description = "Enable internal load balancer"
10+
default = true
11+
}
12+
13+
variable "nlb_name" {
14+
description = "The name of the NLB. Do not include the environment name since this module will automatically append it to the value of this variable."
15+
type = string
16+
# AWS imposes a 32 character limit on the names of NLBs, so here we catch any overages client-side
17+
validation {
18+
condition = length(var.nlb_name) <= 32
19+
error_message = "Your nlb_name must be 32 characters or less in length."
20+
}
21+
}
22+
23+
variable "enable_nlb_access_logs" {
24+
description = "This is Optional, Only used to output the NLB logs to S3. we need to input bucket_name and bucket_prefix to the list. if left empty it will not output the logs to S3"
25+
type = list(any)
26+
default = []
27+
}
28+
29+
variable "nlb_access_logs_s3_bucket_name" {
30+
description = "The S3 Bucket name where NLB logs should be stored. If left empty, no NLB logs will be captured. Tip: It's easiest to create the S3 Bucket using the Gruntwork Module https://github.com/gruntwork-io/terraform-aws-monitoring/tree/master/modules/logs/load-balancer-access-logs."
31+
type = string
32+
default = null
33+
}
34+
35+
variable "custom_nlb_access_logs_s3_prefix" {
36+
description = "Prefix to use for access logs to create a sub-folder in S3 Bucket name where NLB logs should be stored. Only used if var.enable_custom_nlb_access_logs_s3_prefix is true."
37+
type = string
38+
default = null
39+
}
40+
41+
variable "enable_custom_nlb_access_logs_s3_prefix" {
42+
description = "Set to true to use the value of nlb_access_logs_s3_prefix for access logs prefix. If false, the nlb_name will be used. This is useful if you wish to disable the S3 prefix. Only used if var.enable_nlb_access_logs is true."
43+
type = bool
44+
default = false
45+
}
46+
47+
variable "access_logs_s3_bucket_name" {
48+
description = "The name to use for the S3 bucket where the NLB access logs will be stored. If you set this to null, a name will be generated automatically based on var.nlb_name."
49+
type = string
50+
default = null
51+
}
52+
53+
variable "should_create_access_logs_bucket" {
54+
description = "If true, create a new S3 bucket for access logs with the name in var.access_logs_s3_bucket_name. If false, assume the S3 bucket for access logs with the name in var.access_logs_s3_bucket_name already exists, and don't create a new one. Note that if you set this to false, it's up to you to ensure that the S3 bucket has a bucket policy that grants Elastic Load Balancing permission to write the access logs to your bucket."
55+
type = bool
56+
default = true
57+
}
58+
59+
variable "num_days_after_which_archive_log_data" {
60+
description = "After this number of days, log files should be transitioned from S3 to Glacier. Enter 0 to never archive log data."
61+
type = number
62+
}
63+
64+
variable "num_days_after_which_delete_log_data" {
65+
description = "After this number of days, log files should be deleted from S3. Enter 0 to never delete log data."
66+
type = number
67+
}
68+
69+
variable "force_destroy" {
70+
description = "A boolean that indicates whether the access logs bucket should be destroyed, even if there are files in it, when you run Terraform destroy. Unless you are using this bucket only for test purposes, you'll want to leave this variable set to false."
71+
type = bool
72+
default = false
73+
}
74+
75+
variable "nlb_subnets" {
76+
type = list(string)
77+
description = "NLB Subnets"
78+
}
79+
80+
81+
variable "enable_cross_zone_load_balancing" {
82+
description = "Set enable_cross_zone_load_balancing"
83+
type = bool
84+
default = false
85+
}
86+
87+
variable "enable_http2" {
88+
description = "enable_http2"
89+
type = bool
90+
default = false
91+
}
92+
93+
94+
variable "nlb_access_logs_s3_prefix" {
95+
description = "nlb_access_logs_s3_prefix"
96+
type = string
97+
default = null
98+
}
99+
100+
variable "nlb_s3_bucket_name" {
101+
description = "nlb_s3_bucket_name"
102+
type = string
103+
default = null
104+
}
105+
106+
variable "nlb_tags" {
107+
description = "Tags"
108+
type = map(any)
109+
default = {
110+
appname = "nlb"
111+
}
112+
}

0 commit comments

Comments
 (0)