Skip to content

Commit f863200

Browse files
committed
introduced the mandatory tag interface to this database creation module.
1 parent 6431307 commit f863200

File tree

2 files changed

+58
-22
lines changed

2 files changed

+58
-22
lines changed

rds.postgres-main.tf

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
11

2+
locals {
3+
4+
subnet_group_tags = {
5+
Name = "db-subnet-group-${ var.in_ecosystem_name }-${ var.in_tag_timestamp }"
6+
Desc = "This RDS postgres database subnet group for ${ var.in_ecosystem_name } ${ var.in_tag_description }"
7+
}
8+
9+
database_tags = {
10+
Name = var.in_database_name
11+
Id = "${ var.in_database_name }-${ var.in_ecosystem_name }-${ var.in_tag_timestamp }"
12+
}
13+
14+
cloned_database_tags = {
15+
Desc = "This PostgreSQL database named ${ var.in_database_name } was cloned from snapshot ${ data.aws_db_snapshot.from[0].id } and ${ var.in_tag_description }"
16+
}
17+
18+
fresh_database_tags = {
19+
Desc = "This brand new PostgreSQL database named ${ var.in_database_name } ${ var.in_tag_description }"
20+
}
21+
22+
}
223

324
/*
425
| --
@@ -48,12 +69,7 @@ resource aws_db_instance fresh {
4869
backup_window = "21:00-23:00"
4970
maintenance_window = "mon:00:00-mon:03:00"
5071

51-
tags = {
52-
Name = var.in_database_name
53-
Id = "${ var.in_database_name }-${ var.in_ecosystem_name }-${ var.in_tag_timestamp }"
54-
Class = "${ var.in_ecosystem_name }"
55-
Desc = "This brand new PostgreSQL database named ${ var.in_database_name } ${ var.in_tag_description }"
56-
}
72+
tags = merge( local.database_tags, local.fresh_database_tags, var.in_mandatory_tags )
5773

5874
}
5975

@@ -97,12 +113,7 @@ resource aws_db_instance clone {
97113
backup_window = "21:00-23:00"
98114
maintenance_window = "mon:00:00-mon:03:00"
99115

100-
tags = {
101-
Name = var.in_database_name
102-
Id = "${ var.in_database_name }-${ var.in_ecosystem_name }-${ var.in_tag_timestamp }"
103-
Class = "${ var.in_ecosystem_name }"
104-
Desc = "This PostgreSQL database named ${ var.in_database_name } was cloned from snapshot ${ data.aws_db_snapshot.from[0].id } and ${ var.in_tag_description }"
105-
}
116+
tags = merge( local.database_tags, local.cloned_database_tags, var.in_mandatory_tags )
106117
}
107118

108119

@@ -133,19 +144,15 @@ resource aws_db_subnet_group me {
133144
name_prefix = "db-${ var.in_ecosystem_name }"
134145
description = "RDS postgres subnet group for the ${ var.in_ecosystem_name } database."
135146
subnet_ids = var.in_db_subnet_ids
136-
137-
tags = {
138-
Name = "db-subnet-group-${ var.in_ecosystem_name }-${ var.in_tag_timestamp }"
139-
Class = "${ var.in_ecosystem_name }"
140-
Desc = "This RDS postgres database subnet group for ${ var.in_ecosystem_name } ${ var.in_tag_description }"
141-
}
147+
tags = merge( local.subnet_group_tags, var.in_mandatory_tags )
142148
}
143149

144150

145151
/*
146152
| --
147153
| -- The Terraform generated database password will contain
148-
| -- thirty two alphanumeric characters and no specials.
154+
| -- forty-eight characters that may include all alpha-numerics
155+
| -- and eight special printable characters.
149156
| --
150157
*/
151158
resource random_string dbpassword {

rds.postgres-variables.tf

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,43 @@ variable in_id_of_db_to_clone {
2222
default = ""
2323
}
2424

25+
### ############################## ###
26+
### [[variable]] in_mandatory_tags ###
27+
### ############################## ###
28+
29+
variable in_mandatory_tags {
30+
31+
description = "Optional tags unless your organization mandates that a set of given tags must be set."
32+
type = map
33+
default = { }
34+
}
35+
36+
37+
### ################# ###
38+
### in_ecosystem_name ###
39+
### ################# ###
40+
2541
variable in_ecosystem_name {
26-
description = "Creational stamp binding all infrastructure created for this ecosystem."
42+
43+
description = "Creational stamp binding all infrastructure components created on behalf of this ecosystem instance."
2744
}
2845

46+
47+
### ################ ###
48+
### in_tag_timestamp ###
49+
### ################ ###
50+
2951
variable in_tag_timestamp {
30-
description = "Ubiquitous alphanumeric timestamp for resource tags like 909081716 ( YMMDDhhmm ) for 9th Nov 2019 at 5:16 pm."
52+
53+
description = "A timestamp for resource tags in the format ymmdd-hhmm like 80911-1435"
3154
}
3255

56+
57+
### ################## ###
58+
### in_tag_description ###
59+
### ################## ###
60+
3361
variable in_tag_description {
34-
description = "Ubiquitous description for resource tags detailing who created the resource and when, where and why."
62+
63+
description = "Ubiquitous note detailing who, when, where and why for every infrastructure component."
3564
}

0 commit comments

Comments
 (0)