Skip to content

wearetechnative/terraform-aws-module-scheduler

Repository files navigation

START INSTRUCTION FOR TECHNATIVE ENGINEERS

terraform-aws-module-templates

Template for creating a new TerraForm AWS Module. For TechNative Engineers.

Instructions

Your Module Name

Think hard and come up with the shortest descriptive name for your module. Look at competition in the terraform registry.

Your module name should be max. three words seperated by dashes. E.g.

  • html-form-action
  • new-account-notifier
  • budget-alarms
  • fix-missing-tags

Setup Github Project

  1. Click the template button on the top right...
  2. Name github project terraform-aws-[your-module-name]
  3. Make project private untill ready for publication
  4. Add a description in the About section (top right)
  5. Add tags: terraform, terraform-module, aws and more tags relevant to your project: e.g. s3, lambda, sso, etc..
  6. Install pre-commit

Develop your module

  1. Develop your module
  2. Try to use the best practices for TerraForm development and TerraForm AWS Development.

Finish project documentation

  1. Set well written title
  2. Add one or more shields
  3. Start readme with a short and complete as possible module description. This is the part where you sell your module.
  4. Complete README with well written documentation. Try to think as a someone with three months of Terraform experience.
  5. Check if pre-commit correctly generates the standard Terraform documentation.

Publish module

If your module is in a state that it could be useful for others and ready for publication, you can publish a first version.

  1. Create a Github Release
  2. Publish in the TerraForm Registry under the Technative Namespace (the GitHub Repo must be in the TechNative Organization)

END INSTRUCTION FOR TECHNATIVE ENGINEERS

Terraform AWS [Scheduler]

This module allows you to start and stop instances on a defined schedule. The schedules are stored in a DynamoDB table along with their time periods.

Key Concepts

Schedule

A named schedule that defines when instances tagged with that schedule should run. The schedule name is used as the value for the InstanceScheduler tag on any instance you want to manage via this module.

Period

Each schedule has one or more periods. A period defines a set of rules about which days, what timezone, what start time, and what end time the schedule applies.

Period Attributes

Each period includes the following:

Attribute Description

weekdays -  One or more days of the week when the period is active.You can use multiple days.(e.g. mon, tue, fri)
            Valid abbreviations: mon, tue,  wed, thu, fri, sat, sun.
timezone -  The timezone for interpreting begintime and endtime.UTC is the default timezone.                       
begintime-  The time of day when instances should start (in 24-hour format, e.g. 09:00).
endtime  -  The time of day when instances should stop (in 24-hour format, e.g. 17:00).

Rules & Examples

Each schedule must have at least one period.

You can have multiple periods within a schedule (for instance, one for weekdays 9-17, another for weekends).

Times are in 24-hour format.

Days must use consistent abbreviations (e.g. mon, tue, etc.).

How does it work

First use after you clone this repository or when .pre-commit-config.yaml is updated

Run pre-commit install to install any guardrails implemented using pre-commit.

See pre-commit installation on how to install pre-commit.

...

Usage

To use this module ...

module "scheduler"{
    source = "[email protected]:wearetechnative/terraform-aws-lambda.git"
    bucket_name = "instancescheduler-bucket-example"
    dynamodb_table_name = "instance_scheduler"
    kms_key_arn = *******
    lambda_role_name = "scheduler_role"
    periods = [
      {
         "name": "7am-to-8pm",
         "days": ["mon", "tue", "wed", "thu", "fri"],
         "begintime": "7:00",
         "endtime": "20:00",
         "timezone": "Europe/Amsterdam"
      },
      {
         "name": "8am-to-7pm",
         "days": ["mon", "tue", "wed", "thu", "fri"],
         "begintime": "8:00",
         "endtime": "19:00",
         "timezone": "Europe/Amsterdam"
      }
    ]
    schedules = [
      {
         "name": "mon-fri-7am-to-8pm",
         "period": ["7am-to-8pm"]
      },
      {
         "name": "mon-fri-8am-to-7pm",
         "period": ["8am-to-7pm"]
      }
    ]
    sqs_arn = ********
}

Requirements

No requirements.

Providers

Name Version
aws n/a

Modules

Name Source Version
dynamodb_instance_scheduler github.com/wearetechnative/terraform-aws-module-dynamodb.git n/a
ec2_lambda github.com/wearetechnative/terraform-aws-lambda.git n/a
iam_role_lambda_instance_scheduler github.com/wearetechnative/terraform-aws-iam-role.git n/a
iam_role_webpage_scheduler github.com/wearetechnative/terraform-aws-iam-role.git n/a
lambda_start_stop_instances github.com/wearetechnative/terraform-aws-lambda.git n/a
sqs_dlq ../01_sqs_dlq n/a

Resources

Name Type
aws_apigatewayv2_api.my_api resource
aws_apigatewayv2_integration.int resource
aws_apigatewayv2_route.my_route resource
aws_apigatewayv2_stage.my_api_stg resource
aws_cloudwatch_event_rule.rule resource
aws_cloudwatch_event_target.lambda_trigger resource
aws_dynamodb_table_item.period resource
aws_dynamodb_table_item.schedules resource
aws_kms_grant.a resource
aws_lambda_permission.allow_API resource
aws_lambda_permission.allow_API_1 resource
aws_lambda_permission.allow_API_2 resource
aws_lambda_permission.allow_API_3 resource
aws_lambda_permission.allow_eventbridge resource
aws_s3_bucket.webpage_bucket resource
aws_s3_bucket_object.object resource
aws_s3_bucket_object.object2 resource
aws_s3_bucket_object.object3 resource
aws_s3_bucket_website_configuration.website_conf resource
aws_iam_policy_document.instance_scheduler data source
aws_iam_policy_document.launch_ec2 data source

Inputs

Name Description Type Default Required
bucket_name n/a string n/a yes
dynamodb_table_name n/a string n/a yes
kms_key_arn n/a string n/a yes
lambda_role_name name for lambda role which will be created by this module string n/a yes
periods n/a
list(object({
name = string,
days = list(string),
begintime = string,
endtime = string,
timezone = string
}))
n/a yes
schedules n/a
list(object({
name = string,
period = list(string)
}))
n/a yes
sqs_arn n/a string n/a yes

Outputs

No outputs.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5