Skip to content

Commit

Permalink
add prefix list to web
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Oct 2, 2025
1 parent 7b65d71 commit 092eb99
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,6 @@

* 2.7.0 -- 2025-08-26
- custom: add prefix list capability

* 2.8.0 -- 2025-10-02
- web: add prefix list capability
2 changes: 1 addition & 1 deletion common/version.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
locals {
_module_version = "2.7.0"
_module_version = "2.8.0"
}
17 changes: 14 additions & 3 deletions web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,30 @@ module "web" {
# name = "m-web"
# ingress_networks = [ "1.2.3.0/24" ]
# egress_networks = [ "1.2.3.0/24" ]
# ingress_prefix_list_names = [ "onprem-networks.core" ]
# egress_prefix_list_names = [ ]
## tags for Name, CostAllocation, and Environment are pre-set, but they can be overriden
# tags = { }
}
```
## ingress\_prefix\_list\_names
In order to use a managed prefix list, you may pass a list of names in this field. The prefix lists
will be looked up and the resultant IDs used in the security group for inbound port access to port
443 (https). This will fail if the prefix list does not exist.

## Requirements

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

## Providers

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

## Modules

Expand All @@ -48,6 +55,8 @@ No modules.
| Name | Type |
|------|------|
| [aws_security_group.this_security_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) | resource |
| [aws_ec2_managed_prefix_list.egress](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ec2_managed_prefix_list) | data source |
| [aws_ec2_managed_prefix_list.ingress](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ec2_managed_prefix_list) | data source |
| [aws_security_group.egress_security_groups](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/security_group) | data source |
| [aws_security_group.ingress_security_groups](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/security_group) | data source |
| [aws_vpc.this_vpc](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc) | data source |
Expand All @@ -58,13 +67,15 @@ No modules.
|------|-------------|------|---------|:--------:|
| <a name="input_description"></a> [description](#input\_description) | Security Group Description | `string` | `"Web Security Group"` | no |
| <a name="input_egress_networks"></a> [egress\_networks](#input\_egress\_networks) | List of egress networks (with all pre-defined egress ports) | `list(string)` | `[]` | no |
| <a name="input_egress_prefix_list_names"></a> [egress\_prefix\_list\_names](#input\_egress\_prefix\_list\_names) | List of prefix list names for eggress access | `list(string)` | `[]` | no |
| <a name="input_egress_security_groups"></a> [egress\_security\_groups](#input\_egress\_security\_groups) | List of egress security groups (all ports) | `list(string)` | `[]` | no |
| <a name="input_enable_self"></a> [enable\_self](#input\_enable\_self) | Enable\|Disable self full access | `bool` | `false` | no |
| <a name="input_ingress_networks"></a> [ingress\_networks](#input\_ingress\_networks) | List of ingress networks for access (with all pre-defined ingress ports) | `list(string)` | `[]` | no |
| <a name="input_ingress_prefix_list_names"></a> [ingress\_prefix\_list\_names](#input\_ingress\_prefix\_list\_names) | List of prefix list names for ingress access | `list(string)` | `[]` | no |
| <a name="input_ingress_security_groups"></a> [ingress\_security\_groups](#input\_ingress\_security\_groups) | List of ingress security groups for all ports | `list(string)` | `[]` | no |
| <a name="input_name"></a> [name](#input\_name) | Security Group Name | `string` | `"m-web"` | no |
| <a name="input_short_description"></a> [short\_description](#input\_short\_description) | Security Group Short Description | `string` | `"Web"` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | Extra security group tags | `map` | <pre>{<br> "CostAllocation": "csvd:infrastructure",<br> "Environment": "csvd-infrastructure"<br>}</pre> | no |
| <a name="input_tags"></a> [tags](#input\_tags) | Extra security group tags | `map(any)` | <pre>{<br/> "CostAllocation": "csvd:infrastructure",<br/> "Environment": "csvd-infrastructure"<br/>}</pre> | no |
| <a name="input_use_vpc_cidr"></a> [use\_vpc\_cidr](#input\_use\_vpc\_cidr) | Enable\|Disable use of VPC CIDR block in the ingress\_networks | `bool` | `false` | no |
| <a name="input_vpc_full_name"></a> [vpc\_full\_name](#input\_vpc\_full\_name) | VPC Name | `string` | `""` | no |
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | VPC ID Number | `string` | n/a | yes |
Expand Down
1 change: 1 addition & 0 deletions web/data.prefix_lists.tf
33 changes: 33 additions & 0 deletions web/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@
* # name = "m-web"
* # ingress_networks = [ "1.2.3.0/24" ]
* # egress_networks = [ "1.2.3.0/24" ]
* # ingress_prefix_list_names = [ "onprem-networks.core" ]
* # egress_prefix_list_names = [ ]
*
* ## tags for Name, CostAllocation, and Environment are pre-set, but they can be overriden
* # tags = { }
* }
* ```
* ## ingress_prefix_list_names
* In order to use a managed prefix list, you may pass a list of names in this field. The prefix lists
* will be looked up and the resultant IDs used in the security group for inbound port access to port
* 443 (https). This will fail if the prefix list does not exist.
*/

data "aws_vpc" "this_vpc" {
Expand Down Expand Up @@ -97,6 +103,20 @@ resource "aws_security_group" "this_security_group" {
}
}

# ingress with prefix lists
dynamic "ingress" {
for_each = length(var.ingress_prefix_list_names) > 0 ? local.port_map["external"] : toset([])
iterator = p
content {
description = "${local.short_description}: ${p.value["description"]}"
from_port = p.value["from"]
to_port = p.value["to"]
protocol = p.value["proto"]
prefix_list_ids = [for pl in data.aws_ec2_managed_prefix_list.ingress : pl.id]
}
}


# egress all
egress {
description = "${local.short_description}: All"
Expand All @@ -119,6 +139,19 @@ resource "aws_security_group" "this_security_group" {
}
}

# egress with prefix lists
dynamic "egress" {
for_each = length(var.egress_prefix_list_names) > 0 ? { 1 = 1 } : {}
iterator = p
content {
description = local.short_description
from_port = 0
to_port = 0
protocol = -1
prefix_list_ids = [for pl in data.aws_ec2_managed_prefix_list.egress : pl.id]
}
}

tags = merge(
var.tags,
{
Expand Down
1 change: 1 addition & 0 deletions web/variables.prefix_lists.tf
2 changes: 1 addition & 1 deletion web/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ variable "egress_security_groups" {

variable "tags" {
description = "Extra security group tags"
type = map
type = map(any)
default = {
"CostAllocation" = "csvd:infrastructure"
"Environment" = "csvd-infrastructure"
Expand Down

0 comments on commit 092eb99

Please sign in to comment.