Skip to content

Commit cdd1e2e

Browse files
committed
passed initial checks for creating a fresh and a (snap) cloned database
1 parent cca6e5e commit cdd1e2e

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

integration/postgres.test-main.tf

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,44 @@ provider aws {
2020
}
2121
}
2222

23-
2423
locals {
2524
ecosystem_name = "integration"
26-
new_db_name = "brandnewbox"
27-
cloned_db_name = "copycatbox"
25+
fresh_db_name = "brandnewbox"
26+
clone_db_name = "copycatbox"
27+
}
28+
29+
30+
variable in_id_of_db_to_clone {
31+
description = "The ID of mummy database to clone from."
2832
}
2933

34+
output out_fresh_database_hostname { value = module.fresh_db.out_fresh_db_hostname }
35+
output out_fresh_database_hostport { value = module.fresh_db.out_fresh_db_hostport }
36+
37+
output out_clone_database_hostname { value = module.clone_db.out_clone_db_hostname }
38+
output out_clone_database_hostport { value = module.clone_db.out_clone_db_hostport }
3039

31-
output out_database_hostname { value = module.postgres_db.out_database_hostname }
32-
output out_database_hostport { value = module.postgres_db.out_database_hostport }
33-
output out_database_username { value = module.postgres_db.out_database_username }
34-
output out_database_password { value = module.postgres_db.out_database_password }
40+
output out_fresh_database_username { value = module.fresh_db.out_database_username }
41+
output out_fresh_database_password { value = module.fresh_db.out_database_password }
3542

3643

37-
module brand_new_db {
44+
module fresh_db {
3845

3946
source = "./.."
4047

4148
in_security_group_id = module.security-group.out_security_group_id
4249
in_db_subnet_ids = module.vpc-network.out_private_subnet_ids
4350
in_id_of_db_to_clone = var.in_id_of_db_to_clone
4451

45-
in_database_name = local.data_base_name
52+
in_database_name = local.fresh_db_name
4653

4754
in_ecosystem_name = local.ecosystem_name
4855
in_tag_timestamp = module.resource-tags.out_tag_timestamp
4956
in_tag_description = module.resource-tags.out_tag_description
5057
}
5158

5259

53-
module cloned_db {
60+
module clone_db {
5461

5562
source = "./.."
5663

@@ -59,7 +66,7 @@ module cloned_db {
5966
in_id_of_db_to_clone = var.in_id_of_db_to_clone
6067
in_clone_snapshot = true
6168

62-
in_database_name = local.data_base_name
69+
in_database_name = local.clone_db_name
6370

6471
in_ecosystem_name = local.ecosystem_name
6572
in_tag_timestamp = module.resource-tags.out_tag_timestamp

rds.postgres-main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ locals {
2626
resource aws_db_instance fresh {
2727

2828
count = var.in_clone_snapshot ? 0 : 1
29-
identifier = "${ var.in_database_name }-${ var.in_ecosystem_name }-${ var.in_tag_timestamp }"
29+
identifier = "${ var.in_database_name }-fresh-${ var.in_ecosystem_name }-${ var.in_tag_timestamp }"
3030

3131
name = var.in_database_name
3232
username = local.db_username
@@ -73,8 +73,8 @@ resource aws_db_instance clone {
7373

7474
count = var.in_clone_snapshot ? 1 : 0
7575

76-
snapshot_identifier = data.aws_db_snapshot.parent[0].result
77-
identifier = "${ var.in_database_name }-${ var.in_ecosystem_name }-${ var.in_tag_timestamp }"
76+
snapshot_identifier = data.aws_db_snapshot.from[0].id
77+
identifier = "${ var.in_database_name }-clone-${ var.in_ecosystem_name }-${ var.in_tag_timestamp }"
7878

7979
name = var.in_database_name
8080
username = local.db_username
@@ -99,7 +99,7 @@ resource aws_db_instance clone {
9999
Name = var.in_database_name
100100
Id = "${ var.in_database_name }-${ var.in_ecosystem_name }-${ var.in_tag_timestamp }"
101101
Class = "${ var.in_ecosystem_name }"
102-
Desc = "This PostgreSQL database named ${ var.in_database_name } was cloned from snapshot ${ data.aws_db_snapshot.parent[0].result } and ${ var.in_tag_description }"
102+
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 }"
103103
}
104104
}
105105

rds.postgres-outputs.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
output out_fresh_db_hostname { value = length( aws_db_instance.fresh ) == 0 ? "n/a" : aws_db_instance.fresh[0].address }
1414
output out_fresh_db_hostport { value = length( aws_db_instance.fresh ) == 0 ? "n/a" : aws_db_instance.fresh[0].endpoint }
15+
1516
output out_clone_db_hostname { value = length( aws_db_instance.clone ) == 0 ? "n/a" : aws_db_instance.clone[0].address }
1617
output out_clone_db_hostport { value = length( aws_db_instance.clone ) == 0 ? "n/a" : aws_db_instance.clone[0].endpoint }
1718

rds.postgres-variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ variable in_clone_snapshot {
1818
}
1919

2020
variable in_id_of_db_to_clone {
21-
description = "If the ID of mummy database to clone is omitted the parameter will not be set."
21+
description = "The ID of mummy database whose snapshot the database will be cloned from."
2222
default = ""
2323
}
2424

0 commit comments

Comments
 (0)