|
| 1 | +# RDS Postgres Admin Login |
| 2 | + |
| 3 | +Creates a login to an RDS Postgres instance and automatically rotates the |
| 4 | +password. |
| 5 | + |
| 6 | +An active, admin username and password must be provided in an existing secret. |
| 7 | +This admin user will be used to create and rotate credentials. |
| 8 | + |
| 9 | +During rotation, the secret will toggle between primary and alternate usernames |
| 10 | +to avoid the scenario where the password is changed but hasn't been propagated |
| 11 | +to all users yet. This means that each password will remain active for two |
| 12 | +rotations. |
| 13 | + |
| 14 | +Example: |
| 15 | + |
| 16 | +``` |
| 17 | +module "rds_readonly_password" { |
| 18 | + source = "git@github.com:thoughtbot/flightdeck-addons.git//aws/rds-postgres-login?ref=main" |
| 19 | +
|
| 20 | + admin_login_kms_key_id = module.rds_admin_password.kms_key_arn |
| 21 | + admin_login_secret_arn = module.rds_admin_password.secret_arn |
| 22 | + database = module.database.primary |
| 23 | + subnet_ids = module.network_data.private_subnet_ids |
| 24 | + username = "readonly" |
| 25 | + vpc_id = module.network_data.vpc_id |
| 26 | +
|
| 27 | + grants = [ |
| 28 | + "GRANT USAGE ON SCHEMA public TO %s", |
| 29 | + "GRANT SELECT ON ALL TABLES IN SCHEMA public TO %s" |
| 30 | + ] |
| 31 | +} |
| 32 | +
|
| 33 | +module "rds_admin_password" { |
| 34 | + source = "git@github.com:thoughtbot/flightdeck-addons.git//aws/rds-postgres-admin-login?ref=main" |
| 35 | +
|
| 36 | + database = module.database.primary |
| 37 | + initial_password = module.database.initial_password |
| 38 | + subnet_ids = module.network_data.private_subnet_ids |
| 39 | + username = module.database.admin_username |
| 40 | + vpc_id = module.network_data.vpc_id |
| 41 | +} |
| 42 | +``` |
| 43 | + |
| 44 | +<!-- BEGIN_TF_DOCS --> |
| 45 | +## Requirements |
| 46 | + |
| 47 | +| Name | Version | |
| 48 | +|------|---------| |
| 49 | +| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.14.0 | |
| 50 | +| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 4.0 | |
| 51 | + |
| 52 | +## Providers |
| 53 | + |
| 54 | +| Name | Version | |
| 55 | +|------|---------| |
| 56 | +| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.26.0 | |
| 57 | + |
| 58 | +## Modules |
| 59 | + |
| 60 | +| Name | Source | Version | |
| 61 | +|------|--------|---------| |
| 62 | +| <a name="module_rotation"></a> [rotation](#module\_rotation) | github.com/thoughtbot/terraform-aws-secrets//secret-rotation-function | v0.4.0 | |
| 63 | +| <a name="module_secret"></a> [secret](#module\_secret) | github.com/thoughtbot/terraform-aws-secrets//secret | v0.4.0 | |
| 64 | + |
| 65 | +## Resources |
| 66 | + |
| 67 | +| Name | Type | |
| 68 | +|------|------| |
| 69 | +| [aws_iam_policy.access_admin_login](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource | |
| 70 | +| [aws_iam_role_policy_attachment.access_admin_login](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource | |
| 71 | +| [aws_security_group.function](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) | resource | |
| 72 | +| [aws_security_group_rule.function_egress](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource | |
| 73 | +| [aws_iam_policy_document.access_admin_login](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | |
| 74 | +| [aws_kms_key.admin_login](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/kms_key) | data source | |
| 75 | + |
| 76 | +## Inputs |
| 77 | + |
| 78 | +| Name | Description | Type | Default | Required | |
| 79 | +|------|-------------|------|---------|:--------:| |
| 80 | +| <a name="input_admin_login_kms_key_id"></a> [admin\_login\_kms\_key\_id](#input\_admin\_login\_kms\_key\_id) | ARN of the KMS key used to encrypt the admin login | `string` | n/a | yes | |
| 81 | +| <a name="input_admin_login_secret_arn"></a> [admin\_login\_secret\_arn](#input\_admin\_login\_secret\_arn) | ARN of a SecretsManager secret containing admin login | `string` | `null` | no | |
| 82 | +| <a name="input_admin_principals"></a> [admin\_principals](#input\_admin\_principals) | Principals allowed to peform admin actions (default: current account) | `list(string)` | `null` | no | |
| 83 | +| <a name="input_alternate_username"></a> [alternate\_username](#input\_alternate\_username) | Username for the alternate login used during rotation | `string` | `null` | no | |
| 84 | +| <a name="input_database"></a> [database](#input\_database) | The database instance for which a login will be managed | <pre>object({<br> address = string<br> arn = string<br> engine = string<br> identifier = string<br> name = string<br> port = number<br> })</pre> | n/a | yes | |
| 85 | +| <a name="input_grants"></a> [grants](#input\_grants) | List of GRANT statements for this user | `list(string)` | n/a | yes | |
| 86 | +| <a name="input_read_principals"></a> [read\_principals](#input\_read\_principals) | Principals allowed to read the secret (default: current account) | `list(string)` | `null` | no | |
| 87 | +| <a name="input_secret_name"></a> [secret\_name](#input\_secret\_name) | Override the name for this secret | `string` | `null` | no | |
| 88 | +| <a name="input_subnet_ids"></a> [subnet\_ids](#input\_subnet\_ids) | Subnets in which the rotation function should run | `list(string)` | n/a | yes | |
| 89 | +| <a name="input_tags"></a> [tags](#input\_tags) | Tags to be applied to created resources | `map(string)` | `{}` | no | |
| 90 | +| <a name="input_trust_tags"></a> [trust\_tags](#input\_trust\_tags) | Tags required on principals accessing the secret | `map(string)` | `{}` | no | |
| 91 | +| <a name="input_username"></a> [username](#input\_username) | The username for which a login will be managed | `string` | n/a | yes | |
| 92 | +| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | VPC in which the rotation function should run | `string` | n/a | yes | |
| 93 | + |
| 94 | +## Outputs |
| 95 | + |
| 96 | +| Name | Description | |
| 97 | +|------|-------------| |
| 98 | +| <a name="output_policy_json"></a> [policy\_json](#output\_policy\_json) | Required IAM policies | |
| 99 | +| <a name="output_secret_arn"></a> [secret\_arn](#output\_secret\_arn) | ARN of the secrets manager secret containing credentials | |
| 100 | +| <a name="output_secret_name"></a> [secret\_name](#output\_secret\_name) | Name of the secrets manager secret containing credentials | |
| 101 | +<!-- END_TF_DOCS --> |
0 commit comments