Skip to content

Commit c280e4c

Browse files
committed
feat: Update DSQL sub-module and example
1 parent 1e835c1 commit c280e4c

File tree

7 files changed

+84
-34
lines changed

7 files changed

+84
-34
lines changed

docs/UPGRADE-10.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ If you find a bug, please open an issue with supporting configuration to reprodu
88
- Terraform `v1.11` is now minimum supported version to support write-only (`wo_*`) attributes.
99
- AWS provider `v6.18` is now minimum supported version
1010
- The underlying `aws_security_group_rule` resources has been replaced with `aws_vpc_security_group_ingress_rule` and `aws_vpc_security_group_egress_rule` to allow for more flexibility in defining security group rules.
11-
- `master_password` is no longer supported and only the write-only equivalent is supported (`master_password_wo` and `master_password_wo_version`).
11+
- `master_password` is no longer supported and only the write-only equivalent is supported (`master_password_wo` and `master_password_wo_version`) ([#513](https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/pull/513))
1212

1313
## Additional changes
1414

examples/dsql/main.tf

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ provider "aws" {
55
locals {
66
name = "ex-${basename(path.cwd)}"
77
region = "us-east-1"
8-
region2 = "us-east-2"
98
witness_region = "us-west-2"
109

1110
tags = {
@@ -22,35 +21,46 @@ locals {
2221
module "dsql_cluster_1" {
2322
source = "../../modules/dsql"
2423

24+
name = "${local.name}-1"
25+
26+
# For example only
2527
deletion_protection_enabled = false
26-
witness_region = local.witness_region
27-
create_cluster_peering = true
28-
clusters = [module.dsql_cluster_2.arn]
28+
29+
witness_region = local.witness_region
30+
create_cluster_peering = true
31+
clusters = [module.dsql_cluster_2.arn]
2932

3033
timeouts = {
3134
create = "1h"
3235
}
3336

34-
tags = merge(local.tags, { Name = local.name })
37+
tags = local.tags
3538
}
3639

3740
module "dsql_cluster_2" {
3841
source = "../../modules/dsql"
3942

40-
region = local.region2
43+
region = local.witness_region
4144

45+
name = "${local.name}-2"
46+
47+
# For example only
4248
deletion_protection_enabled = false
43-
witness_region = local.witness_region
44-
create_cluster_peering = true
45-
clusters = [module.dsql_cluster_1.arn]
49+
50+
witness_region = local.region
51+
create_cluster_peering = true
52+
clusters = [module.dsql_cluster_1.arn]
4653

4754
tags = merge(local.tags, { Name = local.name })
4855
}
4956

5057
module "dsql_single_region" {
5158
source = "../../modules/dsql"
5259

60+
name = local.name
61+
62+
# For example only
5363
deletion_protection_enabled = false
5464

55-
tags = merge(local.tags, { Name = "single-region" })
65+
tags = local.tags
5666
}

modules/dsql/README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# DSQL Cluster
1+
# AWS RDS Aurora DSQL Terraform module
22

3-
Terraform sub-module which creates DSQL cluster and peering resources.
3+
Terraform sub-module which creates DSQL resources.
44

55
## Usage
66

@@ -10,25 +10,31 @@ See [DSQL](https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/tre
1010
module "dsql_cluster_1" {
1111
source = "../../modules/dsql"
1212
13-
witness_region = "us-west-2"
13+
name = "dsql-1"
14+
15+
witness_region = "us-east-2"
1416
create_cluster_peering = true
1517
clusters = [module.dsql_cluster_2.arn]
1618
17-
tags = { Name = "dsql-1" }
19+
tags = {
20+
Environment = "production"
21+
}
1822
}
1923
2024
module "dsql_cluster_2" {
2125
source = "../../modules/dsql"
2226
27+
region = "us-east-2"
28+
29+
name = "dsql-2"
30+
2331
witness_region = "us-west-2"
2432
create_cluster_peering = true
2533
clusters = [module.dsql_cluster_1.arn]
2634
27-
tags = { Name = "dsql-2" }
28-
29-
providers = {
30-
aws = aws.region2
31-
}
35+
tags = {
36+
Environment = "production"
37+
}
3238
}
3339
```
3440

@@ -66,9 +72,10 @@ No modules.
6672
| <a name="input_create_cluster_peering"></a> [create\_cluster\_peering](#input\_create\_cluster\_peering) | Whether to create cluster peering | `bool` | `false` | no |
6773
| <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 |
6874
| <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 |
75+
| <a name="input_name"></a> [name](#input\_name) | Name used across resources created | `string` | `""` | no |
6976
| <a name="input_region"></a> [region](#input\_region) | Region where the resource(s) will be managed. Defaults to the Region set in the provider configuration | `string` | `null` | no |
70-
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to be associated with the AWS DSQL Cluster resource | `map(string)` | `{}` | no |
71-
| <a name="input_timeouts"></a> [timeouts](#input\_timeouts) | Create timeout configuration for the cluster | `any` | `{}` | no |
77+
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no |
78+
| <a name="input_timeouts"></a> [timeouts](#input\_timeouts) | Timeout configuration for the cluster | <pre>object({<br/> create = optional(string)<br/> })</pre> | `null` | no |
7279
| <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 |
7380

7481
## Outputs

modules/dsql/main.tf

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
################################################################################
2+
# Cluster
3+
################################################################################
4+
15
resource "aws_dsql_cluster" "this" {
26
count = var.create ? 1 : 0
37

@@ -8,14 +12,22 @@ resource "aws_dsql_cluster" "this" {
812

913
dynamic "multi_region_properties" {
1014
for_each = var.witness_region != null ? [true] : []
15+
1116
content {
1217
witness_region = var.witness_region
1318
}
1419
}
1520

16-
tags = var.tags
21+
tags = merge(
22+
var.tags,
23+
{ for k, v in { Name = var.name } : k => v if v != "" }
24+
)
1725
}
1826

27+
################################################################################
28+
# Cluster Peering
29+
################################################################################
30+
1931
resource "aws_dsql_cluster_peering" "this" {
2032
count = var.create && var.create_cluster_peering ? 1 : 0
2133

@@ -26,6 +38,6 @@ resource "aws_dsql_cluster_peering" "this" {
2638
witness_region = var.witness_region
2739

2840
timeouts {
29-
create = try(var.timeouts.create, null)
41+
create = var.timeouts.create
3042
}
3143
}

modules/dsql/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
################################################################################
2+
# Cluster
3+
################################################################################
4+
15
output "arn" {
26
description = "ARN of the cluster"
37
value = try(aws_dsql_cluster.this[0].arn, null)

modules/dsql/variables.tf

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@ variable "region" {
1010
default = null
1111
}
1212

13+
variable "name" {
14+
description = "Name used across resources created"
15+
type = string
16+
default = ""
17+
}
18+
19+
variable "tags" {
20+
description = "A map of tags to add to all resources"
21+
type = map(string)
22+
default = {}
23+
}
24+
25+
################################################################################
26+
# Cluster
27+
################################################################################
28+
1329
variable "deletion_protection_enabled" {
1430
description = "Whether deletion protection is enabled in this cluster"
1531
type = bool
@@ -22,6 +38,10 @@ variable "kms_encryption_key" {
2238
default = null
2339
}
2440

41+
################################################################################
42+
# Cluster Peering
43+
################################################################################
44+
2545
variable "create_cluster_peering" {
2646
description = "Whether to create cluster peering"
2747
type = bool
@@ -41,13 +61,9 @@ variable "witness_region" {
4161
}
4262

4363
variable "timeouts" {
44-
description = "Create timeout configuration for the cluster"
45-
type = any
46-
default = {}
47-
}
48-
49-
variable "tags" {
50-
description = "A map of tags to be associated with the AWS DSQL Cluster resource"
51-
type = map(string)
52-
default = {}
64+
description = "Timeout configuration for the cluster"
65+
type = object({
66+
create = optional(string)
67+
})
68+
default = null
5369
}

wrappers/dsql/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ module "wrapper" {
88
create_cluster_peering = try(each.value.create_cluster_peering, var.defaults.create_cluster_peering, false)
99
deletion_protection_enabled = try(each.value.deletion_protection_enabled, var.defaults.deletion_protection_enabled, null)
1010
kms_encryption_key = try(each.value.kms_encryption_key, var.defaults.kms_encryption_key, null)
11+
name = try(each.value.name, var.defaults.name, "")
1112
region = try(each.value.region, var.defaults.region, null)
1213
tags = try(each.value.tags, var.defaults.tags, {})
13-
timeouts = try(each.value.timeouts, var.defaults.timeouts, {})
14+
timeouts = try(each.value.timeouts, var.defaults.timeouts, null)
1415
witness_region = try(each.value.witness_region, var.defaults.witness_region, null)
1516
}

0 commit comments

Comments
 (0)