Skip to content

Commit c9a7462

Browse files
committed
Add manage_master_user_password and master_user_secret_kms_key_id
1 parent 51ededc commit c9a7462

File tree

6 files changed

+42
-4
lines changed

6 files changed

+42
-4
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ Users have the ability to:
285285
| <a name="input_license_model"></a> [license\_model](#input\_license\_model) | License model information for this DB instance. Optional, but required for some DB engines, i.e. Oracle SE1 | `string` | `null` | no |
286286
| <a name="input_maintenance_window"></a> [maintenance\_window](#input\_maintenance\_window) | The window to perform maintenance in. Syntax: 'ddd:hh24:mi-ddd:hh24:mi'. Eg: 'Mon:00:00-Mon:03:00' | `string` | `null` | no |
287287
| <a name="input_major_engine_version"></a> [major\_engine\_version](#input\_major\_engine\_version) | Specifies the major version of the engine that this option group should be associated with | `string` | `null` | no |
288+
| <a name="input_manage_master_user_password"></a> [manage\_master\_user\_password](#input\_manage\_master\_user\_password) | Set to true to allow RDS to manage the master user password in Secrets Manager. Cannot be set if password is provided | `bool` | `false` | no |
289+
| <a name="input_master_user_secret_kms_key_id"></a> [master\_user\_secret\_kms\_key\_id](#input\_master\_user\_secret\_kms\_key\_id) | The key ARN, key ID, alias ARN or alias name for the KMS key to ecnrypt the master user password secret in Secrets Manager.<br> If not specified, the default KMS key for your Amazon Web Services account is used. | `string` | `null` | no |
288290
| <a name="input_max_allocated_storage"></a> [max\_allocated\_storage](#input\_max\_allocated\_storage) | Specifies the value for Storage Autoscaling | `number` | `0` | no |
289291
| <a name="input_monitoring_interval"></a> [monitoring\_interval](#input\_monitoring\_interval) | The interval, in seconds, between points when Enhanced Monitoring metrics are collected for the DB instance. To disable collecting Enhanced Monitoring metrics, specify 0. The default is 0. Valid Values: 0, 1, 5, 10, 15, 30, 60 | `number` | `0` | no |
290292
| <a name="input_monitoring_role_arn"></a> [monitoring\_role\_arn](#input\_monitoring\_role\_arn) | The ARN for the IAM role that permits RDS to send enhanced monitoring metrics to CloudWatch Logs. Must be specified if monitoring\_interval is non-zero | `string` | `null` | no |
@@ -304,7 +306,7 @@ Users have the ability to:
304306
| <a name="input_parameter_group_name"></a> [parameter\_group\_name](#input\_parameter\_group\_name) | Name of the DB parameter group to associate or create | `string` | `null` | no |
305307
| <a name="input_parameter_group_use_name_prefix"></a> [parameter\_group\_use\_name\_prefix](#input\_parameter\_group\_use\_name\_prefix) | Determines whether to use `parameter_group_name` as is or create a unique name beginning with the `parameter_group_name` as the prefix | `bool` | `true` | no |
306308
| <a name="input_parameters"></a> [parameters](#input\_parameters) | A list of DB parameters (map) to apply | `list(map(string))` | `[]` | no |
307-
| <a name="input_password"></a> [password](#input\_password) | Password for the master DB user. Note that this may show up in logs, and it will be stored in the state file.<br> The password provided will not be used if the variable create\_random\_password is set to true. | `string` | `null` | no |
309+
| <a name="input_password"></a> [password](#input\_password) | Password for the master DB user. Note that this may show up in logs, and it will be stored in the state file.<br> The password provided will not be used if the variable create\_random\_password or manage\_master\_user\_password are set to true. | `string` | `null` | no |
308310
| <a name="input_performance_insights_enabled"></a> [performance\_insights\_enabled](#input\_performance\_insights\_enabled) | Specifies whether Performance Insights are enabled | `bool` | `false` | no |
309311
| <a name="input_performance_insights_kms_key_id"></a> [performance\_insights\_kms\_key\_id](#input\_performance\_insights\_kms\_key\_id) | The ARN for the KMS key to encrypt Performance Insights data | `string` | `null` | no |
310312
| <a name="input_performance_insights_retention_period"></a> [performance\_insights\_retention\_period](#input\_performance\_insights\_retention\_period) | The amount of time in days to retain Performance Insights data. Valid values are `7`, `731` (2 years) or a multiple of `31` | `number` | `7` | no |

main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,14 @@ module "db_instance" {
8484

8585
db_name = var.db_name
8686
username = var.username
87-
password = local.password
87+
password = !var.manage_master_user_password ? local.password : null
8888
port = var.port
8989
domain = var.domain
9090
domain_iam_role_name = var.domain_iam_role_name
9191
iam_database_authentication_enabled = var.iam_database_authentication_enabled
9292
custom_iam_instance_profile = var.custom_iam_instance_profile
93+
manage_master_user_password = var.manage_master_user_password
94+
master_user_secret_kms_key_id = var.master_user_secret_kms_key_id
9395

9496
vpc_security_group_ids = var.vpc_security_group_ids
9597
db_subnet_group_name = local.db_subnet_group_name

modules/db_instance/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ No modules.
7070
| <a name="input_kms_key_id"></a> [kms\_key\_id](#input\_kms\_key\_id) | The ARN for the KMS encryption key. If creating an encrypted replica, set this to the destination KMS ARN. If storage\_encrypted is set to true and kms\_key\_id is not specified the default KMS key created in your account will be used | `string` | `null` | no |
7171
| <a name="input_license_model"></a> [license\_model](#input\_license\_model) | License model information for this DB instance. Optional, but required for some DB engines, i.e. Oracle SE1 | `string` | `null` | no |
7272
| <a name="input_maintenance_window"></a> [maintenance\_window](#input\_maintenance\_window) | The window to perform maintenance in. Syntax: 'ddd:hh24:mi-ddd:hh24:mi'. Eg: 'Mon:00:00-Mon:03:00' | `string` | `null` | no |
73+
| <a name="input_manage_master_user_password"></a> [manage\_master\_user\_password](#input\_manage\_master\_user\_password) | Set to true to allow RDS to manage the master user password in Secrets Manager. Cannot be set if password is provided | `bool` | `false` | no |
74+
| <a name="input_master_user_secret_kms_key_id"></a> [master\_user\_secret\_kms\_key\_id](#input\_master\_user\_secret\_kms\_key\_id) | The key ARN, key ID, alias ARN or alias name for the KMS key to ecnrypt the master user password secret in Secrets Manager.<br> If not specified, the default KMS key for your Amazon Web Services account is used. | `string` | `null` | no |
7375
| <a name="input_max_allocated_storage"></a> [max\_allocated\_storage](#input\_max\_allocated\_storage) | Specifies the value for Storage Autoscaling | `number` | `0` | no |
7476
| <a name="input_monitoring_interval"></a> [monitoring\_interval](#input\_monitoring\_interval) | The interval, in seconds, between points when Enhanced Monitoring metrics are collected for the DB instance. To disable collecting Enhanced Monitoring metrics, specify 0. The default is 0. Valid Values: 0, 1, 5, 10, 15, 30, 60. | `number` | `0` | no |
7577
| <a name="input_monitoring_role_arn"></a> [monitoring\_role\_arn](#input\_monitoring\_role\_arn) | The ARN for the IAM role that permits RDS to send enhanced monitoring metrics to CloudWatch Logs. Must be specified if monitoring\_interval is non-zero. | `string` | `null` | no |

modules/db_instance/main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ locals {
1111

1212
# Replicas will use source metadata
1313
username = var.replicate_source_db != null ? null : var.username
14-
password = var.replicate_source_db != null ? null : var.password
14+
password = var.replicate_source_db != null || var.manage_master_user_password ? null : var.password
1515
engine = var.replicate_source_db != null ? null : var.engine
1616
}
1717

@@ -51,6 +51,8 @@ resource "aws_db_instance" "this" {
5151
domain_iam_role_name = var.domain_iam_role_name
5252
iam_database_authentication_enabled = var.iam_database_authentication_enabled
5353
custom_iam_instance_profile = var.custom_iam_instance_profile
54+
manage_master_user_password = var.manage_master_user_password
55+
master_user_secret_kms_key_id = var.master_user_secret_kms_key_id
5456

5557
vpc_security_group_ids = var.vpc_security_group_ids
5658
db_subnet_group_name = var.db_subnet_group_name

modules/db_instance/variables.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ variable "password" {
122122
default = null
123123
}
124124

125+
variable "manage_master_user_password" {
126+
description = "Set to true to allow RDS to manage the master user password in Secrets Manager. Cannot be set if password is provided"
127+
type = bool
128+
default = false
129+
}
130+
131+
variable "master_user_secret_kms_key_id" {
132+
description = <<EOF
133+
The key ARN, key ID, alias ARN or alias name for the KMS key to ecnrypt the master user password secret in Secrets Manager.
134+
If not specified, the default KMS key for your Amazon Web Services account is used.
135+
EOF
136+
type = string
137+
default = null
138+
}
139+
125140
variable "port" {
126141
description = "The port on which the DB accepts connections"
127142
type = string

variables.tf

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,28 @@ variable "username" {
138138
variable "password" {
139139
description = <<EOF
140140
Password for the master DB user. Note that this may show up in logs, and it will be stored in the state file.
141-
The password provided will not be used if the variable create_random_password is set to true.
141+
The password provided will not be used if the variable create_random_password or manage_master_user_password are set to true.
142142
EOF
143143
type = string
144144
default = null
145145
sensitive = true
146146
}
147147

148+
variable "manage_master_user_password" {
149+
description = "Set to true to allow RDS to manage the master user password in Secrets Manager. Cannot be set if password is provided"
150+
type = bool
151+
default = false
152+
}
153+
154+
variable "master_user_secret_kms_key_id" {
155+
description = <<EOF
156+
The key ARN, key ID, alias ARN or alias name for the KMS key to ecnrypt the master user password secret in Secrets Manager.
157+
If not specified, the default KMS key for your Amazon Web Services account is used.
158+
EOF
159+
type = string
160+
default = null
161+
}
162+
148163
variable "port" {
149164
description = "The port on which the DB accepts connections"
150165
type = string

0 commit comments

Comments
 (0)