diff --git a/README.md b/README.md index c09662d..d5b91d7 100644 --- a/README.md +++ b/README.md @@ -5,43 +5,47 @@ ### [SquareOps Technologies](https://squareops.com/) Your DevOps Partner for Accelerating cloud journey.
-Terraform module which creates RDS resources on AWS. +This Terraform module provisions an Amazon RDS PostgreSQL database on AWS. Amazon RDS (Relational Database Service) is a managed database service that makes it easy to set up, operate, and scale a relational database in the cloud. This module focuses specifically on PostgreSQL database deployments. + +## Features + + 1. Creates an Amazon RDS PostgreSQL database with customizable configurations. + 2. Supports various PostgreSQL versions and allows for easy updates. + 3. Configurable database instance class, storage capacity, and other PostgreSQL-specific settings. + 4. Provides options for enabling multi-AZ deployment for enhanced availability and disaster recovery. + 5. Allows customization of backup retention period and automated backups. + 6. Supports encryption at rest using AWS Key Management Service (KMS) for enhanced security. + 7. Enables fine-grained control over network access through security groups and VPC settings. + 8. Offers customizable tags for resource categorization and management. ## Usage Examples ```hcl module "rds-pg" { - source = "gitlab.com/sq-ia/aws/rds-pg.git" - engine = "postgres" - engine_version = "13" - instance_class = "db.m5.large" - allocated_storage = "20" - storage_encrypted = true - kms_key_arn = "arn:aws:kms:us-east-2:222222222222:key/kms_key_arn" - publicly_accessible = false - replicate_source_db = null - db_name = "postgres" - master_username = "pguser" - port = "5432" - multi_az = "false" - subnet_ids = ["subnet-xyz83181b1c69skaf","subnet-xyzb80a737aeaskaf"] - skip_final_snapshot = false - final_snapshot_identifier_prefix = "final" - maintenance_window = "Mon:00:00-Mon:03:00" + source = "https://github.com/sq-ia/terraform-aws-rds-postgresql.git" + name = "skaf" + db_name = "postgres" + vpc_id = "vpc-047eb87de44acfb73" + multi_az = "true" + subnet_ids = ["subnet-b39cfc", "subnet-090b8d8"] + environment = "prod" + kms_key_arn = "arn:aws:kms:region:2222222222:key/f8c8d802-a34b" + engine_version = "15.2" + instance_class = "db.m5.large" + master_username = "pguser" + allocated_storage = "20" + publicly_accessible = false + skip_final_snapshot = true backup_window = "03:00-06:00" - backup_retention_period = 1 - apply_immediately = true - random_password_length = 10 - create_random_password = true - allowed_security_groups = ["sg-xyz72c1a5f35cskaf"] - allowed_cidr_blocks = [] - vpc_id = "vpc-xyzb5c1d1b2ecskaf" - family = "postgres13" - major_engine_version = "13" - deletion_protection = true + maintenance_window = "Mon:00:00-Mon:03:00" + allowed_security_groups = ["sg-013cb57dc3bc6f880"] + major_engine_version = "15.2" + deletion_protection = false + final_snapshot_identifier_prefix = "final" } ``` -Refer [examples](https://github.com/squareops/terraform-aws-rds-pg/tree/main/examples/complete) for more details. - +Refer [examples](https://github.com/sq-ia/terraform-aws-rds-postgresql/tree/main/example/complete) for more details. + + ## Requirements | Name | Version | @@ -75,82 +79,82 @@ Refer [examples](https://github.com/squareops/terraform-aws-rds-pg/tree/main/exa | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| [additional\_tags](#input\_additional\_tags) | Tags for resources | `map(string)` |
{
"automation": "true"
}
| no | -| [allocated\_storage](#input\_allocated\_storage) | Database storage capacity | `number` | `20` | no | -| [allowed\_cidr\_blocks](#input\_allowed\_cidr\_blocks) | A list of CIDR blocks which are allowed to access the database | `list(any)` | `[]` | no | -| [allowed\_security\_groups](#input\_allowed\_security\_groups) | A list of Security Group ID's to allow access to | `list(any)` | `[]` | no | -| [apply\_immediately](#input\_apply\_immediately) | Specifies whether any cluster modifications are applied immediately, or during the next maintenance window. | `bool` | `false` | no | -| [backup\_retention\_period](#input\_backup\_retention\_period) | The days to retain backups for | `number` | `null` | no | -| [backup\_window](#input\_backup\_window) | When to perform DB backups | `string` | `""` | no | -| [create\_random\_password](#input\_create\_random\_password) | Whether to create random password for RDS primary cluster | `bool` | `true` | no | -| [create\_security\_group](#input\_create\_security\_group) | create security group or not | `bool` | `true` | no | -| [db\_name](#input\_db\_name) | Name for an automatically created database on cluster creation | `string` | `""` | no | -| [deletion\_protection](#input\_deletion\_protection) | provide accidental deletion protection | `bool` | `true` | no | -| [enable\_ssl\_connection](#input\_enable\_ssl\_connection) | Whether or not to enable the ssl connection | `bool` | `false` | no | -| [engine](#input\_engine) | The name of the database engine to be used for this DB cluster. | `string` | `""` | no | -| [engine\_version](#input\_engine\_version) | The database engine version. Updating this argument results in an outage. | `string` | `""` | no | -| [environment](#input\_environment) | Select enviroment type: dev, demo, prod | `string` | `"demo"` | no | -| [family](#input\_family) | Version of mysql DB family being created | `string` | `""` | no | -| [final\_snapshot\_identifier\_prefix](#input\_final\_snapshot\_identifier\_prefix) | The name which is prefixed to the final snapshot on cluster destroy | `string` | `"final"` | no | -| [instance\_class](#input\_instance\_class) | Instance type | `string` | `"db.m5.large"` | no | -| [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 | -| [maintenance\_window](#input\_maintenance\_window) | When to perform DB maintenance | `string` | `""` | no | -| [major\_engine\_version](#input\_major\_engine\_version) | The database major engine version. Updating this argument results in an outage. | `string` | `""` | no | -| [master\_username](#input\_master\_username) | Create username for RDS primary cluster | `string` | `""` | no | -| [multi\_az](#input\_multi\_az) | enable multi AZ for disaster Recovery | `bool` | `false` | no | -| [port](#input\_port) | port for database | `number` | `3306` | no | -| [publicly\_accessible](#input\_publicly\_accessible) | Publicly accessible to the internet | `bool` | `false` | no | -| [random\_password\_length](#input\_random\_password\_length) | (Optional) Length of random password to create. (default: 10) | `number` | `10` | no | -| [rds\_instance\_name](#input\_rds\_instance\_name) | RDS instance name | `string` | `"abc"` | no | -| [region](#input\_region) | In which region DataBase cluster will create | `string` | `""` | no | -| [replicate\_source\_db](#input\_replicate\_source\_db) | Specifies that this resource is a Replicate database, and to use this value as the source database. This correlates to the identifier of another Amazon RDS Database to replicate. | `string` | `null` | no | -| [skip\_final\_snapshot](#input\_skip\_final\_snapshot) | Determines whether a final DB snapshot is created before the DB instance is deleted. If true is specified, no DBSnapshot is created. If false is specified, a DB snapshot is created before the DB instance is deleted, using the value from final\_snapshot\_identifier | `bool` | `true` | no | -| [snapshot\_identifier](#input\_snapshot\_identifier) | Specifies whether or not to create this database from a snapshot. This correlates to the snapshot ID you'd find in the RDS console, e.g: rds:production-2015-06-26-06-05. | `string` | `null` | no | -| [storage\_encrypted](#input\_storage\_encrypted) | Allow Database encryption or not | `bool` | `true` | no | -| [subnet\_ids](#input\_subnet\_ids) | List of subnet IDs used by database subnet group created | `list(any)` | `[]` | no | -| [vpc\_id](#input\_vpc\_id) | In which VPC do you want to deploy the RDS cluster | `string` | `""` | no | +| [additional\_tags](#input\_additional\_tags) | A map of additional tags to apply to the AWS resources | `map(string)` |
{
"automation": "true"
}
| no | +| [allocated\_storage](#input\_allocated\_storage) | The allocated storage capacity for the database in gibibytes (GiB) | `number` | `20` | no | +| [allowed\_cidr\_blocks](#input\_allowed\_cidr\_blocks) | A list of CIDR blocks that are allowed to access the database | `list(any)` | `[]` | no | +| [allowed\_security\_groups](#input\_allowed\_security\_groups) | A list of Security Group IDs to allow access to the database | `list(any)` | `[]` | no | +| [apply\_immediately](#input\_apply\_immediately) | Specifies whether any cluster modifications are applied immediately or during the next maintenance window | `bool` | `false` | no | +| [backup\_retention\_period](#input\_backup\_retention\_period) | The number of days to retain backups for | `number` | `5` | no | +| [backup\_window](#input\_backup\_window) | The preferred window for taking automated backups of the database | `string` | `""` | no | +| [create\_random\_password](#input\_create\_random\_password) | Whether to create a random password for the RDS primary cluster | `bool` | `true` | no | +| [create\_security\_group](#input\_create\_security\_group) | Whether to create a security group for the database | `bool` | `true` | no | +| [db\_name](#input\_db\_name) | The name of the automatically created database on cluster creation | `string` | `""` | no | +| [deletion\_protection](#input\_deletion\_protection) | Specifies whether accidental deletion protection is enabled | `bool` | `true` | no | +| [enable\_ssl\_connection](#input\_enable\_ssl\_connection) | Whether to enable SSL connection to the database | `bool` | `false` | no | +| [engine](#input\_engine) | The name of the database engine to be used for this DB cluster | `string` | `"postgres"` | no | +| [engine\_version](#input\_engine\_version) | The database engine version. Updating this argument results in an outage | `string` | `""` | no | +| [environment](#input\_environment) | Select enviroment type: dev, demo, prod | `string` | `""` | no | +| [family](#input\_family) | The version of the Postgresql DB family being created | `string` | `"postgres15"` | no | +| [final\_snapshot\_identifier\_prefix](#input\_final\_snapshot\_identifier\_prefix) | The prefix name for the final snapshot on cluster destroy | `string` | `"final"` | no | +| [instance\_class](#input\_instance\_class) | The instance type for the database | `string` | `"db.m5.large"` | no | +| [kms\_key\_arn](#input\_kms\_key\_arn) | The ARN for the KMS encryption key. Set this to the destination KMS ARN when creating an encrypted replica. 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 | +| [maintenance\_window](#input\_maintenance\_window) | The preferred window for performing database maintenance | `string` | `""` | no | +| [major\_engine\_version](#input\_major\_engine\_version) | The major engine version for the database. Updating this argument results in an outage | `string` | `""` | no | +| [master\_username](#input\_master\_username) | The username for the RDS primary cluster | `string` | `""` | no | +| [multi\_az](#input\_multi\_az) | Enable multi-AZ for disaster recovery | `bool` | `false` | no | +| [name](#input\_name) | The name of the RDS instance | `string` | `""` | no | +| [port](#input\_port) | The port number for the database | `number` | `5432` | no | +| [publicly\_accessible](#input\_publicly\_accessible) | Specifies whether the RDS instance is publicly accessible over the internet | `bool` | `false` | no | +| [random\_password\_length](#input\_random\_password\_length) | The length of the randomly generated password for the RDS primary cluster (default: 10) | `number` | `10` | no | +| [replicate\_source\_db](#input\_replicate\_source\_db) | Specifies that this resource is a replicate database, and uses the specified value as the source database identifier | `string` | `null` | no | +| [skip\_final\_snapshot](#input\_skip\_final\_snapshot) | Determines whether a final DB snapshot is created before the DB instance is deleted. If set to true, no DB snapshot is created. If set to false, a DB snapshot is created before the DB instance is deleted, using the value from final\_snapshot\_identifier | `bool` | `true` | no | +| [snapshot\_identifier](#input\_snapshot\_identifier) | Specifies whether to create the database from a snapshot. Use the snapshot ID found in the RDS console, e.g., rds:production-2015-06-26-06-05 | `string` | `null` | no | +| [storage\_encrypted](#input\_storage\_encrypted) | Specifies whether to enable database encryption | `bool` | `true` | no | +| [subnet\_ids](#input\_subnet\_ids) | A list of subnet IDs used by the database subnet group | `list(any)` | `[]` | no | +| [vpc\_id](#input\_vpc\_id) | The ID of the VPC where the RDS cluster will be deployed | `string` | `""` | no | ## Outputs | Name | Description | |------|-------------| -| [\_1\_db\_instance\_endpoint](#output\_\_1\_db\_instance\_endpoint) | The connection endpoint | -| [\_2\_db\_instance\_name](#output\_\_2\_db\_instance\_name) | The database name | -| [\_3\_db\_instance\_username](#output\_\_3\_db\_instance\_username) | The master username for the database | -| [\_4\_db\_instance\_password](#output\_\_4\_db\_instance\_password) | The database password (this password may be old, because Terraform doesn't track it after initial creation) | -| [\_5\_rds\_dedicated\_security\_group](#output\_\_5\_rds\_dedicated\_security\_group) | The security group ID of the cluster | -| [\_6\_db\_parameter\_group\_id](#output\_\_6\_db\_parameter\_group\_id) | The db parameter group id | -| [\_7\_db\_subnet\_group\_id](#output\_\_7\_db\_subnet\_group\_id) | The db subnet group name | - -## Contribution & Issue Reporting +| [db\_instance\_endpoint](#output\_db\_instance\_endpoint) | Connection endpoint of the RDS instance. | +| [db\_instance\_name](#output\_db\_instance\_name) | Name of the database instance | +| [db\_instance\_password](#output\_db\_instance\_password) | Password for accessing the database (Note: Terraform does not track this password after initial creation). | +| [db\_instance\_username](#output\_db\_instance\_username) | Master username for accessing the database. | +| [db\_parameter\_group\_id](#output\_db\_parameter\_group\_id) | ID of the parameter group associated with the RDS instance. | +| [db\_subnet\_group\_id](#output\_db\_subnet\_group\_id) | ID of the subnet group associated with the RDS instance. | +| [rds\_dedicated\_security\_group](#output\_rds\_dedicated\_security\_group) | ID of the security group associated with the RDS instance. | + + +## Contribute & Issue Report To report an issue with a project: - 1. Check the repository's [issue tracker](https://github.com/squareops/terraform-aws-postgres/issues) on GitHub - 2. Search to see if the issue has already been reported - 3. If you can't find an answer to your question in the documentation or issue tracker, you can ask a question by creating a new issue. Be sure to provide enough context and details so others can understand your problem. + 1. Check the repository's [issue tracker](https://github.com/sq-ia/terraform-aws-rds-postgresql/issues) on GitHub + 2. Search to check if the issue has already been reported + 3. If you can't find an answer to your question in the documentation or issue tracker, you can ask a question by creating a new issue. Make sure to provide enough context and details. ## License -Apache License, Version 2.0, January 2004 (http://www.apache.org/licenses/). +Apache License, Version 2.0, January 2004 (https://www.apache.org/licenses/LICENSE-2.0) ## Support Us -To support a GitHub project by liking it, you can follow these steps: +To support our GitHub project by liking it, you can follow these steps: - 1. Visit the repository: Navigate to the [GitHub repository](https://github.com/squareops/terraform-aws-postgres). + 1. Visit the repository: Navigate to the [GitHub repository](https://github.com/sq-ia/terraform-aws-rds-postgresql) 2. Click the "Star" button: On the repository page, you'll see a "Star" button in the upper right corner. Clicking on it will star the repository, indicating your support for the project. 3. Optionally, you can also leave a comment on the repository or open an issue to give feedback or suggest changes. -Starring a repository on GitHub is a simple way to show your support and appreciation for the project. It also helps to increase the visibility of the project and make it more discoverable to others. +Staring a repository on GitHub is a simple way to show your support and appreciation for the project. It also helps to increase the visibility of the project and make it more discoverable to others. ## Who we are We believe that the key to success in the digital age is the ability to deliver value quickly and reliably. That’s why we offer a comprehensive range of DevOps & Cloud services designed to help your organization optimize its systems & Processes for speed and agility. - 1. We are an AWS Advanced consulting partner which reflects our deep expertise in AWS Cloud and helping 100+ clients over the last 4 years. + 1. We are an AWS Advanced consulting partner which reflects our deep expertise in AWS Cloud and helping 100+ clients over the last 5 years. 2. Expertise in Kubernetes and overall container solution helps companies expedite their journey by 10X. 3. Infrastructure Automation is a key component to the success of our Clients and our Expertise helps deliver the same in the shortest time. 4. DevSecOps as a service to implement security within the overall DevOps process and helping companies deploy securely and at speed. @@ -159,5 +163,4 @@ We believe that the key to success in the digital age is the ability to deliver We provide [support](https://squareops.com/contact-us/) on all of our projects, no matter how small or large they may be. -You can find more information about our company on this [squareops.com](https://squareops.com/), follow us on [Linkdin](https://www.linkedin.com/company/squareops-technologies-pvt-ltd/), or fill out a [job application](https://squareops.com/careers/). If you have any questions or would like assistance with your cloud strategy and implementation, please don't hesitate to [contact us](https://squareops.com/contact-us/). - +To find more information about our company, visit [squareops.com](https://squareops.com/), follow us on [Linkedin](https://www.linkedin.com/company/squareops-technologies-pvt-ltd/), or fill out a [job application](https://squareops.com/careers/). If you have any questions or would like assistance with your cloud strategy and implementation, please don't hesitate to [contact us](https://squareops.com/contact-us/). \ No newline at end of file diff --git a/example/complete/README.md b/example/complete/README.md new file mode 100644 index 0000000..9a199fa --- /dev/null +++ b/example/complete/README.md @@ -0,0 +1,48 @@ +## PostgreSQL Example +![squareops_avatar] + +[squareops_avatar]: https://squareops.com/wp-content/uploads/2022/12/squareops-logo.png + +### [SquareOps Technologies](https://squareops.com/) Your DevOps Partner for Accelerating cloud journey. +
+ +This example will be very useful for users who are new to a module and want to quickly learn how to use it. By reviewing the examples, users can gain a better understanding of how the module works, what features it supports, and how to customize it to their specific needs. + + +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >= 1.0 | +| [aws](#requirement\_aws) | >= 3.43.0 | + +## Providers + +No providers. + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| [rds-pg](#module\_rds-pg) | git@github.com:sq-ia/terraform-aws-rds-postgresql.git | n/a | + +## Resources + +No resources. + +## Inputs + +No inputs. + +## Outputs + +| Name | Description | +|------|-------------| +| [instance\_endpoint](#output\_instance\_endpoint) | Connection endpoint of the RDS instance. | +| [instance\_name](#output\_instance\_name) | Name of the database instance. | +| [instance\_password](#output\_instance\_password) | Password for accessing the database (Note: Terraform does not track this password after initial creation). | +| [instance\_username](#output\_instance\_username) | Master username for accessing the database. | +| [parameter\_group\_id](#output\_parameter\_group\_id) | ID of the parameter group associated with the RDS instance. | +| [security\_group](#output\_security\_group) | ID of the security group associated with the RDS instance. | +| [subnet\_group\_id](#output\_subnet\_group\_id) | ID of the subnet group associated with the RDS instance. | + diff --git a/example/complete/main.tf b/example/complete/main.tf index e3604c3..20a0d8f 100644 --- a/example/complete/main.tf +++ b/example/complete/main.tf @@ -1,41 +1,36 @@ locals { - region = "us-east-2" - name = "skaf" - environment = "production" - engine_version = "13" - instance_class = "db.m5.large" + region = "us-east-2" + name = "skaf" + vpc_id = "vpc-00ae5511ee10671c1" + family = "postgres15" + subnet_ids = ["subnet-0d9a81939c6dd2a6e","subnet-0fd26f0d73dc9e73d"] + environment = "prod" + kms_key_arn = "arn:aws:kms:us-east-2:271251951598:key/73ff9e84-83e1-4097-b388-fe29623338a9" + engine_version = "15.2" + instance_class = "db.m5d.large" + allowed_security_groups = ["sg-0a680184e11eafd35"] } module "rds-pg" { - source = "../../" - engine = "postgres" - engine_version = local.engine_version - instance_class = local.instance_class - allocated_storage = "20" - storage_encrypted = true - kms_key_arn = "arn:aws:kms:us-east-2:271251951598:key/7fa600be-9c08-4502-a67a-ed7e8bc332cb" - publicly_accessible = false - replicate_source_db = null - db_name = "postgres" - master_username = "pguser" - port = "5432" - multi_az = "false" - subnet_ids = ["subnet-0dd83181b1c69eee8","subnet-095b80a737aea6d0f"] - skip_final_snapshot = false - final_snapshot_identifier_prefix = "final" - maintenance_window = "Mon:00:00-Mon:03:00" + source = "git@github.com:sq-ia/terraform-aws-rds-postgresql.git" + name = local.name + db_name = "postgres" + multi_az = "true" + family = local.family + vpc_id = local.vpc_id + subnet_ids = local.subnet_ids ## db subnets + environment = local.environment + kms_key_arn = local.kms_key_arn + engine_version = local.engine_version + instance_class = local.instance_class + master_username = "pguser" + allocated_storage = "20" + publicly_accessible = false + skip_final_snapshot = true backup_window = "03:00-06:00" - backup_retention_period = 1 - apply_immediately = true - random_password_length = 10 - create_random_password = true - allowed_security_groups = ["sg-03472c1a5f35c026d"] - allowed_cidr_blocks = [] - vpc_id = "vpc-06db5c1d1b2ec66f8" - family = "postgres13" - major_engine_version = "13" - deletion_protection = true + maintenance_window = "Mon:00:00-Mon:03:00" + final_snapshot_identifier_prefix = "final" + allowed_security_groups = local.allowed_security_groups + major_engine_version = local.engine_version + deletion_protection = false } - - - diff --git a/example/complete/output.tf b/example/complete/output.tf index c0fd125..9ac5552 100644 --- a/example/complete/output.tf +++ b/example/complete/output.tf @@ -1,34 +1,34 @@ output "instance_endpoint" { - description = "The connection endpoint" + description = "Connection endpoint of the RDS instance." value = module.rds-pg.db_instance_endpoint } output "instance_name" { - description = "The database name" + description = "Name of the database instance." value = module.rds-pg.db_instance_name } output "instance_username" { - description = "The master username for the database" + description = "Master username for accessing the database." value = module.rds-pg.db_instance_username } output "instance_password" { - description = "The database password (this password may be old, because Terraform doesn't track it after initial creation)" + description = "Password for accessing the database (Note: Terraform does not track this password after initial creation)." value = module.rds-pg.db_instance_password } output "security_group" { - description = "The security group ID of the cluster" + description = "ID of the security group associated with the RDS instance." value = module.rds-pg.rds_dedicated_security_group } output "parameter_group_id" { - description = "The db parameter group id" + description = "ID of the parameter group associated with the RDS instance." value = module.rds-pg.db_parameter_group_id } output "subnet_group_id" { - description = "The db subnet group name" + description = "ID of the subnet group associated with the RDS instance." value = module.rds-pg.db_subnet_group_id -} \ No newline at end of file +} diff --git a/example/complete/provider.tf b/example/complete/provider.tf index 6181612..c291cce 100644 --- a/example/complete/provider.tf +++ b/example/complete/provider.tf @@ -1,3 +1,3 @@ provider "aws" { region = local.region -} \ No newline at end of file +} diff --git a/main.tf b/main.tf index af00687..4279db9 100644 --- a/main.tf +++ b/main.tf @@ -9,17 +9,17 @@ locals { } module "db" { - source = "terraform-aws-modules/rds/aws" - version = "~> 3.0" - identifier = format("%s-%s", var.environment, var.rds_instance_name) - engine = var.engine - engine_version = var.engine_version - instance_class = var.instance_class - allocated_storage = var.allocated_storage - storage_encrypted = var.storage_encrypted - kms_key_id = var.kms_key_arn - publicly_accessible = var.publicly_accessible - replicate_source_db = var.replicate_source_db + source = "terraform-aws-modules/rds/aws" + version = "~> 3.0" + identifier = format("%s-%s", var.environment, var.name) + engine = var.engine + engine_version = var.engine_version + instance_class = var.instance_class + allocated_storage = var.allocated_storage + storage_encrypted = var.storage_encrypted + kms_key_id = var.kms_key_arn + publicly_accessible = var.publicly_accessible + replicate_source_db = var.replicate_source_db name = var.db_name username = var.master_username port = var.port @@ -35,13 +35,12 @@ module "db" { apply_immediately = var.apply_immediately random_password_length = var.random_password_length create_random_password = var.create_random_password - monitoring_interval = "30" - monitoring_role_name = format("%s-%s-MyRDSMonitoringRole", var.rds_instance_name, var.environment) - create_monitoring_role = true - enabled_cloudwatch_logs_exports = ["postgresql"] - + monitoring_interval = "30" + monitoring_role_name = format("%s-%s-RDSPostgresql", var.name, var.environment) + create_monitoring_role = true + enabled_cloudwatch_logs_exports = ["postgresql"] tags = merge( - { "Name" = format("%s-%s", var.environment, var.rds_instance_name) }, + { "Name" = format("%s-%s", var.environment, var.name) }, local.tags, ) @@ -85,7 +84,7 @@ module "security_group_rds" { source = "terraform-aws-modules/security-group/aws" version = "~> 4" create = var.create_security_group - name = format("%s-%s-%s", var.environment, var.rds_instance_name, "rds-sg") + name = format("%s-%s-%s", var.environment, var.name, "rds-sg") description = "Complete PostgreSQL example security group" vpc_id = var.vpc_id @@ -99,7 +98,7 @@ module "security_group_rds" { ] tags = merge( - { "Name" = format("%s-%s-%s", var.environment, var.rds_instance_name, "rds-sg") }, + { "Name" = format("%s-%s-%s", var.environment, var.name, "rds-sg") }, local.tags, ) } diff --git a/outputs.tf b/outputs.tf index f16a409..c89887a 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,34 +1,34 @@ output "db_instance_endpoint" { - description = "The connection endpoint" + description = "Connection endpoint of the RDS instance." value = module.db.db_instance_endpoint } output "db_instance_name" { - description = "The database name" + description = "Name of the database instance" value = module.db.db_instance_name } output "db_instance_username" { - description = "The master username for the database" + description = "Master username for accessing the database." value = nonsensitive(module.db.db_instance_username) } output "db_instance_password" { - description = "The database password (this password may be old, because Terraform doesn't track it after initial creation)" + description = "Password for accessing the database (Note: Terraform does not track this password after initial creation)." value = nonsensitive(module.db.db_instance_password) } output "rds_dedicated_security_group" { - description = "The security group ID of the cluster" + description = "ID of the security group associated with the RDS instance." value = module.security_group_rds.security_group_id } output "db_parameter_group_id" { - description = "The db parameter group id" + description = "ID of the parameter group associated with the RDS instance." value = module.db.db_parameter_group_id } output "db_subnet_group_id" { - description = "The db subnet group name" + description = "ID of the subnet group associated with the RDS instance." value = module.db.db_subnet_group_id -} \ No newline at end of file +} diff --git a/variables.tf b/variables.tf index b1db0e3..405c68e 100644 --- a/variables.tf +++ b/variables.tf @@ -1,5 +1,5 @@ variable "additional_tags" { - description = "Tags for resources " + description = "A map of additional tags to apply to the AWS resources" type = map(string) default = { automation = "true" @@ -7,194 +7,193 @@ variable "additional_tags" { } variable "allocated_storage" { - description = "Database storage capacity" + description = "The allocated storage capacity for the database in gibibytes (GiB)" default = 20 type = number } variable "allowed_cidr_blocks" { - description = "A list of CIDR blocks which are allowed to access the database" + description = "A list of CIDR blocks that are allowed to access the database" default = [] type = list(any) } variable "allowed_security_groups" { - description = "A list of Security Group ID's to allow access to" + description = "A list of Security Group IDs to allow access to the database" default = [] type = list(any) } variable "apply_immediately" { - description = "Specifies whether any cluster modifications are applied immediately, or during the next maintenance window." + description = "Specifies whether any cluster modifications are applied immediately or during the next maintenance window" default = false type = bool } variable "backup_retention_period" { - description = "The days to retain backups for" + description = "The number of days to retain backups for" type = number - default = null + default = 5 } variable "backup_window" { - description = "When to perform DB backups" + description = "The preferred window for taking automated backups of the database" default = "" type = string } variable "create_random_password" { - description = "Whether to create random password for RDS primary cluster" + description = "Whether to create a random password for the RDS primary cluster" type = bool default = true } variable "create_security_group" { - description = "create security group or not" + description = "Whether to create a security group for the database" default = true type = bool } variable "deletion_protection" { - description = "provide accidental deletion protection" + description = "Specifies whether accidental deletion protection is enabled" default = true type = bool } variable "enable_ssl_connection" { - description = "Whether or not to enable the ssl connection" + description = "Whether to enable SSL connection to the database" default = false type = bool } variable "db_name" { - description = "Name for an automatically created database on cluster creation" + description = "The name of the automatically created database on cluster creation" default = "" type = string } - variable "engine" { - description = "The name of the database engine to be used for this DB cluster." - default = "" + description = "The name of the database engine to be used for this DB cluster" + default = "postgres" type = string } variable "engine_version" { - description = "The database engine version. Updating this argument results in an outage." + description = "The database engine version. Updating this argument results in an outage" default = "" type = string } variable "environment" { description = "Select enviroment type: dev, demo, prod" - default = "demo" + default = "" type = string } variable "family" { - description = "Version of mysql DB family being created" - default = "" + description = "The version of the Postgresql DB family being created" + default = "postgres15" type = string } variable "final_snapshot_identifier_prefix" { - description = "The name which is prefixed to the final snapshot on cluster destroy" + description = "The prefix name for the final snapshot on cluster destroy" type = string default = "final" } variable "kms_key_arn" { - description = "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" + description = "The ARN for the KMS encryption key. Set this to the destination KMS ARN when creating an encrypted replica. 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" type = string default = null } variable "instance_class" { - description = "Instance type" + description = "The instance type for the database" default = "db.m5.large" type = string } variable "major_engine_version" { - description = "The database major engine version. Updating this argument results in an outage." + description = "The major engine version for the database. Updating this argument results in an outage" default = "" type = string } variable "master_username" { - description = "Create username for RDS primary cluster" + description = "The username for the RDS primary cluster" default = "" type = string } variable "maintenance_window" { - description = "When to perform DB maintenance" + description = "The preferred window for performing database maintenance" default = "" type = string } variable "multi_az" { - description = "enable multi AZ for disaster Recovery" + description = "Enable multi-AZ for disaster recovery" default = false type = bool } -variable "rds_instance_name" { - description = "RDS instance name" - default = "abc" +variable "name" { + description = "The name of the RDS instance" + default = "" type = string } variable "port" { - description = "port for database" + description = "The port number for the database" type = number - default = 3306 + default = 5432 } variable "publicly_accessible" { - description = "Publicly accessible to the internet" + description = "Specifies whether the RDS instance is publicly accessible over the internet" default = false type = bool } variable "random_password_length" { - description = "(Optional) Length of random password to create. (default: 10)" + description = "The length of the randomly generated password for the RDS primary cluster (default: 10)" type = number default = 10 } variable "replicate_source_db" { - description = "Specifies that this resource is a Replicate database, and to use this value as the source database. This correlates to the identifier of another Amazon RDS Database to replicate." + description = "Specifies that this resource is a replicate database, and uses the specified value as the source database identifier" type = string default = null } variable "skip_final_snapshot" { - description = "Determines whether a final DB snapshot is created before the DB instance is deleted. If true is specified, no DBSnapshot is created. If false is specified, a DB snapshot is created before the DB instance is deleted, using the value from final_snapshot_identifier" + description = "Determines whether a final DB snapshot is created before the DB instance is deleted. If set to true, no DB snapshot is created. If set to false, a DB snapshot is created before the DB instance is deleted, using the value from final_snapshot_identifier" type = bool default = true } variable "snapshot_identifier" { - description = "Specifies whether or not to create this database from a snapshot. This correlates to the snapshot ID you'd find in the RDS console, e.g: rds:production-2015-06-26-06-05." + description = "Specifies whether to create the database from a snapshot. Use the snapshot ID found in the RDS console, e.g., rds:production-2015-06-26-06-05" type = string default = null } variable "storage_encrypted" { - description = "Allow Database encryption or not" + description = "Specifies whether to enable database encryption" default = true type = bool } variable "subnet_ids" { - description = "List of subnet IDs used by database subnet group created" + description = "A list of subnet IDs used by the database subnet group" default = [] type = list(any) } variable "vpc_id" { - description = "In which VPC do you want to deploy the RDS cluster" + description = "The ID of the VPC where the RDS cluster will be deployed" default = "" type = string -} \ No newline at end of file +}