Skip to content

Commit 1f412c5

Browse files
committed
feat/dsql
1 parent 592cb15 commit 1f412c5

File tree

10 files changed

+230
-0
lines changed

10 files changed

+230
-0
lines changed

examples/dsql/README.md

Whitespace-only changes.

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

Whitespace-only changes.

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+
}

modules/dsql/variables.tf

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
variable "create" {
2+
description = "Whether cluster should be created (affects all resources)"
3+
type = bool
4+
default = true
5+
}
6+
7+
variable "deletion_protection_enabled" {
8+
description = "Whether deletion protection is enabled in this cluster"
9+
type = bool
10+
default = null
11+
}
12+
13+
variable "kms_encryption_key" {
14+
description = "The ARN of the AWS KMS key that encrypts data in the DSQL Cluster, or `AWS_OWNED_KMS_KEY`"
15+
type = string
16+
default = null
17+
}
18+
19+
variable "create_cluster_peering" {
20+
description = "Whether to create cluster peering"
21+
type = bool
22+
default = false
23+
}
24+
25+
variable "clusters" {
26+
description = "List of DSQL Cluster ARNs to be peered to this cluster"
27+
type = list(string)
28+
default = null
29+
}
30+
31+
variable "witness_region" {
32+
description = "Witness region for the multi-region clusters. Setting this makes this cluster a multi-region cluster. Changing it recreates the cluster"
33+
type = string
34+
default = null
35+
}
36+
37+
variable "timeouts" {
38+
description = "Create timeout configuration for the cluster"
39+
type = any
40+
default = {}
41+
}
42+
43+
variable "tags" {
44+
description = "A map of tags to be associated with the AWS DSQL Cluster resource"
45+
type = map(string)
46+
default = {}
47+
}

modules/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+
}

0 commit comments

Comments
 (0)