Skip to content

Commit dad2482

Browse files
feat: DSQL Support (#508)
Co-authored-by: Anton Babenko <[email protected]>
1 parent 273752a commit dad2482

File tree

11 files changed

+400
-0
lines changed

11 files changed

+400
-0
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Terraform module which creates AWS RDS Aurora resources.
1515
- Custom endpoints
1616
- RDS multi-AZ support (not Aurora)
1717
- Aurora Limitless
18+
- Aurora DSQL cluster
1819

1920
## Usage
2021

@@ -205,6 +206,33 @@ module "cluster" {
205206
}
206207
```
207208

209+
## DSQL Multi Region Peered Clusters
210+
```hcl
211+
module "dsql_cluster_1" {
212+
source = "../../modules/dsql"
213+
214+
witness_region = "us-west-2"
215+
create_cluster_peering = true
216+
clusters = [module.dsql_cluster_2.arn]
217+
218+
tags = { Name = "dsql-1" }
219+
}
220+
221+
module "dsql_cluster_2" {
222+
source = "../../modules/dsql"
223+
224+
witness_region = "us-west-2"
225+
create_cluster_peering = true
226+
clusters = [module.dsql_cluster_1.arn]
227+
228+
tags = { Name = "dsql-2" }
229+
230+
providers = {
231+
aws = aws.region2
232+
}
233+
}
234+
```
235+
208236
## Examples
209237

210238
- [Autoscaling](https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/tree/master/examples/autoscaling): A PostgreSQL cluster with enhanced monitoring and autoscaling enabled
@@ -215,6 +243,7 @@ module "cluster" {
215243
- [PostgreSQL](https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/tree/master/examples/postgresql): A simple PostgreSQL cluster
216244
- [S3 Import](https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/tree/master/examples/s3-import): A MySQL cluster created from a Percona Xtrabackup stored in S3
217245
- [Serverless](https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/tree/master/examples/serverless): Serverless V1 and V2 (PostgreSQL and MySQL)
246+
- [DSQL](https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/tree/master/examples/dsql): Multi region and single region DSQL clusters
218247

219248
## Documentation
220249

examples/dsql/README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Aurora DSQL Cluster Example
2+
3+
Configuration in this directory creates multi-region peered Aurora DSQL clusters and a single region Aurora DSQL cluster.
4+
5+
## Usage
6+
7+
To run this example you need to execute:
8+
9+
```bash
10+
$ terraform init
11+
$ terraform plan
12+
$ terraform apply
13+
```
14+
15+
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
16+
17+
<!-- BEGIN_TF_DOCS -->
18+
## Requirements
19+
20+
| Name | Version |
21+
|------|---------|
22+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
23+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.100 |
24+
25+
## Providers
26+
27+
No providers.
28+
29+
## Modules
30+
31+
| Name | Source | Version |
32+
|------|--------|---------|
33+
| <a name="module_dsql_cluster_1"></a> [dsql\_cluster\_1](#module\_dsql\_cluster\_1) | ../../modules/dsql | n/a |
34+
| <a name="module_dsql_cluster_2"></a> [dsql\_cluster\_2](#module\_dsql\_cluster\_2) | ../../modules/dsql | n/a |
35+
| <a name="module_dsql_single_region"></a> [dsql\_single\_region](#module\_dsql\_single\_region) | ../../modules/dsql | n/a |
36+
37+
## Resources
38+
39+
No resources.
40+
41+
## Inputs
42+
43+
No inputs.
44+
45+
## Outputs
46+
47+
| Name | Description |
48+
|------|-------------|
49+
| <a name="output_dsql_cluster_1_arn"></a> [dsql\_cluster\_1\_arn](#output\_dsql\_cluster\_1\_arn) | ARN of the cluster |
50+
| <a name="output_dsql_cluster_1_encryption_details"></a> [dsql\_cluster\_1\_encryption\_details](#output\_dsql\_cluster\_1\_encryption\_details) | Encryption configuration details for the DSQL cluster |
51+
| <a name="output_dsql_cluster_1_identifier"></a> [dsql\_cluster\_1\_identifier](#output\_dsql\_cluster\_1\_identifier) | Cluster identifier |
52+
| <a name="output_dsql_cluster_1_multi_region_properties"></a> [dsql\_cluster\_1\_multi\_region\_properties](#output\_dsql\_cluster\_1\_multi\_region\_properties) | Multi-region properties of the DSQL cluster |
53+
| <a name="output_dsql_cluster_1_vpc_endpoint_service_name"></a> [dsql\_cluster\_1\_vpc\_endpoint\_service\_name](#output\_dsql\_cluster\_1\_vpc\_endpoint\_service\_name) | The DSQL cluster's VPC endpoint service name |
54+
| <a name="output_dsql_cluster_2_arn"></a> [dsql\_cluster\_2\_arn](#output\_dsql\_cluster\_2\_arn) | ARN of the cluster |
55+
| <a name="output_dsql_cluster_2_encryption_details"></a> [dsql\_cluster\_2\_encryption\_details](#output\_dsql\_cluster\_2\_encryption\_details) | Encryption configuration details for the DSQL cluster |
56+
| <a name="output_dsql_cluster_2_identifier"></a> [dsql\_cluster\_2\_identifier](#output\_dsql\_cluster\_2\_identifier) | Cluster identifier |
57+
| <a name="output_dsql_cluster_2_multi_region_properties"></a> [dsql\_cluster\_2\_multi\_region\_properties](#output\_dsql\_cluster\_2\_multi\_region\_properties) | Multi-region properties of the DSQL cluster |
58+
| <a name="output_dsql_cluster_2_vpc_endpoint_service_name"></a> [dsql\_cluster\_2\_vpc\_endpoint\_service\_name](#output\_dsql\_cluster\_2\_vpc\_endpoint\_service\_name) | The DSQL cluster's VPC endpoint service name |
59+
<!-- END_TF_DOCS -->

examples/dsql/main.tf

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
provider "aws" {
2+
region = local.region
3+
}
4+
5+
provider "aws" {
6+
region = local.region2
7+
alias = "region2"
8+
}
9+
10+
locals {
11+
name = "ex-${basename(path.cwd)}"
12+
region = "us-east-1"
13+
region2 = "us-east-2"
14+
witness_region = "us-west-2"
15+
16+
tags = {
17+
Example = local.name
18+
GithubRepo = "terraform-aws-rds-aurora"
19+
GithubOrg = "terraform-aws-modules"
20+
}
21+
}
22+
23+
################################################################################
24+
# RDS Aurora Module
25+
################################################################################
26+
27+
module "dsql_cluster_1" {
28+
source = "../../modules/dsql"
29+
30+
deletion_protection_enabled = false
31+
witness_region = local.witness_region
32+
create_cluster_peering = true
33+
clusters = [module.dsql_cluster_2.arn]
34+
35+
timeouts = {
36+
create = "1h"
37+
}
38+
39+
tags = merge(local.tags, { Name = local.name })
40+
}
41+
42+
module "dsql_cluster_2" {
43+
source = "../../modules/dsql"
44+
45+
deletion_protection_enabled = false
46+
witness_region = local.witness_region
47+
create_cluster_peering = true
48+
clusters = [module.dsql_cluster_1.arn]
49+
50+
tags = merge(local.tags, { Name = local.name })
51+
52+
providers = {
53+
aws = aws.region2
54+
}
55+
}
56+
57+
module "dsql_single_region" {
58+
source = "../../modules/dsql"
59+
60+
deletion_protection_enabled = false
61+
62+
tags = merge(local.tags, { Name = "single-region" })
63+
}

examples/dsql/outputs.tf

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
output "dsql_cluster_1_arn" {
2+
description = "ARN of the cluster"
3+
value = module.dsql_cluster_1.arn
4+
}
5+
6+
output "dsql_cluster_1_identifier" {
7+
description = "Cluster identifier"
8+
value = module.dsql_cluster_1.identifier
9+
}
10+
11+
output "dsql_cluster_1_encryption_details" {
12+
description = "Encryption configuration details for the DSQL cluster"
13+
value = module.dsql_cluster_1.encryption_details
14+
}
15+
16+
output "dsql_cluster_1_multi_region_properties" {
17+
description = "Multi-region properties of the DSQL cluster"
18+
value = module.dsql_cluster_1.multi_region_properties
19+
}
20+
21+
output "dsql_cluster_1_vpc_endpoint_service_name" {
22+
description = "The DSQL cluster's VPC endpoint service name"
23+
value = module.dsql_cluster_1.vpc_endpoint_service_name
24+
}
25+
26+
output "dsql_cluster_2_arn" {
27+
description = "ARN of the cluster"
28+
value = module.dsql_cluster_2.arn
29+
}
30+
31+
output "dsql_cluster_2_identifier" {
32+
description = "Cluster identifier"
33+
value = module.dsql_cluster_2.identifier
34+
}
35+
36+
output "dsql_cluster_2_encryption_details" {
37+
description = "Encryption configuration details for the DSQL cluster"
38+
value = module.dsql_cluster_2.encryption_details
39+
}
40+
41+
output "dsql_cluster_2_multi_region_properties" {
42+
description = "Multi-region properties of the DSQL cluster"
43+
value = module.dsql_cluster_2.multi_region_properties
44+
}
45+
46+
output "dsql_cluster_2_vpc_endpoint_service_name" {
47+
description = "The DSQL cluster's VPC endpoint service name"
48+
value = module.dsql_cluster_2.vpc_endpoint_service_name
49+
}

examples/dsql/variables.tf

Whitespace-only changes.

examples/dsql/versions.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 5.100"
8+
}
9+
}
10+
}

modules/dsql/README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# DSQL Cluster
2+
3+
Terraform sub-module which creates DSQL cluster and peering resources.
4+
5+
## Usage
6+
7+
See [DSQL](https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/tree/master/examples/dsql) directory for working examples to reference:
8+
9+
```hcl
10+
module "dsql_cluster_1" {
11+
source = "../../modules/dsql"
12+
13+
witness_region = "us-west-2"
14+
create_cluster_peering = true
15+
clusters = [module.dsql_cluster_2.arn]
16+
17+
tags = { Name = "dsql-1" }
18+
}
19+
20+
module "dsql_cluster_2" {
21+
source = "../../modules/dsql"
22+
23+
witness_region = "us-west-2"
24+
create_cluster_peering = true
25+
clusters = [module.dsql_cluster_1.arn]
26+
27+
tags = { Name = "dsql-2" }
28+
29+
providers = {
30+
aws = aws.region2
31+
}
32+
}
33+
```
34+
35+
<!-- BEGIN_TF_DOCS -->
36+
## Requirements
37+
38+
| Name | Version |
39+
|------|---------|
40+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
41+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.100 |
42+
43+
## Providers
44+
45+
| Name | Version |
46+
|------|---------|
47+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.100 |
48+
49+
## Modules
50+
51+
No modules.
52+
53+
## Resources
54+
55+
| Name | Type |
56+
|------|------|
57+
| [aws_dsql_cluster.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/dsql_cluster) | resource |
58+
| [aws_dsql_cluster_peering.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/dsql_cluster_peering) | resource |
59+
60+
## Inputs
61+
62+
| Name | Description | Type | Default | Required |
63+
|------|-------------|------|---------|:--------:|
64+
| <a name="input_clusters"></a> [clusters](#input\_clusters) | List of DSQL Cluster ARNs to be peered to this cluster | `list(string)` | `null` | no |
65+
| <a name="input_create"></a> [create](#input\_create) | Whether cluster should be created (affects all resources) | `bool` | `true` | no |
66+
| <a name="input_create_cluster_peering"></a> [create\_cluster\_peering](#input\_create\_cluster\_peering) | Whether to create cluster peering | `bool` | `false` | no |
67+
| <a name="input_deletion_protection_enabled"></a> [deletion\_protection\_enabled](#input\_deletion\_protection\_enabled) | Whether deletion protection is enabled in this cluster | `bool` | `null` | no |
68+
| <a name="input_kms_encryption_key"></a> [kms\_encryption\_key](#input\_kms\_encryption\_key) | The ARN of the AWS KMS key that encrypts data in the DSQL Cluster, or `AWS_OWNED_KMS_KEY` | `string` | `null` | no |
69+
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to be associated with the AWS DSQL Cluster resource | `map(string)` | `{}` | no |
70+
| <a name="input_timeouts"></a> [timeouts](#input\_timeouts) | Create timeout configuration for the cluster | `any` | `{}` | no |
71+
| <a name="input_witness_region"></a> [witness\_region](#input\_witness\_region) | Witness region for the multi-region clusters. Setting this makes this cluster a multi-region cluster. Changing it recreates the cluster | `string` | `null` | no |
72+
73+
## Outputs
74+
75+
| Name | Description |
76+
|------|-------------|
77+
| <a name="output_arn"></a> [arn](#output\_arn) | ARN of the cluster |
78+
| <a name="output_encryption_details"></a> [encryption\_details](#output\_encryption\_details) | Encryption configuration details for the DSQL cluster |
79+
| <a name="output_identifier"></a> [identifier](#output\_identifier) | Cluster identifier |
80+
| <a name="output_multi_region_properties"></a> [multi\_region\_properties](#output\_multi\_region\_properties) | Multi-region properties of the DSQL cluster |
81+
| <a name="output_vpc_endpoint_service_name"></a> [vpc\_endpoint\_service\_name](#output\_vpc\_endpoint\_service\_name) | The DSQL cluster's VPC endpoint service name |
82+
<!-- END_TF_DOCS -->

modules/dsql/main.tf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
resource "aws_dsql_cluster" "this" {
2+
count = var.create ? 1 : 0
3+
4+
deletion_protection_enabled = var.deletion_protection_enabled
5+
kms_encryption_key = var.kms_encryption_key
6+
7+
dynamic "multi_region_properties" {
8+
for_each = var.witness_region != null ? [true] : []
9+
content {
10+
witness_region = var.witness_region
11+
}
12+
}
13+
14+
tags = var.tags
15+
}
16+
17+
resource "aws_dsql_cluster_peering" "this" {
18+
count = var.create && var.create_cluster_peering ? 1 : 0
19+
20+
clusters = var.clusters
21+
identifier = aws_dsql_cluster.this[0].identifier
22+
witness_region = var.witness_region
23+
24+
timeouts {
25+
create = try(var.timeouts.create, null)
26+
}
27+
}

modules/dsql/outputs.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
output "arn" {
2+
description = "ARN of the cluster"
3+
value = try(aws_dsql_cluster.this[0].arn, null)
4+
}
5+
6+
output "identifier" {
7+
description = "Cluster identifier"
8+
value = try(aws_dsql_cluster.this[0].identifier, null)
9+
}
10+
11+
output "encryption_details" {
12+
description = "Encryption configuration details for the DSQL cluster"
13+
value = try(aws_dsql_cluster.this[0].encryption_details, null)
14+
}
15+
16+
output "multi_region_properties" {
17+
description = "Multi-region properties of the DSQL cluster"
18+
value = try(aws_dsql_cluster.this[0].multi_region_properties, null)
19+
}
20+
21+
output "vpc_endpoint_service_name" {
22+
description = "The DSQL cluster's VPC endpoint service name"
23+
value = try(aws_dsql_cluster.this[0].vpc_endpoint_service_name, null)
24+
}

0 commit comments

Comments
 (0)