Skip to content

Commit 81db512

Browse files
authored
fix: Correct usage of password and allow restored snapshots to set password, username, etc. (#384)
1 parent 1b3549f commit 81db512

File tree

7 files changed

+14
-21
lines changed

7 files changed

+14
-21
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@ Users have the ability to:
335335
| <a name="output_db_instance_resource_id"></a> [db\_instance\_resource\_id](#output\_db\_instance\_resource\_id) | The RDS Resource ID of this instance |
336336
| <a name="output_db_instance_status"></a> [db\_instance\_status](#output\_db\_instance\_status) | The RDS instance status |
337337
| <a name="output_db_instance_username"></a> [db\_instance\_username](#output\_db\_instance\_username) | The master username for the database |
338-
| <a name="output_db_master_password"></a> [db\_master\_password](#output\_db\_master\_password) | The master password |
339338
| <a name="output_db_option_group_arn"></a> [db\_option\_group\_arn](#output\_db\_option\_group\_arn) | The ARN of the db option group |
340339
| <a name="output_db_option_group_id"></a> [db\_option\_group\_id](#output\_db\_option\_group\_id) | The db option group id |
341340
| <a name="output_db_parameter_group_arn"></a> [db\_parameter\_group\_arn](#output\_db\_parameter\_group\_arn) | The ARN of the db parameter group |

UPGRADE-4.0.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ If you find a bug, please open an issue with supporting configuration to reprodu
4343
2. Renamed variables:
4444

4545
- `name` (deprecated) -> `db_name`
46+
- `master_password` -> `password`
4647

4748
3. Added variables:
4849

@@ -54,7 +55,7 @@ If you find a bug, please open an issue with supporting configuration to reprodu
5455

5556
5. Renamed outputs:
5657

57-
- None
58+
- `db_instance_master_password` -> `db_instance_password`
5859

5960
6. Added outputs:
6061

@@ -88,7 +89,7 @@ module "asg" {
8889
source = "terraform-aws-modules/rds/aws"
8990
version = "~> 4.0"
9091
91-
master_password = "MySuperStrongPassword!"
92+
password = "MySuperStrongPassword!"
9293
# Set random password creation to false if providing your own password as input
9394
create_random_password = false
9495

main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
locals {
2-
create_random_password = var.create_db_instance && var.create_random_password && var.snapshot_identifier == null
3-
master_password = try(random_password.master_password[0].result, var.password)
2+
create_random_password = var.create_db_instance && var.create_random_password && var.replicate_source_db == null
3+
password = try(random_password.master_password[0].result, var.password)
44

55
db_subnet_group_name = var.create_db_subnet_group ? module.db_subnet_group.db_subnet_group_id : var.db_subnet_group_name
66
parameter_group_name_id = var.create_db_parameter_group ? module.db_parameter_group.db_parameter_group_id : var.parameter_group_name
@@ -80,7 +80,7 @@ module "db_instance" {
8080

8181
db_name = var.db_name
8282
username = var.username
83-
password = local.master_password
83+
password = local.password
8484
port = var.port
8585
domain = var.domain
8686
domain_iam_role_name = var.domain_iam_role_name

modules/db_instance/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ No modules.
110110
| <a name="output_db_instance_endpoint"></a> [db\_instance\_endpoint](#output\_db\_instance\_endpoint) | The connection endpoint |
111111
| <a name="output_db_instance_hosted_zone_id"></a> [db\_instance\_hosted\_zone\_id](#output\_db\_instance\_hosted\_zone\_id) | The canonical hosted zone ID of the DB instance (to be used in a Route 53 Alias record) |
112112
| <a name="output_db_instance_id"></a> [db\_instance\_id](#output\_db\_instance\_id) | The RDS instance ID |
113-
| <a name="output_db_instance_master_password"></a> [db\_instance\_master\_password](#output\_db\_instance\_master\_password) | The master password |
114113
| <a name="output_db_instance_name"></a> [db\_instance\_name](#output\_db\_instance\_name) | The database name |
114+
| <a name="output_db_instance_password"></a> [db\_instance\_password](#output\_db\_instance\_password) | The master password |
115115
| <a name="output_db_instance_port"></a> [db\_instance\_port](#output\_db\_instance\_port) | The database port |
116116
| <a name="output_db_instance_resource_id"></a> [db\_instance\_resource\_id](#output\_db\_instance\_resource\_id) | The RDS Resource ID of this instance |
117117
| <a name="output_db_instance_status"></a> [db\_instance\_status](#output\_db\_instance\_status) | The RDS instance status |

modules/db_instance/main.tf

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ locals {
33

44
final_snapshot_identifier = var.skip_final_snapshot ? null : "${var.final_snapshot_identifier_prefix}-${var.identifier}-${try(random_id.snapshot_identifier[0].hex, "")}"
55

6-
# For replica instances or instances restored from snapshot, the metadata is already baked into the source
7-
metadata_already_exists = var.snapshot_identifier != null || var.replicate_source_db != null
8-
username = local.metadata_already_exists ? null : var.username
9-
password = local.metadata_already_exists ? null : var.password
10-
engine = local.metadata_already_exists ? null : var.engine
11-
engine_version = var.replicate_source_db != null ? null : var.engine_version
6+
# Replicas will use source metadata
7+
username = var.replicate_source_db != null ? null : var.username
8+
password = var.replicate_source_db != null ? null : var.password
9+
engine = var.replicate_source_db != null ? null : var.engine
10+
engine_version = var.replicate_source_db != null ? null : var.engine_version
1211
}
1312

1413
# Ref. https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html#genref-aws-service-namespaces

modules/db_instance/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ output "db_instance_domain_iam_role_name" {
7979
value = try(aws_db_instance.this[0].domain_iam_role_name, "")
8080
}
8181

82-
output "db_instance_master_password" {
82+
output "db_instance_password" {
8383
description = "The master password"
8484
value = try(aws_db_instance.this[0].password, "")
8585
sensitive = true

outputs.tf

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ output "db_instance_username" {
6161

6262
output "db_instance_password" {
6363
description = "The database password (this password may be old, because Terraform doesn't track it after initial creation)"
64-
value = local.master_password
64+
value = local.password
6565
sensitive = true
6666
}
6767

@@ -116,12 +116,6 @@ output "db_option_group_arn" {
116116
value = module.db_option_group.db_option_group_arn
117117
}
118118

119-
output "db_master_password" {
120-
description = "The master password"
121-
value = module.db_instance.db_instance_master_password
122-
sensitive = true
123-
}
124-
125119
################################################################################
126120
# CloudWatch Log Group
127121
################################################################################

0 commit comments

Comments
 (0)