diff --git a/README.md b/README.md
index 20f1e93c..bd6a7ab4 100644
--- a/README.md
+++ b/README.md
@@ -362,7 +362,8 @@ Available targets:
| [aws_rds_cluster_instance.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster_instance) | resource |
| [aws_rds_cluster_parameter_group.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster_parameter_group) | resource |
| [aws_security_group.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) | resource |
-| [aws_security_group_rule.egress](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
+| [aws_security_group_rule.egress_cidr_blocks](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
+| [aws_security_group_rule.egress_security_groups](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
| [aws_security_group_rule.ingress_cidr_blocks](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
| [aws_security_group_rule.ingress_security_groups](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
| [aws_security_group_rule.traffic_inside_security_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
@@ -382,6 +383,8 @@ Available targets:
| [allocated\_storage](#input\_allocated\_storage) | The allocated storage in GBs | `number` | `null` | no |
| [allow\_major\_version\_upgrade](#input\_allow\_major\_version\_upgrade) | Enable to allow major engine version upgrades when changing engine versions. Defaults to false. | `bool` | `false` | no |
| [allowed\_cidr\_blocks](#input\_allowed\_cidr\_blocks) | List of CIDR blocks allowed to access the cluster | `list(string)` | `[]` | no |
+| [allowed\_egress\_cidr\_blocks](#input\_allowed\_egress\_cidr\_blocks) | List of allowed egress CIDR blocks | `list(string)` |
[
"0.0.0.0/0"
]
| no |
+| [allowed\_egress\_security\_groups](#input\_allowed\_egress\_security\_groups) | List of allowed egress Security Groups | `list(string)` | `[]` | no |
| [apply\_immediately](#input\_apply\_immediately) | Specifies whether any cluster modifications are applied immediately, or during the next maintenance window | `bool` | `true` | no |
| [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,
in the order they appear in the list. New attributes are appended to the
end of the list. The elements of the list are joined by the `delimiter`
and treated as a single ID element. | `list(string)` | `[]` | no |
| [auto\_minor\_version\_upgrade](#input\_auto\_minor\_version\_upgrade) | Indicates that minor engine upgrades will be applied automatically to the DB instance during the maintenance window | `bool` | `true` | no |
diff --git a/docs/terraform.md b/docs/terraform.md
index 7f771511..ea642f21 100644
--- a/docs/terraform.md
+++ b/docs/terraform.md
@@ -38,7 +38,8 @@
| [aws_rds_cluster_instance.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster_instance) | resource |
| [aws_rds_cluster_parameter_group.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster_parameter_group) | resource |
| [aws_security_group.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) | resource |
-| [aws_security_group_rule.egress](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
+| [aws_security_group_rule.egress_cidr_blocks](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
+| [aws_security_group_rule.egress_security_groups](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
| [aws_security_group_rule.ingress_cidr_blocks](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
| [aws_security_group_rule.ingress_security_groups](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
| [aws_security_group_rule.traffic_inside_security_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
@@ -58,6 +59,8 @@
| [allocated\_storage](#input\_allocated\_storage) | The allocated storage in GBs | `number` | `null` | no |
| [allow\_major\_version\_upgrade](#input\_allow\_major\_version\_upgrade) | Enable to allow major engine version upgrades when changing engine versions. Defaults to false. | `bool` | `false` | no |
| [allowed\_cidr\_blocks](#input\_allowed\_cidr\_blocks) | List of CIDR blocks allowed to access the cluster | `list(string)` | `[]` | no |
+| [allowed\_egress\_cidr\_blocks](#input\_allowed\_egress\_cidr\_blocks) | List of allowed egress CIDR blocks | `list(string)` | [
"0.0.0.0/0"
]
| no |
+| [allowed\_egress\_security\_groups](#input\_allowed\_egress\_security\_groups) | List of allowed egress Security Groups | `list(string)` | `[]` | no |
| [apply\_immediately](#input\_apply\_immediately) | Specifies whether any cluster modifications are applied immediately, or during the next maintenance window | `bool` | `true` | no |
| [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,
in the order they appear in the list. New attributes are appended to the
end of the list. The elements of the list are joined by the `delimiter`
and treated as a single ID element. | `list(string)` | `[]` | no |
| [auto\_minor\_version\_upgrade](#input\_auto\_minor\_version\_upgrade) | Indicates that minor engine upgrades will be applied automatically to the DB instance during the maintenance window | `bool` | `true` | no |
diff --git a/main.tf b/main.tf
index b7a0c54f..43e72bc8 100644
--- a/main.tf
+++ b/main.tf
@@ -55,17 +55,28 @@ resource "aws_security_group_rule" "ingress_cidr_blocks" {
security_group_id = join("", aws_security_group.default[*].id)
}
-resource "aws_security_group_rule" "egress" {
+resource "aws_security_group_rule" "egress_cidr_blocks" {
count = local.enabled && var.egress_enabled ? 1 : 0
- description = "Allow outbound traffic"
+ description = "Allow outbound traffic from existing CIDR blocks"
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
- cidr_blocks = ["0.0.0.0/0"]
+ cidr_blocks = var.allowed_egress_cidr_blocks
security_group_id = join("", aws_security_group.default[*].id)
}
+resource "aws_security_group_rule" "egress_security_groups" {
+ count = local.enabled && var.egress_enabled ? length(var.allowed_egress_security_groups) : 0
+ description = "Allow outbound traffic from existing security groups"
+ type = "egress"
+ from_port = 0
+ to_port = 0
+ protocol = "-1"
+ source_security_group_id = var.allowed_egress_security_groups[count.index]
+ security_group_id = join("", aws_security_group.default.*.id)
+}
+
# The name "primary" is poorly chosen. We actually mean standalone or regional.
# The primary cluster of a global database is actually created with the "secondary" cluster resource below.
resource "aws_rds_cluster" "primary" {
diff --git a/variables.tf b/variables.tf
index 4598a19f..110a68e9 100644
--- a/variables.tf
+++ b/variables.tf
@@ -14,6 +14,12 @@ variable "security_groups" {
description = "List of security groups to be allowed to connect to the DB instance"
}
+variable "allowed_egress_security_groups" {
+ type = list(string)
+ default = []
+ description = "List of allowed egress Security Groups"
+}
+
variable "vpc_id" {
type = string
description = "VPC ID to create the cluster in (e.g. `vpc-a22222ee`)"
@@ -211,6 +217,12 @@ variable "allowed_cidr_blocks" {
description = "List of CIDR blocks allowed to access the cluster"
}
+variable "allowed_egress_cidr_blocks" {
+ type = list(string)
+ default = ["0.0.0.0/0"]
+ description = "List of allowed egress CIDR blocks"
+}
+
variable "publicly_accessible" {
type = bool
description = "Set to true if you want your cluster to be publicly accessible (such as via QuickSight)"