Skip to content

Commit ec4855c

Browse files
Merge pull request #5 from yuvraj-squareops1/main
added replica option and fixes for storage autoscaling
2 parents 9aa03f2 + 6ebc192 commit ec4855c

File tree

13 files changed

+549
-50
lines changed

13 files changed

+549
-50
lines changed

README.md

+41-20
Large diffs are not rendered by default.
+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
## PostgreSQL with Replica Example
2+
![squareops_avatar]
3+
4+
[squareops_avatar]: https://squareops.com/wp-content/uploads/2022/12/squareops-logo.png
5+
6+
### [SquareOps Technologies](https://squareops.com/) Your DevOps Partner for Accelerating cloud journey.
7+
<br>
8+
9+
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.
10+
11+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
12+
## Requirements
13+
14+
| Name | Version |
15+
|------|---------|
16+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
17+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.43.0 |
18+
19+
## Providers
20+
21+
| Name | Version |
22+
|------|---------|
23+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.43.0 |
24+
25+
## Modules
26+
27+
| Name | Source | Version |
28+
|------|--------|---------|
29+
| <a name="module_kms"></a> [kms](#module\_kms) | terraform-aws-modules/kms/aws | n/a |
30+
| <a name="module_rds-pg"></a> [rds-pg](#module\_rds-pg) | squareops/rds-postgresql/aws | n/a |
31+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | squareops/vpc/aws | n/a |
32+
33+
## Resources
34+
35+
| Name | Type |
36+
|------|------|
37+
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
38+
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
39+
40+
## Inputs
41+
42+
No inputs.
43+
44+
## Outputs
45+
46+
| Name | Description |
47+
|------|-------------|
48+
| <a name="output_instance_endpoint"></a> [instance\_endpoint](#output\_instance\_endpoint) | Connection endpoint of the RDS instance. |
49+
| <a name="output_instance_name"></a> [instance\_name](#output\_instance\_name) | Name of the database instance. |
50+
| <a name="output_instance_password"></a> [instance\_password](#output\_instance\_password) | Password for accessing the database (Note: Terraform does not track this password after initial creation). |
51+
| <a name="output_instance_username"></a> [instance\_username](#output\_instance\_username) | Master username for accessing the database. |
52+
| <a name="output_master_user_secret_arn"></a> [master\_user\_secret\_arn](#output\_master\_user\_secret\_arn) | n/a |
53+
| <a name="output_parameter_group_id"></a> [parameter\_group\_id](#output\_parameter\_group\_id) | ID of the parameter group associated with the RDS instance. |
54+
| <a name="output_rds-mysql_replica_db_instance_name"></a> [rds-mysql\_replica\_db\_instance\_name](#output\_rds-mysql\_replica\_db\_instance\_name) | The name of the database instance |
55+
| <a name="output_replica_instances_endpoints"></a> [replica\_instances\_endpoints](#output\_replica\_instances\_endpoints) | Connection endpoint of the RDS replica instances. |
56+
| <a name="output_security_group"></a> [security\_group](#output\_security\_group) | ID of the security group associated with the RDS instance. |
57+
| <a name="output_subnet_group_id"></a> [subnet\_group\_id](#output\_subnet\_group\_id) | ID of the subnet group associated with the RDS instance. |
58+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
locals {
2+
region = "us-east-2"
3+
name = "postgresql"
4+
family = "postgres15"
5+
vpc_cidr = "10.20.0.0/16"
6+
environment = "prod"
7+
storage_type = "gp3"
8+
engine_version = "15.2"
9+
instance_class = "db.m5d.large"
10+
replica_enable = true
11+
replica_count = 1
12+
current_identity = data.aws_caller_identity.current.arn
13+
allowed_security_groups = ["sg-0a680afd35"]
14+
additional_tags = {
15+
Owner = "Organization_Name"
16+
Expires = "Never"
17+
Department = "Engineering"
18+
}
19+
}
20+
21+
data "aws_caller_identity" "current" {}
22+
data "aws_region" "current" {}
23+
24+
module "kms" {
25+
source = "terraform-aws-modules/kms/aws"
26+
27+
deletion_window_in_days = 7
28+
description = "Complete key example showing various configurations available"
29+
enable_key_rotation = true
30+
is_enabled = true
31+
key_usage = "ENCRYPT_DECRYPT"
32+
multi_region = true
33+
34+
# Policy
35+
enable_default_policy = true
36+
key_owners = [local.current_identity]
37+
key_administrators = [local.current_identity]
38+
key_users = [local.current_identity]
39+
key_service_users = [local.current_identity]
40+
key_statements = [
41+
{
42+
sid = "CloudWatchLogs"
43+
actions = [
44+
"kms:Encrypt*",
45+
"kms:Decrypt*",
46+
"kms:ReEncrypt*",
47+
"kms:GenerateDataKey*",
48+
"kms:Describe*"
49+
]
50+
resources = ["*"]
51+
52+
principals = [
53+
{
54+
type = "AWS"
55+
identifiers = ["*"]
56+
}
57+
]
58+
}
59+
]
60+
61+
# Aliases
62+
aliases = ["${local.name}"]
63+
64+
tags = local.additional_tags
65+
}
66+
67+
68+
module "vpc" {
69+
source = "squareops/vpc/aws"
70+
name = local.name
71+
vpc_cidr = local.vpc_cidr
72+
environment = local.environment
73+
availability_zones = ["us-east-2a", "us-east-2b"]
74+
public_subnet_enabled = true
75+
auto_assign_public_ip = true
76+
intra_subnet_enabled = false
77+
private_subnet_enabled = true
78+
one_nat_gateway_per_az = false
79+
database_subnet_enabled = true
80+
}
81+
82+
module "rds-pg" {
83+
source = "squareops/rds-postgresql/aws"
84+
name = local.name
85+
db_name = "postgres"
86+
family = local.family
87+
multi_az = "true"
88+
vpc_id = module.vpc.vpc_id
89+
subnet_ids = module.vpc.database_subnets ## db subnets
90+
environment = local.environment
91+
replica_enable = local.replica_enable
92+
replica_count = local.replica_count
93+
kms_key_arn = module.kms.key_arn
94+
storage_type = local.storage_type
95+
engine_version = local.engine_version
96+
instance_class = local.instance_class
97+
master_username = "pguser"
98+
allocated_storage = "20"
99+
max_allocated_storage = 120
100+
publicly_accessible = false
101+
skip_final_snapshot = true
102+
backup_window = "03:00-06:00"
103+
maintenance_window = "Mon:00:00-Mon:03:00"
104+
final_snapshot_identifier_prefix = "final"
105+
major_engine_version = local.engine_version
106+
deletion_protection = true
107+
cloudwatch_metric_alarms_enabled = true
108+
alarm_cpu_threshold_percent = 70
109+
disk_free_storage_space = "10000000" # in bytes
110+
slack_username = "Admin"
111+
slack_channel = "postgresql-notification"
112+
slack_webhook_url = "https://hooks/xxxxxxxx"
113+
}
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
output "instance_endpoint" {
2+
description = "Connection endpoint of the RDS instance."
3+
value = module.rds-pg.db_instance_endpoint
4+
}
5+
output "replica_instances_endpoints" {
6+
description = "Connection endpoint of the RDS replica instances."
7+
value = module.rds-pg.replica_db_instance_endpoint
8+
}
9+
10+
output "instance_name" {
11+
description = "Name of the database instance."
12+
value = module.rds-pg.db_instance_name
13+
}
14+
15+
output "rds-mysql_replica_db_instance_name" {
16+
description = "The name of the database instance"
17+
value = module.rds-pg.replica_db_instance_name
18+
}
19+
20+
output "instance_username" {
21+
description = "Master username for accessing the database."
22+
value = module.rds-pg.db_instance_username
23+
}
24+
25+
output "instance_password" {
26+
description = "Password for accessing the database (Note: Terraform does not track this password after initial creation)."
27+
value = module.rds-pg.db_instance_password
28+
sensitive = false
29+
}
30+
31+
output "security_group" {
32+
description = "ID of the security group associated with the RDS instance."
33+
value = module.rds-pg.rds_dedicated_security_group
34+
}
35+
36+
output "parameter_group_id" {
37+
description = "ID of the parameter group associated with the RDS instance."
38+
value = module.rds-pg.db_parameter_group_id
39+
}
40+
41+
output "subnet_group_id" {
42+
description = "ID of the subnet group associated with the RDS instance."
43+
value = module.rds-pg.db_subnet_group_id
44+
}
45+
46+
output "master_user_secret_arn" {
47+
value = module.rds-pg.master_credential_secret_arn
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
provider "aws" {
2+
region = local.region
3+
default_tags {
4+
tags = local.additional_tags
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
required_providers {
4+
aws = {
5+
source = "hashicorp/aws"
6+
version = ">= 3.43.0"
7+
}
8+
}
9+
}

examples/complete/README.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,24 @@ This example will be very useful for users who are new to a module and want to q
1818

1919
## Providers
2020

21-
No providers.
21+
| Name | Version |
22+
|------|---------|
23+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.43.0 |
2224

2325
## Modules
2426

2527
| Name | Source | Version |
2628
|------|--------|---------|
29+
| <a name="module_kms"></a> [kms](#module\_kms) | terraform-aws-modules/kms/aws | n/a |
2730
| <a name="module_rds-pg"></a> [rds-pg](#module\_rds-pg) | squareops/rds-postgresql/aws | n/a |
31+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | squareops/vpc/aws | n/a |
2832

2933
## Resources
3034

31-
No resources.
35+
| Name | Type |
36+
|------|------|
37+
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
38+
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
3239

3340
## Inputs
3441

@@ -42,7 +49,10 @@ No inputs.
4249
| <a name="output_instance_name"></a> [instance\_name](#output\_instance\_name) | Name of the database instance. |
4350
| <a name="output_instance_password"></a> [instance\_password](#output\_instance\_password) | Password for accessing the database (Note: Terraform does not track this password after initial creation). |
4451
| <a name="output_instance_username"></a> [instance\_username](#output\_instance\_username) | Master username for accessing the database. |
52+
| <a name="output_master_user_secret_arn"></a> [master\_user\_secret\_arn](#output\_master\_user\_secret\_arn) | n/a |
4553
| <a name="output_parameter_group_id"></a> [parameter\_group\_id](#output\_parameter\_group\_id) | ID of the parameter group associated with the RDS instance. |
54+
| <a name="output_rds-mysql_replica_db_instance_name"></a> [rds-mysql\_replica\_db\_instance\_name](#output\_rds-mysql\_replica\_db\_instance\_name) | The name of the database instance |
55+
| <a name="output_replica_instances_endpoints"></a> [replica\_instances\_endpoints](#output\_replica\_instances\_endpoints) | Connection endpoint of the RDS replica instances. |
4656
| <a name="output_security_group"></a> [security\_group](#output\_security\_group) | ID of the security group associated with the RDS instance. |
4757
| <a name="output_subnet_group_id"></a> [subnet\_group\_id](#output\_subnet\_group\_id) | ID of the subnet group associated with the RDS instance. |
4858
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

0 commit comments

Comments
 (0)