From bb479cc6bf6c5029c42303c987ce8bd586b4a2a7 Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Sat, 13 Mar 2021 14:20:38 -0500 Subject: [PATCH] chore: update examples to to be self-sufficient and using latest practices/versions (#200) --- .gitignore | 3 + README.md | 41 ++--- examples/advanced/main.tf | 69 -------- examples/advanced/versions.tf | 7 - examples/autoscaling/README.md | 65 +++++++ examples/autoscaling/main.tf | 86 +++++++++ examples/{advanced => autoscaling}/outputs.tf | 0 .../{advanced => autoscaling}/variables.tf | 0 examples/autoscaling/versions.tf | 10 ++ examples/custom_instance_settings/README.md | 63 +++++++ examples/custom_instance_settings/main.tf | 110 +++++++----- examples/custom_instance_settings/versions.tf | 7 +- examples/mysql/README.md | 67 +++++++ examples/mysql/main.tf | 145 +++++++-------- examples/mysql/versions.tf | 13 +- examples/postgresql/README.md | 67 +++++++ examples/postgresql/main.tf | 117 ++++++------ examples/postgresql/versions.tf | 12 +- examples/s3_import/README.md | 4 +- examples/s3_import/backup.zip | Bin 3353214 -> 3350966 bytes examples/s3_import/main.tf | 50 +++--- examples/s3_import/versions.tf | 11 +- examples/serverless/README.md | 77 +++++++- examples/serverless/main.tf | 167 +++++++++++------- examples/serverless/outputs.tf | 111 +++++++++--- examples/serverless/versions.tf | 7 +- main.tf | 2 +- versions.tf | 13 +- 28 files changed, 912 insertions(+), 412 deletions(-) delete mode 100644 examples/advanced/main.tf delete mode 100644 examples/advanced/versions.tf create mode 100644 examples/autoscaling/README.md create mode 100644 examples/autoscaling/main.tf rename examples/{advanced => autoscaling}/outputs.tf (100%) rename examples/{advanced => autoscaling}/variables.tf (100%) create mode 100644 examples/autoscaling/versions.tf create mode 100644 examples/custom_instance_settings/README.md create mode 100644 examples/mysql/README.md create mode 100644 examples/postgresql/README.md diff --git a/.gitignore b/.gitignore index 397af32..317fbb4 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,6 @@ override.tf.json # Ignore CLI configuration files .terraformrc terraform.rc + +# S3 import example +backup diff --git a/README.md b/README.md index fd05f6e..4211b57 100644 --- a/README.md +++ b/README.md @@ -22,28 +22,28 @@ module "db" { source = "terraform-aws-modules/rds-aurora/aws" version = "~> 3.0" - name = "test-aurora-db-postgres96" + name = "test-aurora-db-postgres96" + engine = "aurora-postgresql" + engine_version = "11.9" + instance_type = "db.r5.large" - engine = "aurora-postgresql" - engine_version = "9.6.9" + vpc_id = "vpc-12345678" + subnets = ["subnet-12345678", "subnet-87654321"] - vpc_id = "vpc-12345678" - subnets = ["subnet-12345678", "subnet-87654321"] + replica_count = 1 + allowed_security_groups = ["sg-12345678"] + allowed_cidr_blocks = ["10.20.0.0/20"] - replica_count = 1 - allowed_security_groups = ["sg-12345678"] - allowed_cidr_blocks = ["10.20.0.0/20"] - instance_type = "db.r4.large" - storage_encrypted = true - apply_immediately = true - monitoring_interval = 10 + storage_encrypted = true + apply_immediately = true + monitoring_interval = 10 db_parameter_group_name = "default" db_cluster_parameter_group_name = "default" - enabled_cloudwatch_logs_exports = ["audit", "error", "general", "slowquery"] + enabled_cloudwatch_logs_exports = ["postgresql"] - tags = { + tags = { Environment = "dev" Terraform = "true" } @@ -67,11 +67,12 @@ module "db" { ## Examples -- [PostgreSQL](examples/postgresql): A simple example with VPC and PostgreSQL cluster. -- [MySQL](examples/mysql): A simple example with VPC and MySQL cluster. -- [Serverless](examples/serverless): Serverless PostgreSQL cluster. -- [Advanced](examples/advanced): A PostgreSQL cluster with enhanced monitoring and autoscaling enabled. -- [Custom Instance Settings](examples/custom_instance_settings): A PostgreSQL cluster with custom instance settings. +- [Autoscaling](examples/autoscaling): A PostgreSQL cluster with enhanced monitoring and autoscaling enabled +- [Custom Instance Settings](examples/custom_instance_settings): A PostgreSQL cluster with multiple replics configured using custom settings +- [MySQL](examples/mysql): A simple MySQL cluster +- [PostgreSQL](examples/postgresql): A simple PostgreSQL cluster +- [S3 Import](examples/s3_import): A MySQL cluster created from a Percona Xtrabackup stored in S3 +- [Serverless](examples/serverless): Serverless PostgreSQL and MySQL clusters ## Documentation @@ -82,7 +83,7 @@ Terraform documentation is generated automatically using [pre-commit hooks](http | Name | Version | |------|---------| -| terraform | >= 0.12.6 | +| terraform | >= 0.12.26 | | aws | >= 3.8 | | random | >= 2.2 | diff --git a/examples/advanced/main.tf b/examples/advanced/main.tf deleted file mode 100644 index 7d189f8..0000000 --- a/examples/advanced/main.tf +++ /dev/null @@ -1,69 +0,0 @@ -provider "aws" { - region = "us-east-1" -} - -###################################### -# Data sources to get VPC and subnets -###################################### -data "aws_vpc" "default" { - default = true -} - -data "aws_subnet_ids" "all" { - vpc_id = data.aws_vpc.default.id -} - -############# -# RDS Aurora -############# -module "aurora" { - source = "../../" - name = "aurora-example" - engine = "aurora-postgresql" - engine_version = "10.4" - subnets = data.aws_subnet_ids.all.ids - vpc_id = data.aws_vpc.default.id - replica_count = 1 - replica_scale_enabled = true - replica_scale_min = 1 - replica_scale_max = 5 - monitoring_interval = 60 - instance_type = "db.r4.large" - instance_type_replica = "db.t3.large" - apply_immediately = true - skip_final_snapshot = true - db_parameter_group_name = aws_db_parameter_group.aurora_db_postgres96_parameter_group.id - db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.aurora_cluster_postgres96_parameter_group.id - # enabled_cloudwatch_logs_exports = ["audit", "error", "general", "slowquery"] -} - -resource "aws_db_parameter_group" "aurora_db_postgres96_parameter_group" { - name = "test-aurora-db-postgres10-parameter-group" - family = "aurora-postgresql10" - description = "test-aurora-db-postgres10-parameter-group" -} - -resource "aws_rds_cluster_parameter_group" "aurora_cluster_postgres96_parameter_group" { - name = "test-aurora-postgres10-cluster-parameter-group" - family = "aurora-postgresql10" - description = "test-aurora-postgres10-cluster-parameter-group" -} - -############################ -# Example of security group -############################ -resource "aws_security_group" "app_servers" { - name = "app-servers" - description = "For application servers" - vpc_id = data.aws_vpc.default.id -} - -resource "aws_security_group_rule" "allow_access" { - type = "ingress" - from_port = module.aurora.this_rds_cluster_port - to_port = module.aurora.this_rds_cluster_port - protocol = "tcp" - source_security_group_id = aws_security_group.app_servers.id - security_group_id = module.aurora.this_security_group_id -} - diff --git a/examples/advanced/versions.tf b/examples/advanced/versions.tf deleted file mode 100644 index 23fd6a3..0000000 --- a/examples/advanced/versions.tf +++ /dev/null @@ -1,7 +0,0 @@ -terraform { - required_version = ">= 0.12.6" - - required_providers { - aws = ">= 3.8" - } -} diff --git a/examples/autoscaling/README.md b/examples/autoscaling/README.md new file mode 100644 index 0000000..02e47bf --- /dev/null +++ b/examples/autoscaling/README.md @@ -0,0 +1,65 @@ +# Autoscaling Example + +Configuration in this directory creates an Aurora cluster with autoscaling enabled. + +## Usage + +To run this example you need to execute: + +```bash +$ terraform init +$ terraform plan +$ terraform apply +``` + +Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources. + + +## Requirements + +| Name | Version | +|------|---------| +| terraform | >= 0.12.26 | +| aws | >= 3.8 | + +## Providers + +| Name | Version | +|------|---------| +| aws | >= 3.8 | + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| aurora | ../../ | | +| disabled_aurora | ../../ | | +| vpc | terraform-aws-modules/vpc/aws | ~> 2 | + +## Resources + +| Name | +|------| +| [aws_db_parameter_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_parameter_group) | +| [aws_rds_cluster_parameter_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster_parameter_group) | + +## Inputs + +No input. + +## Outputs + +| Name | Description | +|------|-------------| +| this\_rds\_cluster\_database\_name | Name for an automatically created database on cluster creation | +| this\_rds\_cluster\_endpoint | The cluster endpoint | +| this\_rds\_cluster\_id | The ID of the cluster | +| this\_rds\_cluster\_instance\_endpoints | A list of all cluster instance endpoints | +| this\_rds\_cluster\_instance\_ids | A list of all cluster instance ids | +| this\_rds\_cluster\_master\_password | The master password | +| this\_rds\_cluster\_master\_username | The master username | +| this\_rds\_cluster\_port | The port | +| this\_rds\_cluster\_reader\_endpoint | The cluster reader endpoint | +| this\_rds\_cluster\_resource\_id | The Resource ID of the cluster | +| this\_security\_group\_id | The security group ID of the cluster | + diff --git a/examples/autoscaling/main.tf b/examples/autoscaling/main.tf new file mode 100644 index 0000000..ce1a4de --- /dev/null +++ b/examples/autoscaling/main.tf @@ -0,0 +1,86 @@ +provider "aws" { + region = local.region +} + +locals { + name = "advanced" + region = "eu-west-1" + tags = { + Owner = "user" + Environment = "dev" + } +} + +################################################################################ +# Supporting Resources +################################################################################ + +module "vpc" { + source = "terraform-aws-modules/vpc/aws" + version = "~> 2" + + name = local.name + cidr = "10.99.0.0/18" + + azs = ["${local.region}a", "${local.region}b", "${local.region}c"] + public_subnets = ["10.99.0.0/24", "10.99.1.0/24", "10.99.2.0/24"] + private_subnets = ["10.99.3.0/24", "10.99.4.0/24", "10.99.5.0/24"] + database_subnets = ["10.99.7.0/24", "10.99.8.0/24", "10.99.9.0/24"] + + tags = local.tags +} + +################################################################################ +# RDS Aurora Module +################################################################################ + +module "aurora" { + source = "../../" + + name = local.name + engine = "aurora-postgresql" + engine_version = "11.9" + instance_type = "db.r5.large" + instance_type_replica = "db.t3.large" + + vpc_id = module.vpc.vpc_id + db_subnet_group_name = module.vpc.database_subnet_group_name + create_security_group = true + allowed_cidr_blocks = module.vpc.private_subnets_cidr_blocks + + replica_count = 1 + replica_scale_enabled = true + replica_scale_min = 1 + replica_scale_max = 5 + + monitoring_interval = 60 + + apply_immediately = true + skip_final_snapshot = true + + db_parameter_group_name = aws_db_parameter_group.example.id + db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.example.id + enabled_cloudwatch_logs_exports = ["postgresql"] + + tags = local.tags +} + +resource "aws_db_parameter_group" "example" { + name_prefix = "${local.name}-aurora-db-postgres11-parameter-group" + family = "aurora-postgresql11" + description = "${local.name}-aurora-db-postgres11-parameter-group" + tags = local.tags +} + +resource "aws_rds_cluster_parameter_group" "example" { + name_prefix = "${local.name}-aurora-postgres11-cluster-parameter-group" + family = "aurora-postgresql11" + description = "${local.name}-aurora-postgres11-cluster-parameter-group" + tags = local.tags +} + +module "disabled_aurora" { + source = "../../" + + create_cluster = false +} diff --git a/examples/advanced/outputs.tf b/examples/autoscaling/outputs.tf similarity index 100% rename from examples/advanced/outputs.tf rename to examples/autoscaling/outputs.tf diff --git a/examples/advanced/variables.tf b/examples/autoscaling/variables.tf similarity index 100% rename from examples/advanced/variables.tf rename to examples/autoscaling/variables.tf diff --git a/examples/autoscaling/versions.tf b/examples/autoscaling/versions.tf new file mode 100644 index 0000000..b5267ef --- /dev/null +++ b/examples/autoscaling/versions.tf @@ -0,0 +1,10 @@ +terraform { + required_version = ">= 0.12.26" + + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 3.8" + } + } +} diff --git a/examples/custom_instance_settings/README.md b/examples/custom_instance_settings/README.md new file mode 100644 index 0000000..7d83073 --- /dev/null +++ b/examples/custom_instance_settings/README.md @@ -0,0 +1,63 @@ +# Custom Instance Settings Example + +Configuration in this directory creates an Aurora cluster with multiple replicas configured through custom settings. + +## Usage + +To run this example you need to execute: + +```bash +$ terraform init +$ terraform plan +$ terraform apply +``` + +Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources. + + +## Requirements + +| Name | Version | +|------|---------| +| terraform | >= 0.12.26 | +| aws | >= 3.8 | + +## Providers + +| Name | Version | +|------|---------| +| aws | >= 3.8 | + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| aurora | ../../ | | +| vpc | terraform-aws-modules/vpc/aws | ~> 2 | + +## Resources + +| Name | +|------| +| [aws_db_parameter_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_parameter_group) | +| [aws_rds_cluster_parameter_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster_parameter_group) | + +## Inputs + +No input. + +## Outputs + +| Name | Description | +|------|-------------| +| this\_rds\_cluster\_database\_name | Name for an automatically created database on cluster creation | +| this\_rds\_cluster\_endpoint | The cluster endpoint | +| this\_rds\_cluster\_id | The ID of the cluster | +| this\_rds\_cluster\_instance\_endpoints | A list of all cluster instance endpoints | +| this\_rds\_cluster\_master\_password | The master password | +| this\_rds\_cluster\_master\_username | The master username | +| this\_rds\_cluster\_port | The port | +| this\_rds\_cluster\_reader\_endpoint | The cluster reader endpoint | +| this\_rds\_cluster\_resource\_id | The Resource ID of the cluster | +| this\_security\_group\_id | The security group ID of the cluster | + diff --git a/examples/custom_instance_settings/main.tf b/examples/custom_instance_settings/main.tf index bce831c..c515911 100644 --- a/examples/custom_instance_settings/main.tf +++ b/examples/custom_instance_settings/main.tf @@ -1,36 +1,64 @@ provider "aws" { - region = "us-east-1" + region = local.region } -###################################### -# Data sources to get VPC and subnets -###################################### -data "aws_vpc" "default" { - default = true +locals { + name = "custom-instance-settings" + region = "eu-west-1" + tags = { + Owner = "user" + Environment = "dev" + } } -data "aws_subnet_ids" "all" { - vpc_id = data.aws_vpc.default.id +################################################################################ +# Supporting Resources +################################################################################ + +module "vpc" { + source = "terraform-aws-modules/vpc/aws" + version = "~> 2" + + name = local.name + cidr = "10.99.0.0/18" + + azs = ["${local.region}a", "${local.region}b", "${local.region}c"] + public_subnets = ["10.99.0.0/24", "10.99.1.0/24", "10.99.2.0/24"] + private_subnets = ["10.99.3.0/24", "10.99.4.0/24", "10.99.5.0/24"] + database_subnets = ["10.99.7.0/24", "10.99.8.0/24", "10.99.9.0/24"] + + enable_dns_hostnames = true + enable_dns_support = true + + tags = local.tags } -############# -# RDS Aurora -############# +################################################################################ +# RDS Aurora Module +################################################################################ + module "aurora" { - source = "../../" - name = "aurora-example-postgresql" - engine = "aurora-postgresql" - engine_version = "11.6" - subnets = data.aws_subnet_ids.all.ids - vpc_id = data.aws_vpc.default.id - replica_count = 3 - instance_type = "db.r5.large" - apply_immediately = true - skip_final_snapshot = true - db_parameter_group_name = aws_db_parameter_group.aurora_db_postgres11_parameter_group.id - db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.aurora_cluster_postgres11_parameter_group.id - # enabled_cloudwatch_logs_exports = ["audit", "error", "general", "slowquery"] + source = "../../" + + name = local.name + engine = "aurora-postgresql" + engine_version = "11.9" + instance_type = "db.r5.large" + + vpc_id = module.vpc.vpc_id + db_subnet_group_name = module.vpc.database_subnet_group_name + create_security_group = true security_group_description = "" + allowed_cidr_blocks = module.vpc.private_subnets_cidr_blocks + + replica_count = 3 + + apply_immediately = true + skip_final_snapshot = true + + db_parameter_group_name = aws_db_parameter_group.example.id + db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.example.id + enabled_cloudwatch_logs_exports = ["postgresql"] instances_parameters = [ # List index should be equal to `replica_count` @@ -48,34 +76,20 @@ module "aurora" { instance_promotion_tier = 15 } ] -} -resource "aws_db_parameter_group" "aurora_db_postgres11_parameter_group" { - name = "test-aurora-db-postgres11-parameter-group" - family = "aurora-postgresql11" - description = "test-aurora-db-postgres11-parameter-group" + tags = local.tags } -resource "aws_rds_cluster_parameter_group" "aurora_cluster_postgres11_parameter_group" { - name = "test-aurora-postgres11-cluster-parameter-group" +resource "aws_db_parameter_group" "example" { + name = "${local.name}-aurora-db-postgres11-parameter-group" family = "aurora-postgresql11" - description = "test-aurora-postgres11-cluster-parameter-group" -} - -############################ -# Example of security group -############################ -resource "aws_security_group" "app_servers" { - name_prefix = "app-servers-" - description = "For application servers" - vpc_id = data.aws_vpc.default.id + description = "${local.name}-aurora-db-postgres11-parameter-group" + tags = local.tags } -resource "aws_security_group_rule" "allow_access" { - type = "ingress" - from_port = module.aurora.this_rds_cluster_port - to_port = module.aurora.this_rds_cluster_port - protocol = "tcp" - source_security_group_id = aws_security_group.app_servers.id - security_group_id = module.aurora.this_security_group_id +resource "aws_rds_cluster_parameter_group" "example" { + name = "${local.name}-aurora-postgres11-cluster-parameter-group" + family = "aurora-postgresql11" + description = "${local.name}-aurora-postgres11-cluster-parameter-group" + tags = local.tags } diff --git a/examples/custom_instance_settings/versions.tf b/examples/custom_instance_settings/versions.tf index 23fd6a3..b5267ef 100644 --- a/examples/custom_instance_settings/versions.tf +++ b/examples/custom_instance_settings/versions.tf @@ -1,7 +1,10 @@ terraform { - required_version = ">= 0.12.6" + required_version = ">= 0.12.26" required_providers { - aws = ">= 3.8" + aws = { + source = "hashicorp/aws" + version = ">= 3.8" + } } } diff --git a/examples/mysql/README.md b/examples/mysql/README.md new file mode 100644 index 0000000..67e854d --- /dev/null +++ b/examples/mysql/README.md @@ -0,0 +1,67 @@ +# MySQL Example + +Configuration in this directory creates a MySQL Aurora cluster. + +## Usage + +To run this example you need to execute: + +```bash +$ terraform init +$ terraform plan +$ terraform apply +``` + +Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources. + + +## Requirements + +| Name | Version | +|------|---------| +| terraform | >= 0.12.26 | +| aws | >= 3.8 | +| random | >= 2.2 | + +## Providers + +| Name | Version | +|------|---------| +| aws | >= 3.8 | +| random | >= 2.2 | + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| aurora | ../../ | | +| vpc | terraform-aws-modules/vpc/aws | ~> 2 | + +## Resources + +| Name | +|------| +| [aws_db_parameter_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_parameter_group) | +| [aws_rds_cluster_parameter_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster_parameter_group) | +| [random_password](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | + +## Inputs + +No input. + +## Outputs + +| Name | Description | +|------|-------------| +| this\_rds\_cluster\_database\_name | Name for an automatically created database on cluster creation | +| this\_rds\_cluster\_endpoint | The cluster endpoint | +| this\_rds\_cluster\_id | The ID of the cluster | +| this\_rds\_cluster\_instance\_endpoints | A list of all cluster instance endpoints | +| this\_rds\_cluster\_instance\_ids | A list of all cluster instance ids | +| this\_rds\_cluster\_master\_password | The master password | +| this\_rds\_cluster\_master\_username | The master username | +| this\_rds\_cluster\_port | The port | +| this\_rds\_cluster\_reader\_endpoint | The cluster reader endpoint | +| this\_rds\_cluster\_resource\_id | The Resource ID of the cluster | +| this\_security\_group\_id | The security group ID of the cluster | + diff --git a/examples/mysql/main.tf b/examples/mysql/main.tf index 08cbd66..b741d7b 100644 --- a/examples/mysql/main.tf +++ b/examples/mysql/main.tf @@ -1,101 +1,82 @@ provider "aws" { - region = "us-east-1" + region = local.region } -###################################### -# Data sources to get VPC and subnets -###################################### -data "aws_vpc" "default" { - default = true +locals { + name = "mysql" + region = "eu-west-1" + tags = { + Owner = "user" + Environment = "dev" + } } -data "aws_subnet_ids" "all" { - vpc_id = data.aws_vpc.default.id +################################################################################ +# Supporting Resources +################################################################################ + +resource "random_password" "master" { + length = 10 } -############# -# RDS Aurora -############# -module "aurora" { - source = "../../" - name = "aurora-example-mysql" - engine = "aurora-mysql" - engine_version = "5.7.12" - subnets = data.aws_subnet_ids.all.ids - vpc_id = data.aws_vpc.default.id - replica_count = 0 - instance_type = "db.t2.medium" - password = random_password.master.result - create_random_password = false - apply_immediately = true - skip_final_snapshot = true - db_parameter_group_name = aws_db_parameter_group.aurora_db_57_parameter_group.id - db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.aurora_57_cluster_parameter_group.id - iam_database_authentication_enabled = true - enabled_cloudwatch_logs_exports = ["audit", "error", "general", "slowquery"] - allowed_cidr_blocks = ["10.20.0.0/20", "20.20.0.0/20"] +module "vpc" { + source = "terraform-aws-modules/vpc/aws" + version = "~> 2" - create_security_group = true -} + name = local.name + cidr = "10.99.0.0/18" -resource "aws_db_parameter_group" "aurora_db_57_parameter_group" { - name = "test-aurora-db-57-parameter-group" - family = "aurora-mysql5.7" - description = "test-aurora-db-57-parameter-group" -} + azs = ["${local.region}a", "${local.region}b", "${local.region}c"] + public_subnets = ["10.99.0.0/24", "10.99.1.0/24", "10.99.2.0/24"] + private_subnets = ["10.99.3.0/24", "10.99.4.0/24", "10.99.5.0/24"] + database_subnets = ["10.99.7.0/24", "10.99.8.0/24", "10.99.9.0/24"] -resource "aws_rds_cluster_parameter_group" "aurora_57_cluster_parameter_group" { - name = "test-aurora-57-cluster-parameter-group" - family = "aurora-mysql5.7" - description = "test-aurora-57-cluster-parameter-group" + tags = local.tags } -############################ -# Example of security group -############################ -resource "aws_security_group" "app_servers" { - name_prefix = "app-servers-" - description = "For application servers" - vpc_id = data.aws_vpc.default.id -} +################################################################################ +# RDS Aurora Module +################################################################################ -resource "aws_security_group_rule" "allow_access" { - type = "ingress" - from_port = module.aurora.this_rds_cluster_port - to_port = module.aurora.this_rds_cluster_port - protocol = "tcp" - source_security_group_id = aws_security_group.app_servers.id - security_group_id = module.aurora.this_security_group_id -} +module "aurora" { + source = "../../" -# IAM Policy for use with iam_database_authentication_enabled = true -resource "aws_iam_policy" "aurora_mysql_policy_iam_auth" { - name = "test-aurora-db-57-policy-iam-auth" - - policy = < +## Requirements + +| Name | Version | +|------|---------| +| terraform | >= 0.12.26 | +| aws | >= 3.8 | +| random | >= 2.2 | + +## Providers + +| Name | Version | +|------|---------| +| aws | >= 3.8 | +| random | >= 2.2 | + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| aurora | ../../ | | +| vpc | terraform-aws-modules/vpc/aws | ~> 2 | + +## Resources + +| Name | +|------| +| [aws_db_parameter_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_parameter_group) | +| [aws_rds_cluster_parameter_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster_parameter_group) | +| [random_password](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | + +## Inputs + +No input. + +## Outputs + +| Name | Description | +|------|-------------| +| this\_rds\_cluster\_database\_name | Name for an automatically created database on cluster creation | +| this\_rds\_cluster\_endpoint | The cluster endpoint | +| this\_rds\_cluster\_id | The ID of the cluster | +| this\_rds\_cluster\_instance\_endpoints | A list of all cluster instance endpoints | +| this\_rds\_cluster\_instance\_ids | A list of all cluster instance ids | +| this\_rds\_cluster\_master\_password | The master password | +| this\_rds\_cluster\_master\_username | The master username | +| this\_rds\_cluster\_port | The port | +| this\_rds\_cluster\_reader\_endpoint | The cluster reader endpoint | +| this\_rds\_cluster\_resource\_id | The Resource ID of the cluster | +| this\_security\_group\_id | The security group ID of the cluster | + diff --git a/examples/postgresql/main.tf b/examples/postgresql/main.tf index f7a89e7..10a5c40 100644 --- a/examples/postgresql/main.tf +++ b/examples/postgresql/main.tf @@ -1,65 +1,82 @@ provider "aws" { - region = "us-east-1" + region = local.region } -###################################### -# Data sources to get VPC and subnets -###################################### -data "aws_vpc" "default" { - default = true +locals { + name = "postgresql" + region = "eu-west-1" + tags = { + Owner = "user" + Environment = "dev" + } } -data "aws_subnet_ids" "all" { - vpc_id = data.aws_vpc.default.id -} +################################################################################ +# Supporting Resources +################################################################################ -############# -# RDS Aurora -############# -module "aurora" { - source = "../../" - name = "aurora-example-postgresql" - engine = "aurora-postgresql" - engine_version = "11.6" - subnets = data.aws_subnet_ids.all.ids - vpc_id = data.aws_vpc.default.id - replica_count = 2 - instance_type = "db.r4.large" - instance_type_replica = "db.t3.medium" - apply_immediately = true - skip_final_snapshot = true - db_parameter_group_name = aws_db_parameter_group.aurora_db_postgres11_parameter_group.id - db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.aurora_cluster_postgres11_parameter_group.id - # enabled_cloudwatch_logs_exports = ["audit", "error", "general", "slowquery"] - security_group_description = "" +resource "random_password" "master" { + length = 10 } -resource "aws_db_parameter_group" "aurora_db_postgres11_parameter_group" { - name = "test-aurora-db-postgres11-parameter-group" - family = "aurora-postgresql11" - description = "test-aurora-db-postgres11-parameter-group" +module "vpc" { + source = "terraform-aws-modules/vpc/aws" + version = "~> 2" + + name = local.name + cidr = "10.99.0.0/18" + + azs = ["${local.region}a", "${local.region}b", "${local.region}c"] + public_subnets = ["10.99.0.0/24", "10.99.1.0/24", "10.99.2.0/24"] + private_subnets = ["10.99.3.0/24", "10.99.4.0/24", "10.99.5.0/24"] + database_subnets = ["10.99.7.0/24", "10.99.8.0/24", "10.99.9.0/24"] + + tags = local.tags } -resource "aws_rds_cluster_parameter_group" "aurora_cluster_postgres11_parameter_group" { - name = "test-aurora-postgres11-cluster-parameter-group" - family = "aurora-postgresql11" - description = "test-aurora-postgres11-cluster-parameter-group" +################################################################################ +# RDS Aurora Module +################################################################################ + +module "aurora" { + source = "../../" + + name = local.name + engine = "aurora-postgresql" + engine_version = "11.9" + instance_type = "db.r5.large" + instance_type_replica = "db.t3.medium" + + vpc_id = module.vpc.vpc_id + db_subnet_group_name = module.vpc.database_subnet_group_name + create_security_group = true + allowed_cidr_blocks = module.vpc.private_subnets_cidr_blocks + + replica_count = 2 + iam_database_authentication_enabled = true + password = random_password.master.result + create_random_password = false + + apply_immediately = true + skip_final_snapshot = true + + db_parameter_group_name = aws_db_parameter_group.example.id + db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.example.id + enabled_cloudwatch_logs_exports = ["postgresql"] + + tags = local.tags } -############################ -# Example of security group -############################ -resource "aws_security_group" "app_servers" { - name_prefix = "app-servers-" - description = "For application servers" - vpc_id = data.aws_vpc.default.id +resource "aws_db_parameter_group" "example" { + name = "${local.name}-aurora-db-postgres11-parameter-group" + family = "aurora-postgresql11" + description = "${local.name}-aurora-db-postgres11-parameter-group" + tags = local.tags } -resource "aws_security_group_rule" "allow_access" { - type = "ingress" - from_port = module.aurora.this_rds_cluster_port - to_port = module.aurora.this_rds_cluster_port - protocol = "tcp" - source_security_group_id = aws_security_group.app_servers.id - security_group_id = module.aurora.this_security_group_id +resource "aws_rds_cluster_parameter_group" "example" { + name = "${local.name}-aurora-postgres11-cluster-parameter-group" + family = "aurora-postgresql11" + description = "${local.name}-aurora-postgres11-cluster-parameter-group" + tags = local.tags } diff --git a/examples/postgresql/versions.tf b/examples/postgresql/versions.tf index 23fd6a3..309ada5 100644 --- a/examples/postgresql/versions.tf +++ b/examples/postgresql/versions.tf @@ -1,7 +1,15 @@ terraform { - required_version = ">= 0.12.6" + required_version = ">= 0.12.26" required_providers { - aws = ">= 3.8" + aws = { + source = "hashicorp/aws" + version = ">= 3.8" + } + + random = { + source = "hashicorp/random" + version = ">= 2.2" + } } } diff --git a/examples/s3_import/README.md b/examples/s3_import/README.md index 51802a1..f22c611 100644 --- a/examples/s3_import/README.md +++ b/examples/s3_import/README.md @@ -64,8 +64,8 @@ Note that this example may create resources which cost money. Run `terraform des | Name | Source | Version | |------|--------|---------| | aurora | ../../ | | -| import_s3_bucket | terraform-aws-modules/s3-bucket/aws | ~> 1.20 | -| vpc | terraform-aws-modules/vpc/aws | ~> 2.77 | +| import_s3_bucket | terraform-aws-modules/s3-bucket/aws | ~> 1 | +| vpc | terraform-aws-modules/vpc/aws | ~> 2 | ## Resources diff --git a/examples/s3_import/backup.zip b/examples/s3_import/backup.zip index 2efa6593ebe55ff455efa9b406660dcc7ad8e9cd..8cb737fa7f56cc867095f212bc564d42b78e441c 100644 GIT binary patch delta 20953 zcmaJ|2Ygh;_TB~wq%A3Xvq^T-fIxsGdzT(cqKHVBC%z{t{fU4CFrXqOG^Gptkqj+} zO79pY(y?Jcx=I%jsi6b}1O&qWo0&Uzce0!Je!na4clVn!XU;iu&Y8Ji%6{2z-2B~s zq}J(<~KJs?>Pj|@b`iYM$0{;!C;9r7z~};nc2UAhR%h( zx-5FN?aX-mbQw=11kCQ|u--3gFAduCaWkXEh961KHEQ&nTgCt%NMV4fuF(<-%$!Vf zO=IMQ-sVZY%|<*XJoNut@KnN68BYM7Ks;6ORK*j7Cm2r%o=`ktc&vD;;R(kRfhQ7A zR8eoUt$Du1N_AN=-&V^QNe<7qIk11-RC!@nrNOo9`OQ$BS%ZEkP6%S71xV+*t*fn~l1GQHo~s^5!dASYYdCwxrU5 z#t}*^8N6PtM#25y93OCpPi+ZiO9}-SuUBi6ylll+m7=ef+Gd+9H7Uxv2qM!rsR3lj z3R{Tp+Geb2lo4i211jy0hDu`o zcGZ?&+27VyDl0?HmTD9@tBT?q=QQWG&abKj^GuO`RINkCPE)G+Sh%QXRmEuLChi}i z_-5~-c_B)=k!KO?_v$2Vkz(}~6A`A=_gJ=}FJNvp1kL3HXD>?vjzM2P`7BMp|(pz9;zt+{uZO8Yf!O6E0djTZ4r^QK>OtXR~$;R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q?muAFTJ<0}Yrw_F(oFn{wAG{(KQ3``S0{XPtzM3`6LDWyOmZxuD$3&s-(K9Gnd z1rNR0g~>ktp7L*-9aOrx9!2=*en>mcN|~8sXAL6Bw=MP7faAp9E;Uaxq6jq+7aLwvu9EGS#1edZBD-)#0)&va)=i_VLg0&(IH{nT zXHYbjtYRNyrGQn+OWiFrO|_9II*w-)rmI*Dzt+fWa@pyfU|oWL$YOR~(!yT$#trW< z3TVv7k88Br{yGuU%hgf#M42D+UaMgeu(FXKPqMN?jf{_8q+H^)9_?hw6Q>Hc=qE9< zJ!nlRi~jR_g16dI(e}To2r2%8G#KgcPPa0LZ)eP%rG*=k$WB#erWMRTq>(pcS_8`t zvg$)dMvJx*DFLaB4=K<8_{h2jKDkk)9b-*O5&fp+F$$3t@cB&?KRV-t5l3c!jO{?) z`HsyFA&ZetazA;nkbGnCV4jsVh@V0{sb=v>hRua`X6ltceyc@f$f5mutW<$S={3>kOGDe8+domLZyJoitM`JtwKcse-{n8klZOjV1 HakKp&htEl! diff --git a/examples/s3_import/main.tf b/examples/s3_import/main.tf index 72458de..7d29140 100644 --- a/examples/s3_import/main.tf +++ b/examples/s3_import/main.tf @@ -25,19 +25,15 @@ resource "random_pet" "this" { module "vpc" { source = "terraform-aws-modules/vpc/aws" - version = "~> 2.77" + version = "~> 2" name = local.name - cidr = "10.0.0.0/18" + cidr = "10.99.0.0/18" azs = ["${local.region}a", "${local.region}b", "${local.region}c"] - public_subnets = ["10.0.0.0/24", "10.0.1.0/24", "10.0.2.0/24"] - private_subnets = ["10.0.3.0/24", "10.0.4.0/24", "10.0.5.0/24"] - database_subnets = ["10.0.7.0/24", "10.0.8.0/24", "10.0.9.0/24"] - - create_database_subnet_group = true - enable_nat_gateway = true - single_nat_gateway = true + public_subnets = ["10.99.0.0/24", "10.99.1.0/24", "10.99.2.0/24"] + private_subnets = ["10.99.3.0/24", "10.99.4.0/24", "10.99.5.0/24"] + database_subnets = ["10.99.7.0/24", "10.99.8.0/24", "10.99.9.0/24"] enable_dns_hostnames = true enable_dns_support = true @@ -48,7 +44,7 @@ module "vpc" { module "import_s3_bucket" { source = "terraform-aws-modules/s3-bucket/aws" - version = "~> 1.20" + version = "~> 1" bucket = "${local.name}-${random_pet.this.id}" acl = "private" @@ -122,17 +118,20 @@ resource "aws_iam_role_policy" "s3_import" { module "aurora" { source = "../../" - name = local.name - + name = local.name engine = "aurora-mysql" engine_version = "5.7.12" - instance_type = "db.t3.large" - replica_count = 0 + instance_type = "db.r5.large" + + vpc_id = module.vpc.vpc_id + db_subnet_group_name = module.vpc.database_subnet_group_name + create_security_group = true + allowed_cidr_blocks = module.vpc.private_subnets_cidr_blocks - username = "s3_import_user" + replica_count = 1 + iam_database_authentication_enabled = true password = random_password.master.result create_random_password = false - iam_database_authentication_enabled = true # S3 import https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Integrating.LoadFromS3.html s3_import = { @@ -141,29 +140,26 @@ module "aurora" { ingestion_role = aws_iam_role.s3_import.arn } - vpc_id = module.vpc.vpc_id - subnets = module.vpc.database_subnets - create_security_group = true - allowed_cidr_blocks = module.vpc.private_subnets_cidr_blocks + apply_immediately = true + skip_final_snapshot = true - apply_immediately = true - skip_final_snapshot = true - db_subnet_group_name = local.name - db_parameter_group_name = aws_db_parameter_group.aurora_db_57_parameter_group.id - db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.aurora_57_cluster_parameter_group.id + db_parameter_group_name = aws_db_parameter_group.example.id + db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.example.id enabled_cloudwatch_logs_exports = ["audit", "error", "general", "slowquery"] tags = local.tags } -resource "aws_db_parameter_group" "aurora_db_57_parameter_group" { +resource "aws_db_parameter_group" "example" { name = "${local.name}-aurora-db-57-parameter-group" family = "aurora-mysql5.7" description = "${local.name}-aurora-db-57-parameter-group" + tags = local.tags } -resource "aws_rds_cluster_parameter_group" "aurora_57_cluster_parameter_group" { +resource "aws_rds_cluster_parameter_group" "example" { name = "${local.name}-aurora-57-cluster-parameter-group" family = "aurora-mysql5.7" description = "${local.name}-aurora-57-cluster-parameter-group" + tags = local.tags } diff --git a/examples/s3_import/versions.tf b/examples/s3_import/versions.tf index 49f3e58..309ada5 100644 --- a/examples/s3_import/versions.tf +++ b/examples/s3_import/versions.tf @@ -2,7 +2,14 @@ terraform { required_version = ">= 0.12.26" required_providers { - aws = ">= 3.8" - random = ">= 2.2" + aws = { + source = "hashicorp/aws" + version = ">= 3.8" + } + + random = { + source = "hashicorp/random" + version = ">= 2.2" + } } } diff --git a/examples/serverless/README.md b/examples/serverless/README.md index 97fffec..5569014 100644 --- a/examples/serverless/README.md +++ b/examples/serverless/README.md @@ -1,5 +1,76 @@ -# AWS RDS Aurora Terraform Serverless Example +# Serverless Example -## Usage of Serverless PostgreSQL or MySQL 5.6 +Configuration in this directory creates Aurora serverless clusters for both PostgreSQL and MySQL. -Uncomment blocks marked with `# PostgreSQL` or `# MySQL` inside of [`main.tf`](main.tf). +## Usage + +To run this example you need to execute: + +```bash +$ terraform init +$ terraform plan +$ terraform apply +``` + +Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources. + + +## Requirements + +| Name | Version | +|------|---------| +| terraform | >= 0.12.26 | +| aws | >= 3.8 | + +## Providers + +| Name | Version | +|------|---------| +| aws | >= 3.8 | + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| aurora_mysql | ../../ | | +| aurora_postgresql | ../../ | | +| vpc | terraform-aws-modules/vpc/aws | ~> 2 | + +## Resources + +| Name | +|------| +| [aws_db_parameter_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_parameter_group) | +| [aws_rds_cluster_parameter_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster_parameter_group) | + +## Inputs + +No input. + +## Outputs + +| Name | Description | +|------|-------------| +| mysql\_rds\_cluster\_database\_name | Name for an automatically created database on cluster creation | +| mysql\_rds\_cluster\_endpoint | The cluster endpoint | +| mysql\_rds\_cluster\_id | The ID of the cluster | +| mysql\_rds\_cluster\_instance\_endpoints | A list of all cluster instance endpoints | +| mysql\_rds\_cluster\_instance\_ids | A list of all cluster instance ids | +| mysql\_rds\_cluster\_master\_password | The master password | +| mysql\_rds\_cluster\_master\_username | The master username | +| mysql\_rds\_cluster\_port | The port | +| mysql\_rds\_cluster\_reader\_endpoint | The cluster reader endpoint | +| mysql\_rds\_cluster\_resource\_id | The Resource ID of the cluster | +| mysql\_security\_group\_id | The security group ID of the cluster | +| postgresql\_rds\_cluster\_database\_name | Name for an automatically created database on cluster creation | +| postgresql\_rds\_cluster\_endpoint | The cluster endpoint | +| postgresql\_rds\_cluster\_id | The ID of the cluster | +| postgresql\_rds\_cluster\_instance\_endpoints | A list of all cluster instance endpoints | +| postgresql\_rds\_cluster\_instance\_ids | A list of all cluster instance ids | +| postgresql\_rds\_cluster\_master\_password | The master password | +| postgresql\_rds\_cluster\_master\_username | The master username | +| postgresql\_rds\_cluster\_port | The port | +| postgresql\_rds\_cluster\_reader\_endpoint | The cluster reader endpoint | +| postgresql\_rds\_cluster\_resource\_id | The Resource ID of the cluster | +| postgresql\_security\_group\_id | The security group ID of the cluster | + diff --git a/examples/serverless/main.tf b/examples/serverless/main.tf index 8c797cd..01989c9 100644 --- a/examples/serverless/main.tf +++ b/examples/serverless/main.tf @@ -1,53 +1,64 @@ provider "aws" { - region = "us-east-1" + region = local.region } -###################################### -# Data sources to get VPC and subnets -###################################### -data "aws_vpc" "default" { - default = true +locals { + name = "serverless" + region = "eu-west-1" + tags = { + Owner = "user" + Environment = "dev" + } } -data "aws_subnet_ids" "all" { - vpc_id = data.aws_vpc.default.id +################################################################################ +# Supporting Resources +################################################################################ + +module "vpc" { + source = "terraform-aws-modules/vpc/aws" + version = "~> 2" + + name = local.name + cidr = "10.99.0.0/18" + + azs = ["${local.region}a", "${local.region}b", "${local.region}c"] + public_subnets = ["10.99.0.0/24", "10.99.1.0/24", "10.99.2.0/24"] + private_subnets = ["10.99.3.0/24", "10.99.4.0/24", "10.99.5.0/24"] + database_subnets = ["10.99.7.0/24", "10.99.8.0/24", "10.99.9.0/24"] + + tags = local.tags } -############# -# RDS Aurora -############# -module "aurora" { +################################################################################ +# RDS Aurora Module - PostgreSQL +################################################################################ + +module "aurora_postgresql" { source = "../../" - name = "aurora" - # PostgreSQL - engine = "aurora-postgresql" + name = "${local.name}-postgresql" + engine = "aurora-postgresql" + engine_mode = "serverless" + engine_version = null + storage_encrypted = true - # MySQL - # engine = "aurora" + vpc_id = module.vpc.vpc_id + subnets = module.vpc.database_subnets + create_security_group = true + allowed_cidr_blocks = module.vpc.private_subnets_cidr_blocks - engine_mode = "serverless" - engine_version = null replica_scale_enabled = false replica_count = 0 - backtrack_window = 10 # ignored in serverless - - subnets = data.aws_subnet_ids.all.ids - vpc_id = data.aws_vpc.default.id monitoring_interval = 60 - skip_final_snapshot = true - instance_type = "db.r4.large" # ignored for serverless - apply_immediately = true - storage_encrypted = true - # PostgreSQL - db_parameter_group_name = aws_db_parameter_group.aurora_db_postgresql10_parameter_group.id - db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.aurora_cluster_postgresql10_parameter_group.id + apply_immediately = true + skip_final_snapshot = true - # MySQL - # db_parameter_group_name = aws_db_parameter_group.aurora_db_aurora56_parameter_group.id - # db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.aurora_cluster_aurora56_parameter_group.id + db_parameter_group_name = aws_db_parameter_group.example_postgresql.id + db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.example_postgresql.id + # enabled_cloudwatch_logs_exports = # NOT SUPPORTED scaling_configuration = { auto_pause = true @@ -58,47 +69,69 @@ module "aurora" { } } -# PostgreSQL -resource "aws_db_parameter_group" "aurora_db_postgresql10_parameter_group" { - name = "test-postgresql10-parameter-group" +resource "aws_db_parameter_group" "example_postgresql" { + name = "${local.name}-aurora-db-postgres-parameter-group" family = "aurora-postgresql10" - description = "test-postgresql10-parameter-group" + description = "${local.name}-aurora-db-postgres-parameter-group" + tags = local.tags } -resource "aws_rds_cluster_parameter_group" "aurora_cluster_postgresql10_parameter_group" { - name = "test-postgresql10-cluster-parameter-group" +resource "aws_rds_cluster_parameter_group" "example_postgresql" { + name = "${local.name}-aurora-postgres-cluster-parameter-group" family = "aurora-postgresql10" - description = "test-postgresql10-cluster-parameter-group" + description = "${local.name}-aurora-postgres-cluster-parameter-group" + tags = local.tags } -# MySQL -#resource "aws_db_parameter_group" "aurora_db_aurora56_parameter_group" { -# name = "test-aurora56-parameter-group" -# family = "aurora5.6" -# description = "test-aurora56-parameter-group" -#} -# -#resource "aws_rds_cluster_parameter_group" "aurora_cluster_aurora56_parameter_group" { -# name = "test-aurora56-cluster-parameter-group" -# family = "aurora5.6" -# description = "test-aurora56-cluster-parameter-group" -#} - -############################ -# Example of security group -############################ -resource "aws_security_group" "app_servers" { - name = "app-servers" - description = "For application servers" - vpc_id = data.aws_vpc.default.id +################################################################################ +# RDS Aurora Module - MySQL +################################################################################ + +module "aurora_mysql" { + source = "../../" + + name = "${local.name}-mysql" + engine = "aurora-mysql" + engine_mode = "serverless" + engine_version = null + storage_encrypted = true + + vpc_id = module.vpc.vpc_id + subnets = module.vpc.database_subnets + create_security_group = true + allowed_cidr_blocks = module.vpc.private_subnets_cidr_blocks + + replica_scale_enabled = false + replica_count = 0 + + monitoring_interval = 60 + + apply_immediately = true + skip_final_snapshot = true + + db_parameter_group_name = aws_db_parameter_group.example_mysql.id + db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.example_mysql.id + # enabled_cloudwatch_logs_exports = # NOT SUPPORTED + + scaling_configuration = { + auto_pause = true + min_capacity = 2 + max_capacity = 16 + seconds_until_auto_pause = 300 + timeout_action = "ForceApplyCapacityChange" + } } -resource "aws_security_group_rule" "allow_access" { - type = "ingress" - from_port = module.aurora.this_rds_cluster_port - to_port = module.aurora.this_rds_cluster_port - protocol = "tcp" - source_security_group_id = aws_security_group.app_servers.id - security_group_id = module.aurora.this_security_group_id +resource "aws_db_parameter_group" "example_mysql" { + name = "${local.name}-aurora-db-mysql-parameter-group" + family = "aurora-mysql5.7" + description = "${local.name}-aurora-db-mysql-parameter-group" + tags = local.tags } +resource "aws_rds_cluster_parameter_group" "example_mysql" { + name = "${local.name}-aurora-mysql-cluster-parameter-group" + family = "aurora-mysql5.7" + description = "${local.name}-aurora-mysql-cluster-parameter-group" + tags = local.tags +} diff --git a/examples/serverless/outputs.tf b/examples/serverless/outputs.tf index fb6cb04..a24d5bb 100644 --- a/examples/serverless/outputs.tf +++ b/examples/serverless/outputs.tf @@ -1,58 +1,125 @@ +################################################################################ +# RDS Aurora Module - PostgreSQL +################################################################################ + +# aws_rds_cluster +output "postgresql_rds_cluster_id" { + description = "The ID of the cluster" + value = module.aurora_postgresql.this_rds_cluster_id +} + +output "postgresql_rds_cluster_resource_id" { + description = "The Resource ID of the cluster" + value = module.aurora_postgresql.this_rds_cluster_resource_id +} + +output "postgresql_rds_cluster_endpoint" { + description = "The cluster endpoint" + value = module.aurora_postgresql.this_rds_cluster_endpoint +} + +output "postgresql_rds_cluster_reader_endpoint" { + description = "The cluster reader endpoint" + value = module.aurora_postgresql.this_rds_cluster_reader_endpoint +} + +output "postgresql_rds_cluster_database_name" { + description = "Name for an automatically created database on cluster creation" + value = module.aurora_postgresql.this_rds_cluster_database_name +} + +output "postgresql_rds_cluster_master_password" { + description = "The master password" + value = module.aurora_postgresql.this_rds_cluster_master_password + sensitive = true +} + +output "postgresql_rds_cluster_port" { + description = "The port" + value = module.aurora_postgresql.this_rds_cluster_port +} + +output "postgresql_rds_cluster_master_username" { + description = "The master username" + value = module.aurora_postgresql.this_rds_cluster_master_username +} + +# aws_rds_cluster_instance +output "postgresql_rds_cluster_instance_endpoints" { + description = "A list of all cluster instance endpoints" + value = module.aurora_postgresql.this_rds_cluster_instance_endpoints +} + +output "postgresql_rds_cluster_instance_ids" { + description = "A list of all cluster instance ids" + value = module.aurora_postgresql.this_rds_cluster_instance_ids +} + +# aws_security_group +output "postgresql_security_group_id" { + description = "The security group ID of the cluster" + value = module.aurora_postgresql.this_security_group_id +} + +################################################################################ +# RDS Aurora Module - MySQL +################################################################################ + # aws_rds_cluster -output "this_rds_cluster_id" { +output "mysql_rds_cluster_id" { description = "The ID of the cluster" - value = module.aurora.this_rds_cluster_id + value = module.aurora_mysql.this_rds_cluster_id } -output "this_rds_cluster_resource_id" { +output "mysql_rds_cluster_resource_id" { description = "The Resource ID of the cluster" - value = module.aurora.this_rds_cluster_resource_id + value = module.aurora_mysql.this_rds_cluster_resource_id } -output "this_rds_cluster_endpoint" { +output "mysql_rds_cluster_endpoint" { description = "The cluster endpoint" - value = module.aurora.this_rds_cluster_endpoint + value = module.aurora_mysql.this_rds_cluster_endpoint } -output "this_rds_cluster_reader_endpoint" { +output "mysql_rds_cluster_reader_endpoint" { description = "The cluster reader endpoint" - value = module.aurora.this_rds_cluster_reader_endpoint + value = module.aurora_mysql.this_rds_cluster_reader_endpoint } -output "this_rds_cluster_database_name" { +output "mysql_rds_cluster_database_name" { description = "Name for an automatically created database on cluster creation" - value = module.aurora.this_rds_cluster_database_name + value = module.aurora_mysql.this_rds_cluster_database_name } -output "this_rds_cluster_master_password" { +output "mysql_rds_cluster_master_password" { description = "The master password" - value = module.aurora.this_rds_cluster_master_password + value = module.aurora_mysql.this_rds_cluster_master_password sensitive = true } -output "this_rds_cluster_port" { +output "mysql_rds_cluster_port" { description = "The port" - value = module.aurora.this_rds_cluster_port + value = module.aurora_mysql.this_rds_cluster_port } -output "this_rds_cluster_master_username" { +output "mysql_rds_cluster_master_username" { description = "The master username" - value = module.aurora.this_rds_cluster_master_username + value = module.aurora_mysql.this_rds_cluster_master_username } # aws_rds_cluster_instance -output "this_rds_cluster_instance_endpoints" { +output "mysql_rds_cluster_instance_endpoints" { description = "A list of all cluster instance endpoints" - value = module.aurora.this_rds_cluster_instance_endpoints + value = module.aurora_mysql.this_rds_cluster_instance_endpoints } -output "this_rds_cluster_instance_ids" { +output "mysql_rds_cluster_instance_ids" { description = "A list of all cluster instance ids" - value = module.aurora.this_rds_cluster_instance_ids + value = module.aurora_mysql.this_rds_cluster_instance_ids } # aws_security_group -output "this_security_group_id" { +output "mysql_security_group_id" { description = "The security group ID of the cluster" - value = module.aurora.this_security_group_id + value = module.aurora_mysql.this_security_group_id } diff --git a/examples/serverless/versions.tf b/examples/serverless/versions.tf index 23fd6a3..b5267ef 100644 --- a/examples/serverless/versions.tf +++ b/examples/serverless/versions.tf @@ -1,7 +1,10 @@ terraform { - required_version = ">= 0.12.6" + required_version = ">= 0.12.26" required_providers { - aws = ">= 3.8" + aws = { + source = "hashicorp/aws" + version = ">= 3.8" + } } } diff --git a/main.tf b/main.tf index 7ce7b15..de6a54d 100644 --- a/main.tf +++ b/main.tf @@ -1,7 +1,7 @@ locals { port = var.port == "" ? var.engine == "aurora-postgresql" ? "5432" : "3306" : var.port - master_password = var.create_cluster && var.create_random_password && var.is_primary_cluster ? random_password.master_password[0].result : var.password db_subnet_group_name = var.db_subnet_group_name == "" ? join("", aws_db_subnet_group.this.*.name) : var.db_subnet_group_name + master_password = var.create_cluster && var.create_random_password && var.is_primary_cluster ? random_password.master_password[0].result : var.password backtrack_window = (var.engine == "aurora-mysql" || var.engine == "aurora") && var.engine_mode != "serverless" ? var.backtrack_window : 0 rds_enhanced_monitoring_arn = var.create_monitoring_role ? join("", aws_iam_role.rds_enhanced_monitoring.*.arn) : var.monitoring_role_arn diff --git a/versions.tf b/versions.tf index d5bd958..309ada5 100644 --- a/versions.tf +++ b/versions.tf @@ -1,8 +1,15 @@ terraform { - required_version = ">= 0.12.6" + required_version = ">= 0.12.26" required_providers { - aws = ">= 3.8" - random = ">= 2.2" + aws = { + source = "hashicorp/aws" + version = ">= 3.8" + } + + random = { + source = "hashicorp/random" + version = ">= 2.2" + } } }