Skip to content

Commit b5b90cf

Browse files
committed
feat: allow configuring of additional security group rules
1 parent 2a72ece commit b5b90cf

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ Use [the awesome `gossm` project](https://github.com/gjbae1212/gossm).
115115
| [aws_iam_role_policy_attachment.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
116116
| [aws_launch_template.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template) | resource |
117117
| [aws_security_group.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) | resource |
118+
| [aws_security_group_rule.additional](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
118119
| [aws_security_group_rule.allow_all_egress](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
119120
| [aws_ssm_document.session_logging](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssm_document) | resource |
120121
| [null_resource.validate_instance_type](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
@@ -130,6 +131,7 @@ Use [the awesome `gossm` project](https://github.com/gjbae1212/gossm).
130131
| Name | Description | Type | Default | Required |
131132
|------|-------------|------|---------|:--------:|
132133
| <a name="input_additional_security_group_ids"></a> [additional\_security\_group\_ids](#input\_additional\_security\_group\_ids) | Security groups that will be attached to the app instances | `list(string)` | `[]` | no |
134+
| <a name="input_additional_security_group_rules"></a> [additional\_security\_group\_rules](#input\_additional\_security\_group\_rules) | Additional security group rules that will be attached to the primary security group | `map(string)` | `{}` | no |
133135
| <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 |
134136
| <a name="input_ami"></a> [ami](#input\_ami) | The AMI to use for the SSM Agent EC2 Instance. If not provided, the latest Amazon Linux 2023 AMI will be used. Note: This will update periodically as AWS releases updates to their AL2023 AMI. Pin to a specific AMI if you would like to avoid these updates. | `string` | `""` | no |
135137
| <a name="input_architecture"></a> [architecture](#input\_architecture) | The architecture of the AMI (e.g., x86\_64, arm64) | `string` | `"arm64"` | no |

main.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,23 @@ resource "aws_security_group_rule" "allow_all_egress" {
159159
security_group_id = aws_security_group.default.id
160160
}
161161

162+
resource "aws_security_group_rule" "additional" {
163+
for_each = var.additional_security_group_rules
164+
165+
type = lookup(each.value, "type")
166+
from_port = lookup(each.value, "from_port")
167+
to_port = lookup(each.value, "to_port")
168+
protocol = lookup(each.value, "protocol")
169+
170+
description = lookup(each.value, "description", null)
171+
cidr_blocks = lookup(each.value, "cidr_blocks", null)
172+
ipv6_cidr_blocks = lookup(each.value, "ipv6_cidr_blocks", null)
173+
prefix_list_ids = lookup(each.value, "prefix_list_ids", null)
174+
self = lookup(each.value, "self", null)
175+
176+
security_group_id = aws_security_group.default.id
177+
}
178+
162179
#######################
163180
## SECURITY LOGGING ##
164181
#####################

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ variable "additional_security_group_ids" {
6262
default = []
6363
}
6464

65+
variable "additional_security_group_rules" {
66+
description = "Additional security group rules that will be attached to the primary security group"
67+
type = map(string)
68+
default = {}
69+
}
70+
6571
variable "monitoring_enabled" {
6672
description = "Enable detailed monitoring of instance"
6773
type = bool

0 commit comments

Comments
 (0)