Skip to content

Commit 783c686

Browse files
authored
feat: Add RDS cluster activity stream (terraform-aws-modules#407)
* add db_cluster_activity_stream * add ouptuts --------- Co-authored-by: magreenbaum <magreenbaum>
1 parent 87e05fb commit 783c686

File tree

10 files changed

+155
-0
lines changed

10 files changed

+155
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ No modules.
248248
| [aws_iam_role.rds_enhanced_monitoring](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
249249
| [aws_iam_role_policy_attachment.rds_enhanced_monitoring](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
250250
| [aws_rds_cluster.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster) | resource |
251+
| [aws_rds_cluster_activity_stream.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster_activity_stream) | resource |
251252
| [aws_rds_cluster_endpoint.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster_endpoint) | resource |
252253
| [aws_rds_cluster_instance.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster_instance) | resource |
253254
| [aws_rds_cluster_parameter_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster_parameter_group) | resource |
@@ -286,12 +287,15 @@ No modules.
286287
| <a name="input_copy_tags_to_snapshot"></a> [copy\_tags\_to\_snapshot](#input\_copy\_tags\_to\_snapshot) | Copy all Cluster `tags` to snapshots | `bool` | `null` | no |
287288
| <a name="input_create"></a> [create](#input\_create) | Whether cluster should be created (affects nearly all resources) | `bool` | `true` | no |
288289
| <a name="input_create_cloudwatch_log_group"></a> [create\_cloudwatch\_log\_group](#input\_create\_cloudwatch\_log\_group) | Determines whether a CloudWatch log group is created for each `enabled_cloudwatch_logs_exports` | `bool` | `false` | no |
290+
| <a name="input_create_db_cluster_activity_stream"></a> [create\_db\_cluster\_activity\_stream](#input\_create\_db\_cluster\_activity\_stream) | Determines whether a cluster activity stream is created. | `bool` | `false` | no |
289291
| <a name="input_create_db_cluster_parameter_group"></a> [create\_db\_cluster\_parameter\_group](#input\_create\_db\_cluster\_parameter\_group) | Determines whether a cluster parameter should be created or use existing | `bool` | `false` | no |
290292
| <a name="input_create_db_parameter_group"></a> [create\_db\_parameter\_group](#input\_create\_db\_parameter\_group) | Determines whether a DB parameter should be created or use existing | `bool` | `false` | no |
291293
| <a name="input_create_db_subnet_group"></a> [create\_db\_subnet\_group](#input\_create\_db\_subnet\_group) | Determines whether to create the database subnet group or use existing | `bool` | `false` | no |
292294
| <a name="input_create_monitoring_role"></a> [create\_monitoring\_role](#input\_create\_monitoring\_role) | Determines whether to create the IAM role for RDS enhanced monitoring | `bool` | `true` | no |
293295
| <a name="input_create_security_group"></a> [create\_security\_group](#input\_create\_security\_group) | Determines whether to create security group for RDS cluster | `bool` | `true` | no |
294296
| <a name="input_database_name"></a> [database\_name](#input\_database\_name) | Name for an automatically created database on cluster creation | `string` | `null` | no |
297+
| <a name="input_db_cluster_activity_stream_kms_key_id"></a> [db\_cluster\_activity\_stream\_kms\_key\_id](#input\_db\_cluster\_activity\_stream\_kms\_key\_id) | The AWS KMS key identifier for encrypting messages in the database activity stream | `string` | `null` | no |
298+
| <a name="input_db_cluster_activity_stream_mode"></a> [db\_cluster\_activity\_stream\_mode](#input\_db\_cluster\_activity\_stream\_mode) | Specifies the mode of the database activity stream. Database events such as a change or access generate an activity stream event. One of: sync, async | `string` | `null` | no |
295299
| <a name="input_db_cluster_db_instance_parameter_group_name"></a> [db\_cluster\_db\_instance\_parameter\_group\_name](#input\_db\_cluster\_db\_instance\_parameter\_group\_name) | Instance parameter group to associate with all instances of the DB cluster. The `db_cluster_db_instance_parameter_group_name` is only valid in combination with `allow_major_version_upgrade` | `string` | `null` | no |
296300
| <a name="input_db_cluster_instance_class"></a> [db\_cluster\_instance\_class](#input\_db\_cluster\_instance\_class) | The compute and memory capacity of each DB instance in the Multi-AZ DB cluster, for example db.m6g.xlarge. Not all DB instance classes are available in all AWS Regions, or for all database engines | `string` | `null` | no |
297301
| <a name="input_db_cluster_parameter_group_description"></a> [db\_cluster\_parameter\_group\_description](#input\_db\_cluster\_parameter\_group\_description) | The description of the DB cluster parameter group. Defaults to "Managed by Terraform" | `string` | `null` | no |
@@ -312,6 +316,7 @@ No modules.
312316
| <a name="input_endpoints"></a> [endpoints](#input\_endpoints) | Map of additional cluster endpoints and their attributes to be created | `any` | `{}` | no |
313317
| <a name="input_engine"></a> [engine](#input\_engine) | The name of the database engine to be used for this DB cluster. Defaults to `aurora`. Valid Values: `aurora`, `aurora-mysql`, `aurora-postgresql` | `string` | `null` | no |
314318
| <a name="input_engine_mode"></a> [engine\_mode](#input\_engine\_mode) | The database engine mode. Valid values: `global`, `multimaster`, `parallelquery`, `provisioned`, `serverless`. Defaults to: `provisioned` | `string` | `"provisioned"` | no |
319+
| <a name="input_engine_native_audit_fields_included"></a> [engine\_native\_audit\_fields\_included](#input\_engine\_native\_audit\_fields\_included) | Specifies whether the database activity stream includes engine-native audit fields. This option only applies to an Oracle DB instance. By default, no engine-native audit fields are included | `bool` | `false` | no |
315320
| <a name="input_engine_version"></a> [engine\_version](#input\_engine\_version) | The database engine version. Updating this argument results in an outage | `string` | `null` | no |
316321
| <a name="input_final_snapshot_identifier"></a> [final\_snapshot\_identifier](#input\_final\_snapshot\_identifier) | The name of your final DB snapshot when this DB cluster is deleted. If omitted, no final snapshot will be made | `string` | `null` | no |
317322
| <a name="input_global_cluster_identifier"></a> [global\_cluster\_identifier](#input\_global\_cluster\_identifier) | The global cluster identifier specified on `aws_rds_global_cluster` | `string` | `null` | no |
@@ -389,6 +394,7 @@ No modules.
389394
| <a name="output_cluster_reader_endpoint"></a> [cluster\_reader\_endpoint](#output\_cluster\_reader\_endpoint) | A read-only endpoint for the cluster, automatically load-balanced across replicas |
390395
| <a name="output_cluster_resource_id"></a> [cluster\_resource\_id](#output\_cluster\_resource\_id) | The RDS Cluster Resource ID |
391396
| <a name="output_cluster_role_associations"></a> [cluster\_role\_associations](#output\_cluster\_role\_associations) | A map of IAM roles associated with the cluster and their attributes |
397+
| <a name="output_db_cluster_activity_stream_kinesis_stream_name"></a> [db\_cluster\_activity\_stream\_kinesis\_stream\_name](#output\_db\_cluster\_activity\_stream\_kinesis\_stream\_name) | The name of the Amazon Kinesis data stream to be used for the database activity stream |
392398
| <a name="output_db_cluster_cloudwatch_log_groups"></a> [db\_cluster\_cloudwatch\_log\_groups](#output\_db\_cluster\_cloudwatch\_log\_groups) | Map of CloudWatch log groups created and their attributes |
393399
| <a name="output_db_cluster_parameter_group_arn"></a> [db\_cluster\_parameter\_group\_arn](#output\_db\_cluster\_parameter\_group\_arn) | The ARN of the DB cluster parameter group created |
394400
| <a name="output_db_cluster_parameter_group_id"></a> [db\_cluster\_parameter\_group\_id](#output\_db\_cluster\_parameter\_group\_id) | The ID of the DB cluster parameter group created |

examples/mysql/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ Note that this example may create resources which cost money. Run `terraform des
3333
| Name | Source | Version |
3434
|------|--------|---------|
3535
| <a name="module_aurora"></a> [aurora](#module\_aurora) | ../../ | n/a |
36+
| <a name="module_kms"></a> [kms](#module\_kms) | terraform-aws-modules/kms/aws | ~> 2.0 |
3637
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 |
38+
| <a name="module_vpc_endpoints"></a> [vpc\_endpoints](#module\_vpc\_endpoints) | terraform-aws-modules/vpc/aws//modules/vpc-endpoints | ~> 5.0 |
3739

3840
## Resources
3941

@@ -63,6 +65,7 @@ No inputs.
6365
| <a name="output_cluster_reader_endpoint"></a> [cluster\_reader\_endpoint](#output\_cluster\_reader\_endpoint) | A read-only endpoint for the cluster, automatically load-balanced across replicas |
6466
| <a name="output_cluster_resource_id"></a> [cluster\_resource\_id](#output\_cluster\_resource\_id) | The RDS Cluster Resource ID |
6567
| <a name="output_cluster_role_associations"></a> [cluster\_role\_associations](#output\_cluster\_role\_associations) | A map of IAM roles associated with the cluster and their attributes |
68+
| <a name="output_db_cluster_activity_stream_kinesis_stream_name"></a> [db\_cluster\_activity\_stream\_kinesis\_stream\_name](#output\_db\_cluster\_activity\_stream\_kinesis\_stream\_name) | The name of the Amazon Kinesis data stream to be used for the database activity stream |
6669
| <a name="output_db_cluster_cloudwatch_log_groups"></a> [db\_cluster\_cloudwatch\_log\_groups](#output\_db\_cluster\_cloudwatch\_log\_groups) | Map of CloudWatch log groups created and their attributes |
6770
| <a name="output_db_cluster_parameter_group_arn"></a> [db\_cluster\_parameter\_group\_arn](#output\_db\_cluster\_parameter\_group\_arn) | The ARN of the DB cluster parameter group created |
6871
| <a name="output_db_cluster_parameter_group_id"></a> [db\_cluster\_parameter\_group\_id](#output\_db\_cluster\_parameter\_group\_id) | The ID of the DB cluster parameter group created |

examples/mysql/main.tf

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ module "aurora" {
5151
vpc_ingress = {
5252
cidr_blocks = module.vpc.private_subnets_cidr_blocks
5353
}
54+
kms_vpc_endpoint = {
55+
type = "egress"
56+
from_port = 443
57+
to_port = 443
58+
source_security_group_id = module.vpc_endpoints.security_group_id
59+
}
5460
}
5561

5662
apply_immediately = true
@@ -142,6 +148,12 @@ module "aurora" {
142148

143149
enabled_cloudwatch_logs_exports = ["audit", "error", "general", "slowquery"]
144150

151+
create_db_cluster_activity_stream = true
152+
db_cluster_activity_stream_kms_key_id = module.kms.key_id
153+
154+
# https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/DBActivityStreams.Overview.html#DBActivityStreams.Overview.sync-mode
155+
db_cluster_activity_stream_mode = "async"
156+
145157
tags = local.tags
146158
}
147159

@@ -163,3 +175,46 @@ module "vpc" {
163175

164176
tags = local.tags
165177
}
178+
179+
module "kms" {
180+
source = "terraform-aws-modules/kms/aws"
181+
version = "~> 2.0"
182+
183+
deletion_window_in_days = 7
184+
description = "KMS key for ${local.name} cluster activity stream."
185+
enable_key_rotation = true
186+
is_enabled = true
187+
key_usage = "ENCRYPT_DECRYPT"
188+
189+
aliases = [local.name]
190+
191+
tags = local.tags
192+
}
193+
194+
# https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/DBActivityStreams.Prereqs.html#DBActivityStreams.Prereqs.KMS
195+
module "vpc_endpoints" {
196+
source = "terraform-aws-modules/vpc/aws//modules/vpc-endpoints"
197+
version = "~> 5.0"
198+
199+
vpc_id = module.vpc.vpc_id
200+
201+
create_security_group = true
202+
security_group_name_prefix = "${local.name}-vpc-endpoints-"
203+
security_group_description = "VPC endpoint security group"
204+
security_group_rules = {
205+
ingress_https = {
206+
description = "HTTPS from VPC"
207+
cidr_blocks = [module.vpc.vpc_cidr_block]
208+
}
209+
}
210+
211+
endpoints = {
212+
kms = {
213+
service = "kms"
214+
private_dns_enabled = true
215+
subnet_ids = module.vpc.database_subnets
216+
}
217+
}
218+
219+
tags = local.tags
220+
}

examples/mysql/outputs.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,12 @@ output "db_cluster_cloudwatch_log_groups" {
157157
description = "Map of CloudWatch log groups created and their attributes"
158158
value = module.aurora.db_cluster_cloudwatch_log_groups
159159
}
160+
161+
################################################################################
162+
# Cluster Activity Stream
163+
################################################################################
164+
165+
output "db_cluster_activity_stream_kinesis_stream_name" {
166+
description = "The name of the Amazon Kinesis data stream to be used for the database activity stream"
167+
value = module.aurora.db_cluster_activity_stream_kinesis_stream_name
168+
}

examples/postgresql/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Note that this example may create resources which cost money. Run `terraform des
3333
| Name | Source | Version |
3434
|------|--------|---------|
3535
| <a name="module_aurora"></a> [aurora](#module\_aurora) | ../../ | n/a |
36+
| <a name="module_kms"></a> [kms](#module\_kms) | terraform-aws-modules/kms/aws | ~> 2.0 |
3637
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 |
3738

3839
## Resources
@@ -63,6 +64,7 @@ No inputs.
6364
| <a name="output_cluster_reader_endpoint"></a> [cluster\_reader\_endpoint](#output\_cluster\_reader\_endpoint) | A read-only endpoint for the cluster, automatically load-balanced across replicas |
6465
| <a name="output_cluster_resource_id"></a> [cluster\_resource\_id](#output\_cluster\_resource\_id) | The RDS Cluster Resource ID |
6566
| <a name="output_cluster_role_associations"></a> [cluster\_role\_associations](#output\_cluster\_role\_associations) | A map of IAM roles associated with the cluster and their attributes |
67+
| <a name="output_db_cluster_activity_stream_kinesis_stream_name"></a> [db\_cluster\_activity\_stream\_kinesis\_stream\_name](#output\_db\_cluster\_activity\_stream\_kinesis\_stream\_name) | The name of the Amazon Kinesis data stream to be used for the database activity stream |
6668
| <a name="output_db_cluster_cloudwatch_log_groups"></a> [db\_cluster\_cloudwatch\_log\_groups](#output\_db\_cluster\_cloudwatch\_log\_groups) | Map of CloudWatch log groups created and their attributes |
6769
| <a name="output_db_cluster_parameter_group_arn"></a> [db\_cluster\_parameter\_group\_arn](#output\_db\_cluster\_parameter\_group\_arn) | The ARN of the DB cluster parameter group created |
6870
| <a name="output_db_cluster_parameter_group_id"></a> [db\_cluster\_parameter\_group\_id](#output\_db\_cluster\_parameter\_group\_id) | The ID of the DB cluster parameter group created |

examples/postgresql/main.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ module "aurora" {
108108
enabled_cloudwatch_logs_exports = ["postgresql"]
109109
create_cloudwatch_log_group = true
110110

111+
create_db_cluster_activity_stream = true
112+
db_cluster_activity_stream_kms_key_id = module.kms.key_id
113+
db_cluster_activity_stream_mode = "async"
114+
111115
tags = local.tags
112116
}
113117

@@ -129,3 +133,18 @@ module "vpc" {
129133

130134
tags = local.tags
131135
}
136+
137+
module "kms" {
138+
source = "terraform-aws-modules/kms/aws"
139+
version = "~> 2.0"
140+
141+
deletion_window_in_days = 7
142+
description = "KMS key for ${local.name} cluster activity stream."
143+
enable_key_rotation = true
144+
is_enabled = true
145+
key_usage = "ENCRYPT_DECRYPT"
146+
147+
aliases = [local.name]
148+
149+
tags = local.tags
150+
}

examples/postgresql/outputs.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,12 @@ output "db_cluster_cloudwatch_log_groups" {
157157
description = "Map of CloudWatch log groups created and their attributes"
158158
value = module.aurora.db_cluster_cloudwatch_log_groups
159159
}
160+
161+
################################################################################
162+
# Cluster Activity Stream
163+
################################################################################
164+
165+
output "db_cluster_activity_stream_kinesis_stream_name" {
166+
description = "The name of the Amazon Kinesis data stream to be used for the database activity stream"
167+
value = module.aurora.db_cluster_activity_stream_kinesis_stream_name
168+
}

main.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,3 +412,18 @@ resource "aws_cloudwatch_log_group" "this" {
412412

413413
tags = var.tags
414414
}
415+
416+
################################################################################
417+
# Cluster Activity Stream
418+
################################################################################
419+
420+
resource "aws_rds_cluster_activity_stream" "this" {
421+
count = local.create && var.create_db_cluster_activity_stream ? 1 : 0
422+
423+
resource_arn = aws_rds_cluster.this[0].arn
424+
mode = var.db_cluster_activity_stream_mode
425+
kms_key_id = var.db_cluster_activity_stream_kms_key_id
426+
engine_native_audit_fields_included = var.engine_native_audit_fields_included
427+
428+
depends_on = [aws_rds_cluster_instance.this]
429+
}

outputs.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,12 @@ output "db_cluster_cloudwatch_log_groups" {
170170
description = "Map of CloudWatch log groups created and their attributes"
171171
value = aws_cloudwatch_log_group.this
172172
}
173+
174+
################################################################################
175+
# Cluster Activity Stream
176+
################################################################################
177+
178+
output "db_cluster_activity_stream_kinesis_stream_name" {
179+
description = "The name of the Amazon Kinesis data stream to be used for the database activity stream"
180+
value = try(aws_rds_cluster_activity_stream.this[0].kinesis_stream_name, null)
181+
}

variables.tf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,3 +683,31 @@ variable "cloudwatch_log_group_kms_key_id" {
683683
type = string
684684
default = null
685685
}
686+
687+
################################################################################
688+
# Cluster Activity Stream
689+
################################################################################
690+
691+
variable "create_db_cluster_activity_stream" {
692+
description = "Determines whether a cluster activity stream is created."
693+
type = bool
694+
default = false
695+
}
696+
697+
variable "db_cluster_activity_stream_mode" {
698+
description = "Specifies the mode of the database activity stream. Database events such as a change or access generate an activity stream event. One of: sync, async"
699+
type = string
700+
default = null
701+
}
702+
703+
variable "db_cluster_activity_stream_kms_key_id" {
704+
description = "The AWS KMS key identifier for encrypting messages in the database activity stream"
705+
type = string
706+
default = null
707+
}
708+
709+
variable "engine_native_audit_fields_included" {
710+
description = "Specifies whether the database activity stream includes engine-native audit fields. This option only applies to an Oracle DB instance. By default, no engine-native audit fields are included"
711+
type = bool
712+
default = false
713+
}

0 commit comments

Comments
 (0)