Skip to content

Commit

Permalink
tests(documentdb): add an example of docdb scheduler
Browse files Browse the repository at this point in the history
This commit introduces a new test for the documentdb module,
specifically focusing on the addition of an example for the docdb
scheduler. The test is designed to validate the functionality and
reliability of the scheduler, ensuring that it performs as expected and
meets the required specifications.
  • Loading branch information
diodonfrost committed Jun 8, 2023
1 parent 17f2a85 commit 7f8a896
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
78 changes: 78 additions & 0 deletions examples/documentdb-scheduler/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Deploy two lambda for testing with awspec

resource "aws_kms_key" "scheduler" {
description = "test kms option on scheduler module"
deletion_window_in_days = 7
}

resource "aws_docdb_cluster" "scheduled" {
cluster_identifier = "docdb-cluster-scheduled"
engine = "docdb"
master_username = "foo"
master_password = "mustbeeightchars"
skip_final_snapshot = true
tags = {
tostop = "true"
terratest_tag = var.random_tag
}
}

resource "aws_docdb_cluster_instance" "scheduled" {
identifier = "docdb-instance-scheduled"
cluster_identifier = aws_docdb_cluster.scheduled.id
instance_class = "db.r5.large"
tags = {
tostop = "true"
terratest_tag = var.random_tag
}
}

resource "aws_docdb_cluster" "not_scheduled" {
cluster_identifier = "docdb-cluster-not-scheduled"
engine = "docdb"
master_username = "foo"
master_password = "mustbeeightchars"
skip_final_snapshot = true
tags = {
tostop = "false"
terratest_tag = var.random_tag
}
}

resource "aws_docdb_cluster_instance" "not_scheduled" {
identifier = "docdb-instance-not-scheduled"
cluster_identifier = aws_docdb_cluster.not_scheduled.id
instance_class = "db.r5.large"
tags = {
tostop = "false"
terratest_tag = var.random_tag
}
}


module "documentdb-stop-friday" {
source = "../.."
name = "stop-documentdb"
kms_key_arn = aws_kms_key.scheduler.arn
cloudwatch_schedule_expression = "cron(0 23 ? * FRI *)"
schedule_action = "stop"
documentdb_schedule = "true"

scheduler_tag = {
key = "tostop"
value = "true"
}
}

module "documentdb-start-monday" {
source = "../.."
name = "start-documentdb"
cloudwatch_schedule_expression = "cron(0 07 ? * MON *)"
schedule_action = "start"
documentdb_schedule = "true"

scheduler_tag = {
key = "tostop"
value = "true"
}
}
17 changes: 17 additions & 0 deletions examples/documentdb-scheduler/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Terraform documentdb-scheduler outputs

output "lambda_stop_name" {
value = module.documentdb-stop-friday.scheduler_lambda_name
}

output "lambda_stop_arn" {
value = module.documentdb-stop-friday.scheduler_lambda_arn
}

output "lambda_start_name" {
value = module.documentdb-start-monday.scheduler_lambda_name
}

output "lambda_start_arn" {
value = module.documentdb-start-monday.scheduler_lambda_arn
}
4 changes: 4 additions & 0 deletions examples/documentdb-scheduler/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "random_tag" {
description = "aws tag use during integration tests"
default = "terratest_random_tag"
}

0 comments on commit 7f8a896

Please sign in to comment.