Skip to content

eventbridge-schedule-to-cloudwatch-alarm-terraform: Update AWS Provider to v6 - #3301

Open
kakakakakku wants to merge 3 commits into
aws-samples:mainfrom
kakakakakku:eventbridge-schedule-to-cloudwatch-alarm-terraform
Open

eventbridge-schedule-to-cloudwatch-alarm-terraform: Update AWS Provider to v6#3301
kakakakakku wants to merge 3 commits into
aws-samples:mainfrom
kakakakakku:eventbridge-schedule-to-cloudwatch-alarm-terraform

Conversation

@kakakakakku

Copy link
Copy Markdown
Contributor

Issue #, if available:
N/A

Description of changes:
Hi😀 Thanks for the useful patterns!

To keep this pattern maintainable, I updated the AWS Provider to v6.

Check

terraform apply completed successfully and works good.

$ terraform apply
(snip)

$ aws cloudwatch describe-alarms --alarm-names example-ec2-cpu-alarm \
  --query 'MetricAlarms[0].ActionsEnabled' --region us-west-1
true

$ aws cloudwatch describe-alarms --alarm-names example-ec2-cpu-alarm \
  --query 'MetricAlarms[0].ActionsEnabled' --region us-west-1
false

$ aws cloudwatch describe-alarms --alarm-names example-ec2-cpu-alarm \
  --query 'MetricAlarms[0].ActionsEnabled' --region us-west-1
true
image

Note: The original schedules only fire at 8am/5pm EST on weekdays, so I temporarily changed them as follows to confirm that both schedules fire as expected.

-  schedule_expression = "cron(0 8 ? * MON-FRI *)" # Scheduled EnableAlarmActions at 8am EST Mon-Fri
-  schedule_expression_timezone = "US/Eastern" # Default is UTC
+  schedule_expression = "cron(45 22 * * ? *)" # TEMP: Scheduled EnableAlarmActions at 22:45 JST
+  schedule_expression_timezone = "Asia/Tokyo" # Default is UTC
   description = "Enable the CloudWatch alarm for EC2 CPU monitoring"

   target {
@@ -103,8 +103,8 @@ resource "aws_scheduler_schedule" "disable-ec2-alarm" {
     mode = "OFF"
   }

-  schedule_expression = "cron(0 17 ? * MON-FRI *)" # Scheduled DisableAlarmActions at 5pm EST Mon-Fri
-  schedule_expression_timezone = "US/Eastern" # Default is UTC
+  schedule_expression = "cron(40 22 * * ? *)" # TEMP: Scheduled DisableAlarmActions at 22:40 JST
+  schedule_expression_timezone = "Asia/Tokyo" # Default is UTC
   description = "Disable the CloudWatch alarm for EC2 CPU monitoring"

Thank you😀


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.


filter {
name = "name"
name = "name"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

╷
│ Error: Most Recent Image Not Filtered
│
│   with data.aws_ami.amazon-linux-2,
│   on main.tf line 36, in data "aws_ami" "amazon-linux-2":
│   36: data "aws_ami" "amazon-linux-2" {
│
│ "most_recent" is set to "true" and results are not filtered by owner or image ID. With this configuration, a third party may introduce a new image which will be returned by this data source. Filter by owner or image ID to avoid this
│ possibility.
╵


resource "aws_iam_role_policy_attachment" "scheduler_alarm_policy_attachment" {
role = aws_iam_role.scheduler-alarm-role.name
policy_arn = aws_iam_policy.scheduler_alarm_policy.arn

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: The managed_policy_arns argument is already deprecated. I update code correctly😀 See document below.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants