Skip to content

Commit 13056ba

Browse files
mbarrienczimergebot
authored andcommitted
Allow restricting aws-aurora ingress by security groups (#148)
Allow restricting aws-aurora ingress by security groupsAdd ability to restrict aws-aurora ingress by security group, not just by CIDR blocks.
1 parent 20df8cf commit 13056ba

File tree

9 files changed

+51
-23
lines changed

9 files changed

+51
-23
lines changed

aws-aurora-mysql/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ module "db" {
4444
| db\_parameters | Instance params you can set. [Doc](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Reference.html#AuroraMySQL.Reference.Parameters.Instance) | list | `<list>` | no |
4545
| env | Env for tagging and naming. See [doc](../README.md#consistent-tagging). | string | n/a | yes |
4646
| iam\_database\_authentication\_enabled | | string | `"false"` | no |
47-
| ingress\_cidr\_blocks | A list of CIDR blocks that should be allowed to communicate with this Aurora cluster. | list | n/a | yes |
47+
| ingress\_cidr\_blocks | A list of CIDR blocks that should be allowed to communicate with this Aurora cluster. | list(string) | `[]` | no |
48+
| ingress\_security\_groups | A list of security groups that should be allowed to communicate with this Aurora cluster. | list(string) | `[]` | no |
4849
| instance\_class | See valid instance types [here](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Managing.Performance.html) | string | `"db.t2.small"` | no |
4950
| instance\_count | Number of instances to create in this cluster. | string | `"1"` | no |
5051
| kms\_key\_id | If provided, storage will be encrypted with this key, otherwise an AWS-managed key is used. (Encryption is always on). | string | `""` | no |

aws-aurora-mysql/main.tf

+5-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ module "aurora" {
1919
performance_insights_enabled = "${var.performance_insights_enabled}"
2020
enabled_cloudwatch_logs_exports = ["audit", "error", "general", "slowquery"]
2121

22-
ingress_cidr_blocks = "${var.ingress_cidr_blocks}"
23-
vpc_id = "${var.vpc_id}"
24-
publicly_accessible = "${var.publicly_accessible}"
25-
port = 3306
22+
ingress_cidr_blocks = var.ingress_cidr_blocks
23+
ingress_security_groups = var.ingress_security_groups
24+
vpc_id = var.vpc_id
25+
publicly_accessible = var.publicly_accessible
26+
port = 3306
2627

2728
instance_class = "${var.instance_class}"
2829
instance_count = "${var.instance_count}"

aws-aurora-mysql/variables.tf

+8-1
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,17 @@ variable "env" {
2424
}
2525

2626
variable "ingress_cidr_blocks" {
27-
type = "list"
27+
type = list(string)
28+
default = []
2829
description = "A list of CIDR blocks that should be allowed to communicate with this Aurora cluster."
2930
}
3031

32+
variable "ingress_security_groups" {
33+
type = list(string)
34+
description = "A list of security groups that should be allowed to communicate with this Aurora cluster."
35+
default = []
36+
}
37+
3138
variable "instance_class" {
3239
type = "string"
3340
description = "See valid instance types [here](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Managing.Performance.html)"

aws-aurora-postgres/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ module "db" {
4444
| engine\_version | The version of Postgres to use. | string | `"10"` | no |
4545
| env | Env for tagging and naming. See [doc](../README.md#consistent-tagging). | string | n/a | yes |
4646
| iam\_database\_authentication\_enabled | | string | `"false"` | no |
47-
| ingress\_cidr\_blocks | A list of CIDR blocks that should be allowed to communicate with this Aurora cluster. | list | n/a | yes |
47+
| ingress\_cidr\_blocks | A list of CIDR blocks that should be allowed to communicate with this Aurora cluster. | list(string) | `[]` | no |
48+
| ingress\_security\_groups | A list of security groups that should be allowed to communicate with this Aurora cluster. | list(string) | `[]` | no |
4849
| instance\_class | See valid instance types [here](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraPostgreSQL.Managing.html) | string | `"db.r4.large"` | no |
4950
| instance\_count | Number of instances to create in this cluster. | string | `"1"` | no |
5051
| kms\_key\_id | If provided, storage will be encrypted with this key, otherwise an AWS-managed key is used. (Encryption is always on). | string | `""` | no |

aws-aurora-postgres/main.tf

+7-6
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ module "aurora" {
1717
iam_database_authentication_enabled = "${var.iam_database_authentication_enabled}"
1818
performance_insights_enabled = "${var.performance_insights_enabled}"
1919

20-
ingress_cidr_blocks = "${var.ingress_cidr_blocks}"
21-
vpc_id = "${var.vpc_id}"
22-
publicly_accessible = "${var.publicly_accessible}"
23-
port = 5432
24-
instance_class = "${var.instance_class}"
25-
instance_count = "${var.instance_count}"
20+
ingress_cidr_blocks = var.ingress_cidr_blocks
21+
ingress_security_groups = var.ingress_security_groups
22+
vpc_id = var.vpc_id
23+
publicly_accessible = var.publicly_accessible
24+
port = 5432
25+
instance_class = var.instance_class
26+
instance_count = var.instance_count
2627

2728
# backtrack_window not supported yet
2829
backtrack_window = 0

aws-aurora-postgres/variables.tf

+8-1
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,17 @@ variable "env" {
2424
}
2525

2626
variable "ingress_cidr_blocks" {
27-
type = "list"
27+
type = list(string)
28+
default = []
2829
description = "A list of CIDR blocks that should be allowed to communicate with this Aurora cluster."
2930
}
3031

32+
variable "ingress_security_groups" {
33+
type = list(string)
34+
description = "A list of security groups that should be allowed to communicate with this Aurora cluster."
35+
default = []
36+
}
37+
3138
variable "instance_class" {
3239
type = "string"
3340
description = "See valid instance types [here](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraPostgreSQL.Managing.html)"

aws-aurora/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ This is a low-level module for creating AWS Aurora clusters. We strongly reccome
1919
| engine\_version | | string | n/a | yes |
2020
| env | Env for tagging and naming. See [doc](../README.md#consistent-tagging). | string | n/a | yes |
2121
| iam\_database\_authentication\_enabled | | string | `"true"` | no |
22-
| ingress\_cidr\_blocks | | list | n/a | yes |
22+
| ingress\_cidr\_blocks | A list of CIDR blocks that should be allowed to communicate with this Aurora cluster. | list(string) | `[]` | no |
23+
| ingress\_security\_groups | A list of security groups that should be allowed to communicate with this Aurora cluster. | list(string) | `[]` | no |
2324
| instance\_class | | string | `"db.t2.small"` | no |
2425
| instance\_count | | string | `"1"` | no |
2526
| kms\_key\_id | If supplied, RDS will use this key to encrypt data at rest. Empty string means that RDS will use an AWS-managed key. Encryption is always on with this module. | string | `""` | no |

aws-aurora/main.tf

+8-7
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,25 @@ locals {
1212
}
1313

1414
resource "aws_security_group" "rds" {
15-
name = "${local.name}"
15+
name = local.name
1616
description = "Allow db traffic."
1717

18-
vpc_id = "${var.vpc_id}"
18+
vpc_id = var.vpc_id
1919

2020
ingress {
21-
from_port = "${var.port}"
22-
to_port = "${var.port}"
23-
protocol = "tcp"
24-
cidr_blocks = "${var.ingress_cidr_blocks}"
21+
from_port = var.port
22+
to_port = var.port
23+
protocol = "tcp"
24+
cidr_blocks = var.ingress_cidr_blocks
25+
security_groups = var.ingress_security_groups
2526
}
2627

2728
lifecycle {
2829
create_before_destroy = true
2930
ignore_changes = ["name", "description"]
3031
}
3132

32-
tags = "${local.tags}"
33+
tags = local.tags
3334
}
3435

3536
resource "aws_rds_cluster" "db" {

aws-aurora/variables.tf

+9-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ variable "env" {
2020
}
2121

2222
variable "ingress_cidr_blocks" {
23-
type = "list"
23+
type = list(string)
24+
default = []
25+
description = "A list of CIDR blocks that should be allowed to communicate with this Aurora cluster."
26+
}
27+
28+
variable "ingress_security_groups" {
29+
type = list(string)
30+
description = "A list of security groups that should be allowed to communicate with this Aurora cluster."
31+
default = []
2432
}
2533

2634
variable "instance_class" {

0 commit comments

Comments
 (0)