Skip to content

Commit b3b00f0

Browse files
feat: Add web acl association (#291)
Co-authored-by: Anton Babenko <[email protected]>
1 parent 286b327 commit b3b00f0

File tree

5 files changed

+16
-1
lines changed

5 files changed

+16
-1
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.80.0
3+
rev: v1.81.0
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_wrapper_module_for_each

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ No modules.
322322
| [aws_lb_target_group_attachment.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb_target_group_attachment) | resource |
323323
| [aws_security_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) | resource |
324324
| [aws_security_group_rule.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
325+
| [aws_wafv2_web_acl_association.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/wafv2_web_acl_association) | resource |
325326

326327
## Inputs
327328

@@ -372,6 +373,7 @@ No modules.
372373
| <a name="input_target_group_tags"></a> [target\_group\_tags](#input\_target\_group\_tags) | A map of tags to add to all target groups | `map(string)` | `{}` | no |
373374
| <a name="input_target_groups"></a> [target\_groups](#input\_target\_groups) | A list of maps containing key/value pairs that define the target groups to be created. Order of these maps is important and the index of these are to be referenced in listener definitions. Required key/values: name, backend\_protocol, backend\_port | `any` | `[]` | no |
374375
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | VPC id where the load balancer and other resources will be deployed. | `string` | `null` | no |
376+
| <a name="input_web_acl_arn"></a> [web\_acl\_arn](#input\_web\_acl\_arn) | WAF ARN to associate this LB with. | `string` | `null` | no |
375377
| <a name="input_xff_header_processing_mode"></a> [xff\_header\_processing\_mode](#input\_xff\_header\_processing\_mode) | Determines how the load balancer modifies the X-Forwarded-For header in the HTTP request before sending the request to the target. | `string` | `"append"` | no |
376378

377379
## Outputs

main.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,3 +841,9 @@ resource "aws_security_group_rule" "this" {
841841
self = lookup(each.value, "self", null)
842842
source_security_group_id = lookup(each.value, "source_security_group_id", null)
843843
}
844+
845+
resource "aws_wafv2_web_acl_association" "this" {
846+
count = var.web_acl_arn != null ? 1 : 0
847+
resource_arn = aws_lb.this[0].arn
848+
web_acl_arn = var.web_acl_arn
849+
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,9 @@ variable "security_group_tags" {
277277
type = map(string)
278278
default = {}
279279
}
280+
281+
variable "web_acl_arn" {
282+
description = "WAF ARN to associate this LB with."
283+
type = string
284+
default = null
285+
}

wrappers/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@ module "wrapper" {
4949
security_group_description = try(each.value.security_group_description, var.defaults.security_group_description, null)
5050
security_group_rules = try(each.value.security_group_rules, var.defaults.security_group_rules, {})
5151
security_group_tags = try(each.value.security_group_tags, var.defaults.security_group_tags, {})
52+
web_acl_arn = try(each.value.web_acl_arn, var.defaults.web_acl_arn, null)
5253
}

0 commit comments

Comments
 (0)