Skip to content

Commit 4469a13

Browse files
authored
Merge pull request #13 from Datatamer/DEV-14447
DEV-14447 Combine sg ids input variables.
2 parents ce4bf06 + addea53 commit 4469a13

File tree

10 files changed

+29
-54
lines changed

10 files changed

+29
-54
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Tamr Terraform Template Repo
22

3+
## v0.4.0 - Oct 27th 2020
4+
* Consolidates inputs `tamr_vm_sg_id` and `spark_cluster_sg_ids` into one input, `ingress_sg_ids`
5+
36
## v0.3.1 - Sep 10th 2020
47
* Adds outputs, `rds_username` and `rds_dbname`
58

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This repo follows the [terraform standard module structure](https://www.terrafor
77
Inline example implementation of the module. This is the most basic example of what it would look like to use this module.
88
```
99
module "rds_postgres" {
10-
source = "git::https://github.com/Datatamer/terraform-aws-rds-postgres.git?ref=0.3.0"
10+
source = "git::https://github.com/Datatamer/terraform-aws-rds-postgres.git?ref=0.4.0"
1111
postgres_name = "example_rds_postgres"
1212
parameter_group_name = "example-rds-postgres-pg"
1313
identifier_prefix = "example-rds-"
@@ -16,8 +16,7 @@ module "rds_postgres" {
1616
1717
subnet_group_name = "example_subnet"
1818
rds_subnet_ids = ["example-subnet-1", "example-subnet-2"]
19-
spark_cluster_sg_ids = ["sg-examplesecuritygroup1", "sg-examplesecuritygroup2"]
20-
tamr_vm_sg_id = "sg-exampletamrsecuritygroup"
19+
ingress_sg_ids = ["sg-sparksecuritygroup1", "sg-sparksecuritygroup2", "sg-tamrvmsecuritygroup"]
2120
vpc_id = "vpc-examplevpcnetworkid"
2221
}
2322
```
@@ -50,11 +49,10 @@ This terraform module will create:
5049

5150
| Name | Description | Type | Default | Required |
5251
|------|-------------|------|---------|:--------:|
52+
| ingress\_sg\_ids | List of security group IDs to allow ingress from (i.e. Spark cluster SG IDs, Tamr VM SG ID) | `list(string)` | n/a | yes |
5353
| password | The password for the master DB user. | `string` | n/a | yes |
5454
| rds\_subnet\_ids | VPC subnet IDs in subnet group | `list(string)` | n/a | yes |
55-
| spark\_cluster\_sg\_ids | List of Spark service access security group IDs to allow ingress from | `list(string)` | n/a | yes |
5655
| subnet\_group\_name | The name of the subnet group to add the RDS instance to | `string` | n/a | yes |
57-
| tamr\_vm\_sg\_id | Tamr VM security group ID to allow ingress from | `string` | n/a | yes |
5856
| vpc\_id | VPC ID for the rds security group | `string` | n/a | yes |
5957
| additional\_cidrs | Additional CIDR to connect to RDS Postgres instance | `list(string)` | `[]` | no |
6058
| additional\_tags | Additional tags to set on the RDS instance | `map` | `{}` | no |

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.1
1+
0.4.0

examples/minimal/local.tfvars

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
vpc_id = "vpc-example"
2-
subnet_ids = ["subnet-az1", "subnet-az2"]
3-
spark_service_access_sg_ids = ["example-spark-service-access-sg"]
4-
tamr_vm_sg_id = "example-tamr-vm-sg"
1+
vpc_id = "vpc-example"
2+
subnet_ids = ["subnet-az1", "subnet-az2"]
3+
ingress_sg_ids = ["example-spark-service-access-sg", "example-tamr-vm-sg"]

examples/minimal/main.tf

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module "rds_postgres" {
2-
# source = "git::https://github.com/Datatamer/terraform-aws-rds-postgres.git?ref=0.3.0"
2+
# source = "git::https://github.com/Datatamer/terraform-aws-rds-postgres.git?ref=0.4.0"
33
source = "../.."
44

55
identifier_prefix = "example-rds-pg-"
@@ -12,7 +12,5 @@ module "rds_postgres" {
1212
subnet_group_name = "example_subnet_group"
1313
# Network requirement: DB subnet group needs a subnet in at least two Availability Zones
1414
rds_subnet_ids = var.subnet_ids
15-
16-
spark_cluster_sg_ids = var.spark_service_access_sg_ids
17-
tamr_vm_sg_id = var.tamr_vm_sg_id
15+
ingress_sg_ids = var.ingress_sg_ids
1816
}

main.tf

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ resource "aws_db_subnet_group" "rds_postgres_subnet_group" {
1111
}
1212

1313
module "rds_sg" {
14-
source = "./modules/rds-postgres-sg"
15-
spark_cluster_sg_ids = var.spark_cluster_sg_ids
16-
tamr_vm_sg_id = var.tamr_vm_sg_id
17-
vpc_id = var.vpc_id
18-
security_group_name = var.security_group_name
19-
additional_cidrs = var.additional_cidrs
20-
additional_tags = var.additional_tags
14+
source = "./modules/rds-postgres-sg"
15+
ingress_sg_ids = var.ingress_sg_ids
16+
vpc_id = var.vpc_id
17+
security_group_name = var.security_group_name
18+
additional_cidrs = var.additional_cidrs
19+
additional_tags = var.additional_tags
2120
}
2221

2322
resource "aws_db_instance" "rds_postgres" {

modules/rds-postgres-sg/README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ This terraform module creates the security group and the security group rules fo
44
# Example
55
```
66
module "rds_sg" {
7-
source = "git::https://github.com/Datatamer/terraform-aws-rds-postgres.git//modules/rds-postgres-sg?ref=0.3.0"
8-
spark_cluster_sg_ids = ["sg-examplesparksecuritygroup1", "sg-examplesparksecuritygroup2"]
9-
tamr_vm_sg_id = "sg-exampletamrvmsecuritygroup"
7+
source = "git::https://github.com/Datatamer/terraform-aws-rds-postgres.git//modules/rds-postgres-sg?ref=0.4.0"
8+
ingress_sg_ids = ["sg-examplesparksecuritygroup1", "sg-examplesparksecuritygroup2", "sg-exampletamrvmsecuritygroup"]
109
vpc_id = "vpc-examplevpcid"
1110
security_group_name = "examplerdssecuritygroup"
1211
additional_cidrs = ["1.2.3.4/32"]
@@ -36,8 +35,7 @@ This terraform module will create:
3635

3736
| Name | Description | Type | Default | Required |
3837
|------|-------------|------|---------|:--------:|
39-
| spark\_cluster\_sg\_ids | List of Security groups attached to the ec2 instances of EMR Spark | `list(string)` | n/a | yes |
40-
| tamr\_vm\_sg\_id | Security group id attached to the tamr vm | `string` | n/a | yes |
38+
| ingress\_sg\_ids | List of security group IDs to allow ingress from (i.e. Spark cluster SG IDs, Tamr VM SG ID) | `list(string)` | n/a | yes |
4139
| vpc\_id | VPC ID for the rds security group | `string` | n/a | yes |
4240
| additional\_cidrs | Additional CIDR to connect to RDS Postgres instance | `list(string)` | `[]` | no |
4341
| additional\_tags | Additional tags to set on the RDS instance | `map` | `{}` | no |

modules/rds-postgres-sg/main.tf

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,15 @@ resource "aws_security_group" "rds_postgres_sg" {
55
tags = var.additional_tags
66
}
77

8-
resource "aws_security_group_rule" "tamr_vm" {
9-
description = "Rule for ingress from Tamr VM to Postgres"
8+
resource "aws_security_group_rule" "pg_ingress" {
9+
description = "Ingress rule to Postgres DB instance."
10+
count = length(var.ingress_sg_ids)
1011
from_port = 5432
1112
protocol = "tcp"
1213
security_group_id = aws_security_group.rds_postgres_sg.id
1314
to_port = 5432
1415
type = "ingress"
15-
source_security_group_id = var.tamr_vm_sg_id
16-
}
17-
18-
resource "aws_security_group_rule" "spark_cluster" {
19-
description = "Rule for ingress from Spark cluster to Postgres"
20-
count = length(var.spark_cluster_sg_ids)
21-
from_port = 5432
22-
protocol = "tcp"
23-
security_group_id = aws_security_group.rds_postgres_sg.id
24-
to_port = 5432
25-
type = "ingress"
26-
source_security_group_id = var.spark_cluster_sg_ids[count.index]
16+
source_security_group_id = var.ingress_sg_ids[count.index]
2717
}
2818

2919
resource "aws_security_group_rule" "additional_cidrs" {

modules/rds-postgres-sg/variables.tf

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@ variable "security_group_name" {
44
default = "tamr_rds_sg"
55
}
66

7-
variable "tamr_vm_sg_id" {
8-
description = "Security group id attached to the tamr vm"
9-
type = string
10-
}
11-
12-
variable "spark_cluster_sg_ids" {
13-
description = "List of Security groups attached to the ec2 instances of EMR Spark"
7+
variable "ingress_sg_ids" {
8+
description = "List of security group IDs to allow ingress from (i.e. Spark cluster SG IDs, Tamr VM SG ID)"
149
type = list(string)
1510
}
1611

variables.tf

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,8 @@ variable "security_group_name" {
109109
default = "tamr_rds_sg"
110110
}
111111

112-
variable "tamr_vm_sg_id" {
113-
description = "Tamr VM security group ID to allow ingress from"
114-
type = string
115-
}
116-
117-
variable "spark_cluster_sg_ids" {
118-
description = "List of Spark service access security group IDs to allow ingress from"
112+
variable "ingress_sg_ids" {
113+
description = "List of security group IDs to allow ingress from (i.e. Spark cluster SG IDs, Tamr VM SG ID)"
119114
type = list(string)
120115
}
121116

0 commit comments

Comments
 (0)