Skip to content

Commit

Permalink
optionally specify event_bus_name
Browse files Browse the repository at this point in the history
  • Loading branch information
wakumaku committed Mar 11, 2021
1 parent 8061468 commit 4c70ef0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 58 deletions.
69 changes: 11 additions & 58 deletions event.tf
Original file line number Diff line number Diff line change
@@ -1,72 +1,25 @@
locals {
action_start = "start"
action_stop = "stop"
action_terminate = "terminate"
action_reboot = "reboot"
action_switch = "switch"
schedule_types = [
"start",
"stop",
"terminate",
"reboot",
"switch",
]
}

module "event_start" {
source = "./event"
for_each = { for st in local.schedule_types : st => st }
source = "./event"

prefix = var.prefix
schedules = var.schedules.start
schedule_type = local.action_start
schedule_type = each.value
instance_list = var.instance_list
lambda_arn = aws_lambda_function.instanceswitcher.arn
lambda_name = aws_lambda_function.instanceswitcher.function_name

tags = local.tags_base
}

module "event_stop" {
source = "./event"

prefix = var.prefix
schedules = var.schedules.stop
schedule_type = local.action_stop
instance_list = var.instance_list
lambda_arn = aws_lambda_function.instanceswitcher.arn
lambda_name = aws_lambda_function.instanceswitcher.function_name

tags = local.tags_base
}

module "event_reboot" {
source = "./event"

prefix = var.prefix
schedules = var.schedules.reboot
schedule_type = local.action_reboot
instance_list = var.instance_list
lambda_arn = aws_lambda_function.instanceswitcher.arn
lambda_name = aws_lambda_function.instanceswitcher.function_name

tags = local.tags_base
}

module "event_terminate" {
source = "./event"

prefix = var.prefix
schedules = var.schedules.terminate
schedule_type = local.action_terminate
instance_list = var.instance_list
lambda_arn = aws_lambda_function.instanceswitcher.arn
lambda_name = aws_lambda_function.instanceswitcher.function_name

tags = local.tags_base
}

module "event_switch" {
source = "./event"

prefix = var.prefix
schedules = var.schedules.switch
schedule_type = local.action_switch
instance_list = var.instance_list
lambda_arn = aws_lambda_function.instanceswitcher.arn
lambda_name = aws_lambda_function.instanceswitcher.function_name
event_bus_name = var.event_bus_name

tags = local.tags_base
}
5 changes: 5 additions & 0 deletions event/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ variable "schedules" {}
variable "instance_list" {}
variable "lambda_arn" {}
variable "lambda_name" {}
variable "event_bus_name" {
default = null
}
variable "tags" {}

resource "aws_cloudwatch_event_rule" "instanceswitcher" {
Expand All @@ -12,6 +15,8 @@ resource "aws_cloudwatch_event_rule" "instanceswitcher" {
description = "Instance Switcher rule: ${var.schedule_type} [${count.index}]"
schedule_expression = "cron(${var.schedules[count.index]})"

event_bus_name = var.event_bus_name

tags = var.tags
}

Expand Down
5 changes: 5 additions & 0 deletions input.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ variable "policies_path" {
default = "/"
}

variable "event_bus_name" {
description = "The event bus to associate with the created rules. If you omit this, the default event bus is used."
default = null
}

variable "tags" {
description = "Custom tags to be added to the created resources"
type = map(string)
Expand Down

0 comments on commit 4c70ef0

Please sign in to comment.