Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multiple crons to start and stop app #52

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ In addition you have the option to create or not :
| cluster\_name | n/a | `string` | `"Name of existing ECS Cluster to deploy this app to"` | no |
| command | Command to run on container | `list(string)` | `null` | no |
| compat\_keep\_target\_group\_naming | Keeps old naming convention for target groups to avoid recreation of resource in production environments | `bool` | `false` | no |
| container\_port | Port your container listens (used in the placeholder task definition) | `number` | `8080` | no |
| container\_port | Port your container listens (used in the placeholder task definition) | `string` | `8080` | no |
| cpu | Hard limit for CPU for the container | `number` | `0` | no |
| dynamic\_stickiness | Target Group stickiness. Used in dynamic block. | `any` | `[]` | no |
| ecs\_service\_capacity\_provider\_strategy | (Optional) The capacity provider strategy to use for the service. Can be one or more. These can be updated without destroying and recreating the service only if set to [] and not changing from 0 capacity\_provider\_strategy blocks to greater than 0, or vice versa. | `list` | <pre>[<br> {}<br>]</pre> | no |
Expand All @@ -110,10 +110,10 @@ In addition you have the option to create or not :
| healthy\_threshold | The number of consecutive health checks successes required before considering an unhealthy target healthy | `number` | `3` | no |
| hosted\_zone | Hosted Zone to create DNS record for this app | `string` | `""` | no |
| hosted\_zone\_id | Hosted Zone ID to create DNS record for this app (use this to avoid data lookup when using `hosted_zone`) | `string` | `""` | no |
| hosted\_zone\_is\_internal | Set true in case the hosted zone is in an internal VPC, otherwise false | `string` | `"false"` | no |
| hostname\_create | Optional parameter to create or not a Route53 record | `string` | `"false"` | no |
| hosted\_zone\_is\_internal | Set true in case the hosted zone is in an internal VPC, otherwise false | `bool` | `false` | no |
| hostname\_create | Optional parameter to create or not a Route53 record | `bool` | `false` | no |
| hostname\_redirects | List of hostnames to redirect to the main one, comma-separated | `string` | `""` | no |
| hostnames | List of hostnames to create listerner rule and optionally, DNS records for this app | `list` | `[]` | no |
| hostnames | List of hostnames to create listerner rule and optionally, DNS records for this app | `list(string)` | `[]` | no |
| http\_header | Header to use on listerner rule with name e values | `list(any)` | `[]` | no |
| image | Docker image to deploy (can be a placeholder) | `string` | `""` | no |
| launch\_type | The launch type on which to run your service. The valid values are EC2 and FARGATE. Defaults to EC2. | `string` | `"EC2"` | no |
Expand All @@ -122,7 +122,7 @@ In addition you have the option to create or not :
| log\_subscription\_filter\_filter\_pattern | n/a | `string` | `""` | no |
| log\_subscription\_filter\_role\_arn | n/a | `string` | `""` | no |
| memory | Hard memory of the container | `number` | `512` | no |
| name | Name of your ECS service | `any` | n/a | yes |
| name | Name of your ECS service | `string` | n/a | yes |
| network\_mode | The Docker networking mode to use for the containers in the task. The valid values are none, bridge, awsvpc, and host. (REQUIRED IF 'LAUCH\_TYPE' IS FARGATE) | `any` | `null` | no |
| ordered\_placement\_strategy | Service level strategy rules that are taken into consideration during task placement. List from top to bottom in order of precedence. The maximum number of ordered\_placement\_strategy blocks is 5. | <pre>list(object({<br> field = string<br> type = string<br> }))</pre> | `[]` | no |
| paths | List of paths to use on listener rule (example: ['/\*']) | `list(string)` | `[]` | no |
Expand All @@ -133,21 +133,23 @@ In addition you have the option to create or not :
| redirects | Map of path redirects to add to the listener | `map` | `{}` | no |
| schedule\_cron\_start | Cron expression to define when to trigger a start of the auto-scaling group. E.g. 'cron(00 21 ? \* SUN-THU \*)' to start at 8am UTC time. | `string` | `""` | no |
| schedule\_cron\_stop | Cron expression to define when to trigger a stop of the auto-scaling group. E.g. 'cron(00 09 ? \* MON-FRI \*)' to start at 8am UTC time | `string` | `""` | no |
| schedules\_stop | n/a | `any` | n/a | yes |
| security\_groups | The security groups associated with the task or service | `any` | `null` | no |
| service\_deployment\_maximum\_percent | Maximum percentage of tasks to run during deployments | `number` | `200` | no |
| service\_deployment\_minimum\_healthy\_percent | Minimum healthy percentage during deployments | `number` | `100` | no |
| service\_desired\_count | Desired count for this service (for use when auto scaling is disabled) | `number` | `1` | no |
| service\_health\_check\_grace\_period\_seconds | Time until your container starts serving requests | `number` | `0` | no |
| service\_role\_arn | Existing service role ARN created by ECS cluster module | `any` | `null` | no |
| source\_ips | List of source ip to use on listerner rule | `list` | `[]` | no |
| source\_ips | List of source ip to use on listerner rule | `list(string)` | `[]` | no |
| ssm\_variables | Map of variables and SSM locations to add to the task definition | `map(string)` | `{}` | no |
| static\_variables | Map of variables and static values to add to the task definition | `map(string)` | `{}` | no |
| subnets | The subnets associated with the task or service. (REQUIRED IF 'LAUCH\_TYPE' IS FARGATE) | `any` | `null` | no |
| tags | Map of tags that will be added to created resources. By default resources will be tagged with terraform=true. | `map(string)` | `{}` | no |
| task\_definition\_arn | Task definition to use for this service (optional) | `string` | `""` | no |
| task\_role\_arn | Existing task role ARN created by ECS cluster module | `any` | `null` | no |
| task\_role\_policies | Custom policies to be added on the task role. | `list` | `[]` | no |
| task\_role\_policies\_managed | AWS Managed policies to be added on the task role. | `list` | `[]` | no |
| task\_role\_policies | Custom policies to be added on the task role. | `list(string)` | `[]` | no |
| task\_role\_policies\_managed | AWS Managed policies to be added on the task role. | `list(string)` | `[]` | no |
| timezone | n/a | `string` | `"UTC"` | no |
| ulimits | Container ulimit settings. This is a list of maps, where each map should contain "name", "hardLimit" and "softLimit" | <pre>list(object({<br> name = string<br> hardLimit = number<br> softLimit = number<br> }))</pre> | `null` | no |
| unhealthy\_threshold | The number of consecutive health check failures required before considering the target unhealthy | `number` | `3` | no |
| vpc\_id | VPC ID to deploy this app to | `any` | n/a | yes |
Expand Down
28 changes: 26 additions & 2 deletions _variables.tf
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
variable "name" {
type = string
description = "Name of your ECS service"
}

variable "container_port" {
default = 8080
type = string
description = "Port your container listens (used in the placeholder task definition)"
}

variable "port" {
default = 80
type = number
description = "Port for target group to listen"
}

variable "protocol" {
default = "HTTP"
type = string
description = "Protocol to use (HTTP or HTTPS)"
}

variable "memory" {
default = 512
type = number
description = "Hard memory of the container"
}

variable "cpu" {
default = 0
type = number
description = "Hard limit for CPU for the container"
}

Expand All @@ -34,32 +40,38 @@ variable "paths" {
}

variable "hosted_zone_is_internal" {
default = "false"
default = false
type = bool
description = "Set true in case the hosted zone is in an internal VPC, otherwise false"
}

variable "hosted_zone" {
default = ""
type = string
description = "Hosted Zone to create DNS record for this app"
}

variable "hosted_zone_id" {
default = ""
type = string
description = "Hosted Zone ID to create DNS record for this app (use this to avoid data lookup when using `hosted_zone`)"
}

variable "hostname_create" {
default = "false"
default = false
type = bool
description = "Optional parameter to create or not a Route53 record"
}

variable "hostnames" {
default = []
type = list(string)
description = "List of hostnames to create listerner rule and optionally, DNS records for this app"
}

variable "source_ips" {
default = []
type = list(string)
description = "List of source ip to use on listerner rule"
}

Expand All @@ -72,11 +84,13 @@ variable "http_header" {
variable "hostname_redirects" {
description = "List of hostnames to redirect to the main one, comma-separated"
default = ""
type = string
}


variable "healthcheck_path" {
default = "/"
type = string
}

variable "healthcheck_interval" {
Expand Down Expand Up @@ -467,6 +481,10 @@ variable "enable_schedule" {
description = "Enables schedule to shut down and start up instances outside business hours."
}

variable "schedules_stop" {

}

variable "schedule_cron_start" {
type = string
default = ""
Expand All @@ -487,11 +505,17 @@ variable "command" {

variable "task_role_policies_managed" {
default = []
type = list(string)
description = "AWS Managed policies to be added on the task role."
}

variable "task_role_policies" {
default = []
type = list(string)
description = "Custom policies to be added on the task role."
}

variable "timezone" {
type = string
default = "UTC"
}
7 changes: 4 additions & 3 deletions appautoscaling.tf
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ resource "aws_appautoscaling_scheduled_action" "scale_service_out" {
resource_id = aws_appautoscaling_target.ecs[0].resource_id
scalable_dimension = aws_appautoscaling_target.ecs[0].scalable_dimension
schedule = var.schedule_cron_stop
timezone = "UTC"
timezone = var.timezone

scalable_target_action {
min_capacity = 0
Expand All @@ -99,10 +99,11 @@ resource "aws_appautoscaling_scheduled_action" "scale_service_in" {
resource_id = aws_appautoscaling_target.ecs[0].resource_id
scalable_dimension = aws_appautoscaling_target.ecs[0].scalable_dimension
schedule = var.schedule_cron_start
timezone = "UTC"
timezone = var.timezone

scalable_target_action {
min_capacity = var.autoscaling_min
max_capacity = var.autoscaling_max
}
}
}