From ff543170a5b2ba20b4769c15d0187fdd1e3cbba4 Mon Sep 17 00:00:00 2001
From: cloudpossebot <11232728+cloudpossebot@users.noreply.github.com>
Date: Wed, 7 Jul 2021 23:24:32 +0000
Subject: [PATCH] Auto Format
---
README.md | 13 +++++++++++++
docs/terraform.md | 13 +++++++++++++
main.tf | 4 ++--
3 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 9a59e79..1a775ed 100644
--- a/README.md
+++ b/README.md
@@ -221,6 +221,7 @@ Available targets:
| [terraform](#requirement\_terraform) | >= 0.13.0 |
| [aws](#requirement\_aws) | >= 2.0 |
| [null](#requirement\_null) | >= 2.0 |
+| [random](#requirement\_random) | >= 3.0 |
| [template](#requirement\_template) | >= 2.0 |
## Providers
@@ -228,6 +229,7 @@ Available targets:
| Name | Version |
|------|---------|
| [aws](#provider\_aws) | >= 2.0 |
+| [random](#provider\_random) | >= 3.0 |
## Modules
@@ -249,6 +251,10 @@ Available targets:
| [aws_security_group_rule.egress](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
| [aws_security_group_rule.ingress_cidr_blocks](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
| [aws_security_group_rule.ingress_security_groups](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
+| [aws_ssm_parameter.database_password](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssm_parameter) | resource |
+| [aws_ssm_parameter.database_user](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssm_parameter) | resource |
+| [random_password.database_password](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
+| [random_pet.database_user](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource |
## Inputs
@@ -291,6 +297,7 @@ Available targets:
| [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).
Set to `0` for unlimited length.
Set to `null` for default, which is `0`.
Does not affect `id_full`. | `number` | `null` | no |
| [instance\_class](#input\_instance\_class) | Class of RDS instance | `string` | n/a | yes |
| [iops](#input\_iops) | The amount of provisioned IOPS. Setting this implies a storage\_type of 'io1'. Default is 0 if rds storage type is not 'io1' | `number` | `0` | no |
+| [kms\_alias\_name\_ssm](#input\_kms\_alias\_name\_ssm) | KMS alias name for SSM | `string` | `"alias/aws/ssm"` | no |
| [kms\_key\_arn](#input\_kms\_key\_arn) | The ARN of the existing KMS key to encrypt storage | `string` | `""` | no |
| [label\_key\_case](#input\_label\_key\_case) | The letter case of label keys (`tag` names) (i.e. `name`, `namespace`, `environment`, `stage`, `attributes`) to use in `tags`.
Possible values: `lower`, `title`, `upper`.
Default value: `title`. | `string` | `null` | no |
| [label\_order](#input\_label\_order) | The naming order of the id output and Name tag.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 5 elements, but at least one must be present. | `list(string)` | `null` | no |
@@ -314,6 +321,10 @@ Available targets:
| [security\_group\_ids](#input\_security\_group\_ids) | The IDs of the security groups from which to allow `ingress` traffic to the DB instance | `list(string)` | `[]` | no |
| [skip\_final\_snapshot](#input\_skip\_final\_snapshot) | If true (default), no snapshot will be made before deleting DB | `bool` | `true` | no |
| [snapshot\_identifier](#input\_snapshot\_identifier) | Snapshot identifier e.g: rds:production-2019-06-26-06-05. If specified, the module create cluster from the snapshot | `string` | `null` | no |
+| [ssm\_enabled](#input\_ssm\_enabled) | If `true` create SSM keys for the database user and password. | `bool` | `false` | no |
+| [ssm\_key\_password](#input\_ssm\_key\_password) | The SSM key to save the password. See `var.ssm_path_format`. | `string` | `"admin/db_password"` | no |
+| [ssm\_key\_user](#input\_ssm\_key\_user) | The SSM key to save the user. See `var.ssm_path_format`. | `string` | `"admin/db_user"` | no |
+| [ssm\_path\_format](#input\_ssm\_path\_format) | SSM path prefix. The first value will use the `var.database_name` and then the appropriate ssm key like `var.ssm_key_user` | `string` | `"/rds/%v/%v"` | no |
| [stage](#input\_stage) | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
| [storage\_encrypted](#input\_storage\_encrypted) | (Optional) Specifies whether the DB instance is encrypted. The default is false if not specified | `bool` | `true` | no |
| [storage\_type](#input\_storage\_type) | One of 'standard' (magnetic), 'gp2' (general purpose SSD), or 'io1' (provisioned IOPS SSD) | `string` | `"standard"` | no |
@@ -330,6 +341,8 @@ Available targets:
| [instance\_arn](#output\_instance\_arn) | ARN of the instance |
| [instance\_endpoint](#output\_instance\_endpoint) | DNS Endpoint of the instance |
| [instance\_id](#output\_instance\_id) | ID of the instance |
+| [instance\_password\_ssm\_key](#output\_instance\_password\_ssm\_key) | SSM key of RDS password for the master DB user |
+| [instance\_user](#output\_instance\_user) | RDS Username for the master DB user |
| [option\_group\_id](#output\_option\_group\_id) | ID of the Option Group |
| [parameter\_group\_id](#output\_parameter\_group\_id) | ID of the Parameter Group |
| [resource\_id](#output\_resource\_id) | The RDS Resource ID of this instance. |
diff --git a/docs/terraform.md b/docs/terraform.md
index 862a7b3..8e36c90 100644
--- a/docs/terraform.md
+++ b/docs/terraform.md
@@ -6,6 +6,7 @@
| [terraform](#requirement\_terraform) | >= 0.13.0 |
| [aws](#requirement\_aws) | >= 2.0 |
| [null](#requirement\_null) | >= 2.0 |
+| [random](#requirement\_random) | >= 3.0 |
| [template](#requirement\_template) | >= 2.0 |
## Providers
@@ -13,6 +14,7 @@
| Name | Version |
|------|---------|
| [aws](#provider\_aws) | >= 2.0 |
+| [random](#provider\_random) | >= 3.0 |
## Modules
@@ -34,6 +36,10 @@
| [aws_security_group_rule.egress](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
| [aws_security_group_rule.ingress_cidr_blocks](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
| [aws_security_group_rule.ingress_security_groups](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
+| [aws_ssm_parameter.database_password](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssm_parameter) | resource |
+| [aws_ssm_parameter.database_user](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssm_parameter) | resource |
+| [random_password.database_password](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
+| [random_pet.database_user](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource |
## Inputs
@@ -76,6 +82,7 @@
| [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).
Set to `0` for unlimited length.
Set to `null` for default, which is `0`.
Does not affect `id_full`. | `number` | `null` | no |
| [instance\_class](#input\_instance\_class) | Class of RDS instance | `string` | n/a | yes |
| [iops](#input\_iops) | The amount of provisioned IOPS. Setting this implies a storage\_type of 'io1'. Default is 0 if rds storage type is not 'io1' | `number` | `0` | no |
+| [kms\_alias\_name\_ssm](#input\_kms\_alias\_name\_ssm) | KMS alias name for SSM | `string` | `"alias/aws/ssm"` | no |
| [kms\_key\_arn](#input\_kms\_key\_arn) | The ARN of the existing KMS key to encrypt storage | `string` | `""` | no |
| [label\_key\_case](#input\_label\_key\_case) | The letter case of label keys (`tag` names) (i.e. `name`, `namespace`, `environment`, `stage`, `attributes`) to use in `tags`.
Possible values: `lower`, `title`, `upper`.
Default value: `title`. | `string` | `null` | no |
| [label\_order](#input\_label\_order) | The naming order of the id output and Name tag.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 5 elements, but at least one must be present. | `list(string)` | `null` | no |
@@ -99,6 +106,10 @@
| [security\_group\_ids](#input\_security\_group\_ids) | The IDs of the security groups from which to allow `ingress` traffic to the DB instance | `list(string)` | `[]` | no |
| [skip\_final\_snapshot](#input\_skip\_final\_snapshot) | If true (default), no snapshot will be made before deleting DB | `bool` | `true` | no |
| [snapshot\_identifier](#input\_snapshot\_identifier) | Snapshot identifier e.g: rds:production-2019-06-26-06-05. If specified, the module create cluster from the snapshot | `string` | `null` | no |
+| [ssm\_enabled](#input\_ssm\_enabled) | If `true` create SSM keys for the database user and password. | `bool` | `false` | no |
+| [ssm\_key\_password](#input\_ssm\_key\_password) | The SSM key to save the password. See `var.ssm_path_format`. | `string` | `"admin/db_password"` | no |
+| [ssm\_key\_user](#input\_ssm\_key\_user) | The SSM key to save the user. See `var.ssm_path_format`. | `string` | `"admin/db_user"` | no |
+| [ssm\_path\_format](#input\_ssm\_path\_format) | SSM path prefix. The first value will use the `var.database_name` and then the appropriate ssm key like `var.ssm_key_user` | `string` | `"/rds/%v/%v"` | no |
| [stage](#input\_stage) | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
| [storage\_encrypted](#input\_storage\_encrypted) | (Optional) Specifies whether the DB instance is encrypted. The default is false if not specified | `bool` | `true` | no |
| [storage\_type](#input\_storage\_type) | One of 'standard' (magnetic), 'gp2' (general purpose SSD), or 'io1' (provisioned IOPS SSD) | `string` | `"standard"` | no |
@@ -115,6 +126,8 @@
| [instance\_arn](#output\_instance\_arn) | ARN of the instance |
| [instance\_endpoint](#output\_instance\_endpoint) | DNS Endpoint of the instance |
| [instance\_id](#output\_instance\_id) | ID of the instance |
+| [instance\_password\_ssm\_key](#output\_instance\_password\_ssm\_key) | SSM key of RDS password for the master DB user |
+| [instance\_user](#output\_instance\_user) | RDS Username for the master DB user |
| [option\_group\_id](#output\_option\_group\_id) | ID of the Option Group |
| [parameter\_group\_id](#output\_parameter\_group\_id) | ID of the Parameter Group |
| [resource\_id](#output\_resource\_id) | The RDS Resource ID of this instance. |
diff --git a/main.tf b/main.tf
index 7fa48c9..1fa8585 100644
--- a/main.tf
+++ b/main.tf
@@ -19,7 +19,7 @@ locals {
)
availability_zone = var.multi_az ? null : var.availability_zone
-
+
create_user = local.enabled && length(var.database_user) == 0
create_password = local.enabled && length(var.database_password) == 0
@@ -80,7 +80,7 @@ resource "aws_ssm_parameter" "database_password" {
key_id = var.kms_alias_name_ssm
overwrite = true
}
-
+
resource "aws_db_instance" "default" {
count = local.enabled ? 1 : 0