Skip to content

Commit

Permalink
chore: update examples to to be self-sufficient and using latest prac…
Browse files Browse the repository at this point in the history
…tices/versions (#200)
  • Loading branch information
bryantbiggs authored Mar 13, 2021
1 parent 24b3539 commit e859489
Show file tree
Hide file tree
Showing 28 changed files with 912 additions and 412 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ override.tf.json
# Ignore CLI configuration files
.terraformrc
terraform.rc

# S3 import example
backup
41 changes: 21 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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

Expand All @@ -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 |

Expand Down
69 changes: 0 additions & 69 deletions examples/advanced/main.tf

This file was deleted.

7 changes: 0 additions & 7 deletions examples/advanced/versions.tf

This file was deleted.

65 changes: 65 additions & 0 deletions examples/autoscaling/README.md
Original file line number Diff line number Diff line change
@@ -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.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## 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 |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
86 changes: 86 additions & 0 deletions examples/autoscaling/main.tf
Original file line number Diff line number Diff line change
@@ -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
}
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions examples/autoscaling/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 0.12.26"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.8"
}
}
}
63 changes: 63 additions & 0 deletions examples/custom_instance_settings/README.md
Original file line number Diff line number Diff line change
@@ -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.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## 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 |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Loading

0 comments on commit e859489

Please sign in to comment.