Skip to content

Commit

Permalink
fix(variable): rename scheduler tag variable name
Browse files Browse the repository at this point in the history
Previously, I have revert this refactor because the former
variable name resource_tag was no longer working while waiting
for the fix.

This commit revert the revert and fix the bug which prevented
the use of the variable "resource_tag".
  • Loading branch information
diodonfrost committed Feb 26, 2021
1 parent 41a0e60 commit a2e0e2a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ module "start_ec2_instance" {
| kms_key_arn | The ARN for the KMS encryption key. If this configuration is not provided when environment variables are in use, AWS Lambda uses a default service key | string | null | no |
| aws_regions | A list of one or more aws regions where the lambda will be apply, default use the current region | list | null | no |
| cloudwatch_schedule_expression | The scheduling expression | string | `"cron(0 22 ? * MON-FRI *)"` | yes |
| schedule_action | Define schedule action to apply on resources | string | `"stop"` | yes |
| resources_tag | Set the tag use for identify resources to stop or start | map | { tostop = "true" } | yes |
| autoscaling_schedule | Enable scheduling on autoscaling resources | string | `"false"` | no |
| ec2_schedule | Enable scheduling on ec2 instance resources | string | `"false"` | no |
| rds_schedule | Enable scheduling on rds resources | string | `"false"` | no |
| cloudwatch_alarm_schedule | Enable scheduleding on cloudwatch alarm resources | string | `"false"` | no |
| schedule_action | Define schedule action to apply on resources | string | `"stop"` | yes |
| scheduler_tag | Set the tag to use for identify aws resources to stop or start | map | {"key" = "tostop", "value" = "true"} | yes |

## Outputs

Expand Down
4 changes: 2 additions & 2 deletions examples/autoscaling-scheduler/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ module "autoscaling-stop-friday" {
autoscaling_schedule = "true"
cloudwatch_alarm_schedule = "true"

resources_tag = {
scheduler_tag = {
key = "tostop"
value = "true"
}
Expand All @@ -114,7 +114,7 @@ module "autoscaling-start-monday" {
autoscaling_schedule = "true"
cloudwatch_alarm_schedule = "true"

resources_tag = {
scheduler_tag = {
key = "tostop"
value = "true"
}
Expand Down
4 changes: 2 additions & 2 deletions examples/instance-scheduler/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module "ec2-stop-friday" {
autoscaling_schedule = "false"
cloudwatch_alarm_schedule = "true"

resources_tag = {
scheduler_tag = {
key = "tostop"
value = "true"
}
Expand All @@ -63,7 +63,7 @@ module "ec2-start-monday" {
autoscaling_schedule = "false"
cloudwatch_alarm_schedule = "true"

resources_tag = {
scheduler_tag = {
key = "tostop"
value = "true"
}
Expand Down
4 changes: 2 additions & 2 deletions examples/rds-scheduler/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ module "rds-stop-friday" {
autoscaling_schedule = "false"
cloudwatch_alarm_schedule = "true"

resources_tag = {
scheduler_tag = {
key = "tostop"
value = "true"
}
Expand All @@ -120,7 +120,7 @@ module "rds-start-monday" {
autoscaling_schedule = "false"
cloudwatch_alarm_schedule = "true"

resources_tag = {
scheduler_tag = {
key = "tostop"
value = "true"
}
Expand Down
4 changes: 2 additions & 2 deletions examples/test_fixture/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module "aws-stop-friday" {
ec2_schedule = "true"
rds_schedule = "true"

resources_tag = {
scheduler_tag = {
key = "tostop"
value = "true"
}
Expand All @@ -30,7 +30,7 @@ module "aws-start-monday" {
ec2_schedule = "true"
rds_schedule = "true"

resources_tag = {
scheduler_tag = {
key = "tostop"
value = "true"
}
Expand Down
8 changes: 5 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ locals {
}
]
}
# Backward compatibility with the former scheduler variable name.
scheduler_tag = var.resources_tag == null ? var.scheduler_tag : var.resources_tag
}

################################################
Expand All @@ -222,7 +224,7 @@ locals {
data "archive_file" "this" {
type = "zip"
source_dir = "${path.module}/package/"
output_path = "${path.module}/aws-stop-start-resources-3.1.2.zip" # The version should match with the latest git tag
output_path = "${path.module}/aws-stop-start-resources-3.1.3.zip" # The version should match with the latest git tag
}

# Create Lambda function for stop or start aws resources
Expand All @@ -239,8 +241,8 @@ resource "aws_lambda_function" "this" {
variables = {
AWS_REGIONS = var.aws_regions == null ? data.aws_region.current.name : join(", ", var.aws_regions)
SCHEDULE_ACTION = var.schedule_action
TAG_KEY = var.resources_tag["key"]
TAG_VALUE = var.resources_tag["value"]
TAG_KEY = local.scheduler_tag["key"]
TAG_VALUE = local.scheduler_tag["value"]
EC2_SCHEDULE = tostring(var.ec2_schedule)
RDS_SCHEDULE = tostring(var.rds_schedule)
AUTOSCALING_SCHEDULE = tostring(var.autoscaling_schedule)
Expand Down
13 changes: 10 additions & 3 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,19 @@ variable "schedule_action" {
}

variable "resources_tag" {
description = "Set the tag use for identify resources to stop or start"
# This variable has been renamed to "scheduler_tag"
description = "DEPRECATED, use scheduler_tag variable instead"
type = map(string)
default = null
}

variable "scheduler_tag" {
description = "Set the tag to use for identify aws resources to stop or start"
type = map(string)

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

Expand Down

0 comments on commit a2e0e2a

Please sign in to comment.