Skip to content

Commit a2e0e2a

Browse files
committed
fix(variable): rename scheduler tag variable name
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".
1 parent 41a0e60 commit a2e0e2a

File tree

7 files changed

+25
-16
lines changed

7 files changed

+25
-16
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ module "start_ec2_instance" {
7070
| 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 |
7171
| aws_regions | A list of one or more aws regions where the lambda will be apply, default use the current region | list | null | no |
7272
| cloudwatch_schedule_expression | The scheduling expression | string | `"cron(0 22 ? * MON-FRI *)"` | yes |
73-
| schedule_action | Define schedule action to apply on resources | string | `"stop"` | yes |
74-
| resources_tag | Set the tag use for identify resources to stop or start | map | { tostop = "true" } | yes |
7573
| autoscaling_schedule | Enable scheduling on autoscaling resources | string | `"false"` | no |
7674
| ec2_schedule | Enable scheduling on ec2 instance resources | string | `"false"` | no |
7775
| rds_schedule | Enable scheduling on rds resources | string | `"false"` | no |
7876
| cloudwatch_alarm_schedule | Enable scheduleding on cloudwatch alarm resources | string | `"false"` | no |
77+
| schedule_action | Define schedule action to apply on resources | string | `"stop"` | yes |
78+
| scheduler_tag | Set the tag to use for identify aws resources to stop or start | map | {"key" = "tostop", "value" = "true"} | yes |
7979

8080
## Outputs
8181

examples/autoscaling-scheduler/main.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ module "autoscaling-stop-friday" {
9898
autoscaling_schedule = "true"
9999
cloudwatch_alarm_schedule = "true"
100100

101-
resources_tag = {
101+
scheduler_tag = {
102102
key = "tostop"
103103
value = "true"
104104
}
@@ -114,7 +114,7 @@ module "autoscaling-start-monday" {
114114
autoscaling_schedule = "true"
115115
cloudwatch_alarm_schedule = "true"
116116

117-
resources_tag = {
117+
scheduler_tag = {
118118
key = "tostop"
119119
value = "true"
120120
}

examples/instance-scheduler/main.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module "ec2-stop-friday" {
4747
autoscaling_schedule = "false"
4848
cloudwatch_alarm_schedule = "true"
4949

50-
resources_tag = {
50+
scheduler_tag = {
5151
key = "tostop"
5252
value = "true"
5353
}
@@ -63,7 +63,7 @@ module "ec2-start-monday" {
6363
autoscaling_schedule = "false"
6464
cloudwatch_alarm_schedule = "true"
6565

66-
resources_tag = {
66+
scheduler_tag = {
6767
key = "tostop"
6868
value = "true"
6969
}

examples/rds-scheduler/main.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ module "rds-stop-friday" {
104104
autoscaling_schedule = "false"
105105
cloudwatch_alarm_schedule = "true"
106106

107-
resources_tag = {
107+
scheduler_tag = {
108108
key = "tostop"
109109
value = "true"
110110
}
@@ -120,7 +120,7 @@ module "rds-start-monday" {
120120
autoscaling_schedule = "false"
121121
cloudwatch_alarm_schedule = "true"
122122

123-
resources_tag = {
123+
scheduler_tag = {
124124
key = "tostop"
125125
value = "true"
126126
}

examples/test_fixture/main.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module "aws-stop-friday" {
1515
ec2_schedule = "true"
1616
rds_schedule = "true"
1717

18-
resources_tag = {
18+
scheduler_tag = {
1919
key = "tostop"
2020
value = "true"
2121
}
@@ -30,7 +30,7 @@ module "aws-start-monday" {
3030
ec2_schedule = "true"
3131
rds_schedule = "true"
3232

33-
resources_tag = {
33+
scheduler_tag = {
3434
key = "tostop"
3535
value = "true"
3636
}

main.tf

+5-3
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ locals {
210210
}
211211
]
212212
}
213+
# Backward compatibility with the former scheduler variable name.
214+
scheduler_tag = var.resources_tag == null ? var.scheduler_tag : var.resources_tag
213215
}
214216

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

228230
# Create Lambda function for stop or start aws resources
@@ -239,8 +241,8 @@ resource "aws_lambda_function" "this" {
239241
variables = {
240242
AWS_REGIONS = var.aws_regions == null ? data.aws_region.current.name : join(", ", var.aws_regions)
241243
SCHEDULE_ACTION = var.schedule_action
242-
TAG_KEY = var.resources_tag["key"]
243-
TAG_VALUE = var.resources_tag["value"]
244+
TAG_KEY = local.scheduler_tag["key"]
245+
TAG_VALUE = local.scheduler_tag["value"]
244246
EC2_SCHEDULE = tostring(var.ec2_schedule)
245247
RDS_SCHEDULE = tostring(var.rds_schedule)
246248
AUTOSCALING_SCHEDULE = tostring(var.autoscaling_schedule)

variables.tf

+10-3
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,19 @@ variable "schedule_action" {
3939
}
4040

4141
variable "resources_tag" {
42-
description = "Set the tag use for identify resources to stop or start"
42+
# This variable has been renamed to "scheduler_tag"
43+
description = "DEPRECATED, use scheduler_tag variable instead"
44+
type = map(string)
45+
default = null
46+
}
47+
48+
variable "scheduler_tag" {
49+
description = "Set the tag to use for identify aws resources to stop or start"
4350
type = map(string)
4451

4552
default = {
46-
key = "tostop"
47-
value = "true"
53+
"key" = "tostop"
54+
"value" = "true"
4855
}
4956
}
5057

0 commit comments

Comments
 (0)