Skip to content

Commit 30437f7

Browse files
Merge pull request #2 from jaynathani-tamr/DEV-13447-sg-module-rds
DEV-13447 sg module rds
2 parents ecde2e6 + 878e0dc commit 30437f7

File tree

16 files changed

+216
-38
lines changed

16 files changed

+216
-38
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ override.tf.json
2727

2828
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
2929
# example: *tfplan*
30+
31+
# IDE files
32+
**/.idea/*

README.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
11
# Tamr AWS RDS Terraform Module
2-
This terraform module creates an AWS RDS postgres instance.
2+
This terraform module creates an AWS RDS postgres instance that will be used by TAMR.
33
This repo follows the [terraform standard module structure](https://www.terraform.io/docs/modules/index.html#standard-module-structure).
44

55
# Examples
66
## Basic
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-rds-postgres?ref=0.1.0"
11-
postgres_name = "tamr_rds_db"
12-
parameter_group_name = "tamr-rds-postgres-pg"
13-
identifier_prefix = "tamr-rds-"
10+
source = "git::https://github.com/Datatamer/terraform-rds-postgres.git?ref=0.1.0"
11+
postgres_name = "example_rds_postgres"
12+
parameter_group_name = "example-rds-postgres-pg"
13+
identifier_prefix = "example-rds-"
1414
15-
username = "tamr"
16-
password = "8characterpassword"
15+
username = "exampleUsername"
16+
password = "examplePassword"
1717
18-
subnet_name = "rds_private"
19-
vpc_security_group_ids = []
18+
subnet_name = "example_subnet"
19+
spark_cluster_sg_ids = ["sg-examplesecuritygroup1", "sg-examplesecuritygroup2"]
20+
tamr_vm_sg_id = "sg-exampletamrsecuritygroup"
21+
vpc_id = "vpc-examplevpcnetworkid"
2022
}
2123
```
2224

2325
# Resources Created
2426
This terraform module will create:
2527
* an AWS RDS Postgres instance
2628
* database parameter group
29+
* A security group for the rds instance
2730

2831
# Variables
2932
## Inputs
30-
* `vpc_security_group_ids` (required): List of VPC security groups to associate
3133
* `password` (required): The postgres password
34+
* `tamr_vm_sg_id` (required): Security group id attached to the tamr vm
35+
* `spark_cluster_sg_id` (required): Security group is attached to the ec2 instances of EMR Spark
36+
* `vpc_id` (required): VPC ID for the rds security group
3237
* `username` (optional): The postgres username
3338
* `postgres_name` (optional): The name of the postgres instance
3439
* `parameter_group_name` (optional): The name of the rds parameter group
@@ -45,20 +50,22 @@ This terraform module will create:
4550
* `apply_immediately` (optional): Apply immediately, do not set this to true for production
4651
* `copy_tags_to_snapshot` (optional): Copy tags to snapshots
4752
* `additional_tags` (optional): Tags to set on the RDS instance
53+
* `security_group_name` (optional): Name for the security group for the rds instance
54+
* `additional_cidrs` (optional): Additional CIDR to connect to RDS Postgres instance
4855

4956
## Outputs
5057
* `rds_postgres_pg_id`: ID of the RDS postgres parameter group
5158
* `rds_postgres_id`: ID of the of the RDS instance
59+
* `rds_sg_id`: ID of the security group attached to the RDS instance
5260

5361
# References
5462
* AWS RDS: https://aws.amazon.com/rds/features/
5563
* Terraform module structure: https://www.terraform.io/docs/modules/index.html#standard-module-structure
5664

5765
# Development
5866
## Releasing new versions
59-
* Update version contained in `VERSION`
60-
* Document changes in `CHANGELOG.md`
61-
* Create a tag in github for the commit associated with the version
67+
* Updated version contained in `VERSION`
68+
* Documented changes in `CHANGELOG.md`
6269

6370
# License
6471
Apache 2 Licensed. See LICENSE for full details.

examples/local.tfvars

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
postgres_db_name = "example_postgres_db"

examples/main.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module "rds_postgres" {
2+
source = "git::https://github.com/Datatamer/terraform-rds-postgres.git?ref=0.1.0"
3+
postgres_name = "example_rds_postgres"
4+
parameter_group_name = "example-rds-postgres-pg"
5+
identifier_prefix = "example-rds-"
6+
7+
username = "exampleUsername"
8+
password = "examplePassword"
9+
10+
subnet_name = "example_subnet"
11+
spark_cluster_sg_ids = ["sg-examplesecuritygroup1", "sg-examplesecuritygroup2"]
12+
tamr_vm_sg_id = "sg-exampletamrsecuritygroup"
13+
vpc_id = "vpc-examplevpcnetworkid"
14+
}

examples/minimal/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/minimal/main.tf

Lines changed: 0 additions & 3 deletions
This file was deleted.

examples/minimal/outputs.tf

Lines changed: 0 additions & 8 deletions
This file was deleted.

examples/minimal/providers.tf

Lines changed: 0 additions & 2 deletions
This file was deleted.

examples/variables.tf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
variable "postgres_db_name" {
2+
type = string
3+
description = "Name of the postgres db"
4+
}
5+
6+
variable "parameter_group_name" {
7+
type = string
8+
description = "Name of the parameter group"
9+
}
10+
11+
variable "identifier_prefix" {
12+
type = string
13+
description = "Identifier prefix for the resources"
14+
}
15+
16+
variable "pg_username" {
17+
type = string
18+
description = "Username for postgres"
19+
}
20+
21+
variable "pg_password" {
22+
type = string
23+
description = "Password for postgres"
24+
}
25+
26+

main.tf

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
resource "aws_db_parameter_group" "rds_postgres_pg" {
22
name = var.parameter_group_name
33
family = "postgres9.6"
4-
description = "RDS default parameter group"
4+
description = "TAMR RDS parameter group"
5+
tags = var.additional_tags
6+
}
7+
8+
module "rds_sg" {
9+
source = "./modules/rds-postgres-sg"
10+
spark_cluster_sg_ids = var.spark_cluster_sg_ids
11+
tamr_vm_sg_id = var.tamr_vm_sg_id
12+
vpc_id = var.vpc_id
13+
security_group_name = var.security_group_name
14+
additional_cidrs = var.additional_cidrs
15+
additional_tags = var.additional_tags
516
}
617

718
resource "aws_db_instance" "rds_postgres" {
@@ -23,7 +34,7 @@ resource "aws_db_instance" "rds_postgres" {
2334
db_subnet_group_name = var.subnet_name
2435
multi_az = true
2536
publicly_accessible = false
26-
vpc_security_group_ids = var.vpc_security_group_ids
37+
vpc_security_group_ids = [module.rds_sg.rds_sg_id]
2738
parameter_group_name = aws_db_parameter_group.rds_postgres_pg.name
2839

2940
maintenance_window = var.maintenance_window
@@ -34,10 +45,7 @@ resource "aws_db_instance" "rds_postgres" {
3445
apply_immediately = var.apply_immediately
3546

3647
copy_tags_to_snapshot = var.copy_tags_to_snapshot
37-
tags = merge(
38-
{"Name": var.postgres_name},
39-
var.additional_tags,
40-
)
48+
tags = var.additional_tags
4149

4250
lifecycle {
4351
ignore_changes = [password]

0 commit comments

Comments
 (0)