Skip to content

Commit 6431307

Browse files
committed
upgrading the documentation for this module and removing user/pass inputs for the clone
1 parent 3e1b7eb commit 6431307

File tree

4 files changed

+69
-49
lines changed

4 files changed

+69
-49
lines changed

README.md

Lines changed: 58 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,81 @@
11

2-
# Create PostgreSQL RDS Database | Terraform Module
2+
# PostgreSQL RDS | Enterprise Grade | Terraform Module
33

4-
Create a simple 32G AWS PostgreSQL RDS database. This module suits rapid proof of concept development - it is not designed to provision a production quality enterprise database.
4+
Provision either a new **enterprise grade** PostgreSQL RDS database or **create a clone of another database from its snapshot**. In this context enterprise grade means
5+
- a 48 long password chosen from a set of 70 characters
6+
- a non predictable master database username string
7+
- a high redundancy multi-availability zone database
8+
- private subnet residency in a non-default VPC (if you so wish)
9+
- behind the scenes encryption at rest
10+
- robust options for backup (maintenance) windows and retention period
11+
- sensible descriptive resource tags
512

6-
The username is readwrite and the database listens on port 5432. Just provide a security group, private subnet ids, the database name and the ubiquitous tag information.
13+
## From Snapshot or New
714

8-
The only outputs needed are the out_database_hostname and the simple terraform generated out_database_password.
15+
This module will conditionally **instantiate from a snapshot** depending on a boolean variable that you provide.
916

10-
## Usage
17+
## integration test | Jenkinsfile
1118

12-
locals
13-
{
14-
ecosystem_name = "business-app"
15-
}
19+
This module comes with an **[integraion test](integration/postgres.test-main.tf)** and a Jenkinsfile so you know that it has been validated day in, day out. It doesn't grow stale and stop working like many other Terraform modules.
1620

17-
module postgres_db
18-
{
19-
source = "github.com/devops4me/terraform-aws-postgres-rds"
20-
in_security_group_id = "${ module.security-group.out_security_group_id }"
21-
in_db_subnet_ids = "${ module.vpc-network.out_private_subnet_ids }"
21+
## Test Drive | Create Two Databases
2222

23-
in_database_name = "businessdata"
23+
Why not test drive this PostgreSQL terraform module.
2424

25-
in_ecosystem_name = "${ local.ecosystem_name }"
26-
in_tag_timestamp = "${ module.resource-tags.out_tag_timestamp }"
27-
in_tag_description = "${ module.resource-tags.out_tag_description }"
28-
}
25+
```
26+
git clone https://github.com/devops4me/terraform-aws-postgres-rds
27+
cd terraform-aws-postgres-rds/integration
28+
# Export your AWS Credentials and Region
29+
terraform init
30+
terraform deploy
31+
```
32+
33+
## Usage | Creating New and Cloned Databases
2934

30-
module vpc-network
31-
{
32-
source = "github.com/devops4me/terraform-aws-vpc-network"
33-
in_vpc_cidr = "10.66.0.0/16"
34-
in_num_public_subnets = 3
35-
in_num_private_subnets = 3
35+
This is a small insight
3636

37-
in_ecosystem_name = "${ local.ecosystem_name }"
38-
in_tag_timestamp = "${ module.resource-tags.out_tag_timestamp }"
39-
in_tag_description = "${ module.resource-tags.out_tag_description }"
37+
```
38+
locals {
39+
ecosystem_name = "canary"
40+
fresh_db_name = "freshdb"
41+
clone_db_name = "clonedb"
4042
}
4143
42-
module security-group
43-
{
44-
source = "github.com/devops4me/terraform-aws-security-group"
45-
in_ingress = [ "ssh", "https", ]
46-
in_vpc_id = "${ module.vpc-network.out_vpc_id }"
44+
module fresh_db {
45+
46+
source = "github.com/devops4me/terraform-aws-postgres-rds"
47+
48+
in_security_group_id = module.security-group.out_security_group_id
49+
in_db_subnet_ids = module.vpc-network.out_private_subnet_ids
50+
in_database_name = local.fresh_db_name
4751
48-
in_ecosystem_name = "${ local.ecosystem_name }"
49-
in_tag_timestamp = "${ module.resource-tags.out_tag_timestamp }"
50-
in_tag_description = "${ module.resource-tags.out_tag_description }"
52+
in_ecosystem_name = local.ecosystem_name
53+
in_tag_timestamp = module.resource-tags.out_tag_timestamp
54+
in_tag_description = module.resource-tags.out_tag_description
5155
}
5256
53-
module resource-tags
54-
{
55-
source = "github.com/devops4me/terraform-aws-resource-tags"
57+
module clone_db {
58+
59+
source = "github.com/devops4me/terraform-aws-postgres-rds"
60+
61+
in_security_group_id = module.security-group.out_security_group_id
62+
in_db_subnet_ids = module.vpc-network.out_private_subnet_ids
63+
in_id_of_db_to_clone = var.in_id_of_db_to_clone
64+
in_clone_snapshot = true
65+
66+
in_database_name = local.clone_db_name
67+
68+
in_ecosystem_name = local.ecosystem_name
69+
in_tag_timestamp = module.resource-tags.out_tag_timestamp
70+
in_tag_description = module.resource-tags.out_tag_description
5671
}
72+
```
5773

74+
The important outputs are the **out_database_hostname**, **out_database_username** and the **out_database_password**.
5875

59-
The important outputs are the **out_database_hostname** and the terraform generated **out_database_password**.
76+
Look at the integration test for the bells and whistles that terraform demands.
6077

78+
---
6179

6280
## Inputs
6381

integration/postgres.test-main.tf

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ module fresh_db {
5050

5151
in_security_group_id = module.security-group.out_security_group_id
5252
in_db_subnet_ids = module.vpc-network.out_private_subnet_ids
53-
in_id_of_db_to_clone = var.in_id_of_db_to_clone
54-
55-
in_database_name = local.fresh_db_name
53+
in_database_name = local.fresh_db_name
5654

5755
in_ecosystem_name = local.ecosystem_name
5856
in_tag_timestamp = module.resource-tags.out_tag_timestamp

rds.postgres-main.tf

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ resource aws_db_instance fresh {
6868
| -- Just providing the ID will not cause this cloning to happen, the
6969
| -- boolean variable in_clone_snapshot must also be set to true.
7070
| --
71+
| -- Note that the username and password are absent. You are allowed to
72+
| -- reset the database name, however you must know the username and
73+
| -- password of the DB the snapshot was created from.
74+
| --
7175
*/
7276
resource aws_db_instance clone {
7377

@@ -77,8 +81,6 @@ resource aws_db_instance clone {
7781
identifier = "${ var.in_database_name }-clone-${ var.in_ecosystem_name }-${ var.in_tag_timestamp }"
7882

7983
name = var.in_database_name
80-
username = local.db_username
81-
password = random_string.dbpassword.result
8284
port = 5432
8385

8486
engine = "postgres"
@@ -147,14 +149,16 @@ resource aws_db_subnet_group me {
147149
| --
148150
*/
149151
resource random_string dbpassword {
150-
length = 32
152+
length = 48
151153
upper = true
152154
lower = true
153155
number = true
154-
special = false
156+
special = true
157+
override_special = "()[]-_:="
155158
}
156159

157160

161+
158162
/*
159163
| --
160164
| -- It is good practise for the database user name to be suffixed

rds.postgres-outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
| --
1212
*/
1313
output out_fresh_db_hostname { value = length( aws_db_instance.fresh ) == 0 ? "n/a" : aws_db_instance.fresh[0].address }
14-
output out_fresh_db_hostport { value = length( aws_db_instance.fresh ) == 0 ? "n/a" : aws_db_instance.fresh[0].endpoint }
14+
output out_fresh_db_endpoint { value = length( aws_db_instance.fresh ) == 0 ? "n/a" : aws_db_instance.fresh[0].endpoint }
1515

1616
output out_clone_db_hostname { value = length( aws_db_instance.clone ) == 0 ? "n/a" : aws_db_instance.clone[0].address }
17-
output out_clone_db_hostport { value = length( aws_db_instance.clone ) == 0 ? "n/a" : aws_db_instance.clone[0].endpoint }
17+
output out_clone_db_endpoint { value = length( aws_db_instance.clone ) == 0 ? "n/a" : aws_db_instance.clone[0].endpoint }
1818

1919
output out_database_username { value = local.db_username }
2020
output out_database_password { value = random_string.dbpassword.result }

0 commit comments

Comments
 (0)