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 additional waf features #791

Merged
merged 4 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 modules/waf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,17 @@ components:
| Name | Type |
|------|------|
| [aws_ssm_parameter.acl_arn](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssm_parameter) | resource |
| [aws_alb.alb](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/alb) | data source |
| [aws_lbs.alb_by_tags](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/lbs) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_acl_name"></a> [acl\_name](#input\_acl\_name) | Friendly name of the ACL. The ACL ARN will be stored in SSM under {ssm\_path\_prefix}/{acl\_name}/arn | `string` | n/a | yes |
| <a name="input_additional_tag_map"></a> [additional\_tag\_map](#input\_additional\_tag\_map) | Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.<br>This is for some rare cases where resources want additional configuration of tags<br>and therefore take a list of maps with tag key, value, and additional configuration. | `map(string)` | `{}` | no |
| <a name="input_alb_names"></a> [alb\_names](#input\_alb\_names) | list of ALB names to associate with the web ACL. | `list(string)` | `[]` | no |
| <a name="input_alb_tags"></a> [alb\_tags](#input\_alb\_tags) | list of tags to match one or more ALBs to associate with the web ACL. | `list(map(string))` | `[]` | no |
| <a name="input_association_resource_arns"></a> [association\_resource\_arns](#input\_association\_resource\_arns) | A list of ARNs of the resources to associate with the web ACL.<br>This must be an ARN of an Application Load Balancer, Amazon API Gateway stage, or AWS AppSync.<br><br>Do not use this variable to associate a Cloudfront Distribution.<br>Instead, you should use the `web_acl_id` property on the `cloudfront_distribution` resource.<br>For more details, refer to https://docs.aws.amazon.com/waf/latest/APIReference/API_AssociateWebACL.html | `list(string)` | `[]` | no |
| <a name="input_association_resource_component_selectors"></a> [association\_resource\_component\_selectors](#input\_association\_resource\_component\_selectors) | A list of Atmos component selectors to get from the remote state and associate their ARNs with the web ACL.<br>The components must be Application Load Balancers, Amazon API Gateway stages, or AWS AppSync.<br><br>component:<br> Atmos component name<br>component\_arn\_output:<br> The component output that defines the component ARN<br><br>Do not use this variable to select a Cloudfront Distribution component.<br>Instead, you should use the `web_acl_id` property on the `cloudfront_distribution` resource.<br>For more details, refer to https://docs.aws.amazon.com/waf/latest/APIReference/API_AssociateWebACL.html | <pre>list(object({<br> component = string<br> namespace = optional(string, null)<br> tenant = optional(string, null)<br> environment = optional(string, null)<br> stage = optional(string, null)<br> component_arn_output = string<br> }))</pre> | `[]` | no |
| <a name="input_attributes"></a> [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,<br>in the order they appear in the list. New attributes are appended to the<br>end of the list. The elements of the list are joined by the `delimiter`<br>and treated as a single ID element. | `list(string)` | `[]` | no |
Expand Down
15 changes: 15 additions & 0 deletions modules/waf/alb.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
locals {
alb_arns = concat(local.alb_name_arns, local.alb_tag_arns)
alb_name_arns = [for alb_instance in data.aws_alb.alb : alb_instance.arn]
alb_tag_arns = flatten([for alb_instance in data.aws_lbs.alb_by_tags : alb_instance.arns])
}

data "aws_alb" "alb" {
for_each = toset(var.alb_names)
name = each.key
}

data "aws_lbs" "alb_by_tags" {
for_each = { for i, v in var.alb_tags : i => v }
tags = each.value
}
2 changes: 1 addition & 1 deletion modules/waf/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ locals {
if local.enabled
]

association_resource_arns = concat(var.association_resource_arns, local.association_resource_component_selectors_arns)
association_resource_arns = toset(concat(var.association_resource_arns, local.association_resource_component_selectors_arns, local.alb_arns))
}

module "aws_waf" {
Expand Down
Empty file modified modules/waf/remote-state.tf
100644 → 100755
Empty file.
14 changes: 14 additions & 0 deletions modules/waf/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,20 @@ variable "association_resource_arns" {
nullable = false
}

variable "alb_names" {
description = "list of ALB names to associate with the web ACL."
type = list(string)
default = []
nullable = false
}

variable "alb_tags" {
description = "list of tags to match one or more ALBs to associate with the web ACL."
type = list(map(string))
default = []
nullable = false
}

variable "association_resource_component_selectors" {
type = list(object({
component = string
Expand Down