Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
feat: add leave_on_terminate (default true so containers gracefully l…
Browse files Browse the repository at this point in the history
…eave when ECS stops the task) (#15)

* feat: set leave_on_terminate from variable

* fix: helps if you pass the variable

* fix: convert boolean to string for template

* feat: making this more opinionated, setting leave_on_terminate true by default

The consul default for leave_on_terminate is false; however running
consul in docker means we need to set this to true: when the docker
container exits, local data in the container is lost; therefore we need
to send a graceful leave before exiting. Docker stop (and ECS Stop Task)
send a TERM.

* chore: gitignore

* feat: update variable description and README for leave_on_terminate
  • Loading branch information
jnoss authored Jul 8, 2019
1 parent 108637a commit aebde4c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ Session.vim
# auto-generated tag files
tags


# editors
.idea
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ This module supports two modes. If you pass a single ECS cluster ID into the `ec
- `oauth2_proxy_htpasswd_file` - Path the htpasswd file defaults to /conf/htpasswd
- `join_ec2_tag_key` - EC2 Tag Key which consul uses to search to generate a list of IP's to Join. Defaults to Name
- `raft_multiplier" - An integer multiplier used by Consul servers to scale key Raft timing parameters https://www.consul.io/docs/guides/performance.html defaults to 5
- `leave_on_terminate` - If enabled, when the agent receives a TERM signal, it will send a Leave message to the rest of the cluster and gracefully leave. Defaults to true in this module so that containers will gracefully leave the consul cluster when ECS stops the task.
- `region` - AWS Region - defaults to us-east-1
- `registrator_image` - Image to use when deploying registrator agent, defaults to the gliderlabs registrator:latest image
- `registrator_memory_reservation` The soft limit (in MiB) of memory to reserve for the container, defaults 32
Expand Down
2 changes: 1 addition & 1 deletion files/consul.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"environment": [
{
"name": "CONSUL_LOCAL_CONFIG",
"value": "{ \"retry_join\": [\"provider=aws tag_key=${join_ec2_tag_key} tag_value=${join_ec2_tag}\"], \"raft_protocol\": 3, \"skip_leave_on_interrupt\": true, \"enable_script_checks\": ${enable_script_checks}, \"datacenter\":\"${datacenter}\", \"performance\": { \"raft_multiplier\": ${raft_multiplier} }}"
"value": "{ \"retry_join\": [\"provider=aws tag_key=${join_ec2_tag_key} tag_value=${join_ec2_tag}\"], \"raft_protocol\": 3, \"skip_leave_on_interrupt\": true, \"leave_on_terminate\": ${leave_on_terminate}, \"enable_script_checks\": ${enable_script_checks}, \"datacenter\":\"${datacenter}\", \"performance\": { \"raft_multiplier\": ${raft_multiplier} }}"
},
{
"name": "CONSUL_BIND_INTERFACE",
Expand Down
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ data "template_file" "consul" {
oauth2_proxy_client_id = "${var.oauth2_proxy_client_id}"
oauth2_proxy_client_secret = "${var.oauth2_proxy_client_secret}"
raft_multiplier = "${var.raft_multiplier}"
leave_on_terminate = "${var.leave_on_terminate ? "true" : "false"}"
s3_backup_bucket = "${var.s3_backup_bucket}"
}
}
Expand Down
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ variable "service_minimum_healthy_percent" {
default = "66"
}

variable "leave_on_terminate" {
description = "If enabled, when the agent receives a TERM signal, it will send a Leave message to the rest of the cluster and gracefully leave. Defaults to true in this module so that containers will gracefully leave the consul cluster when ECS stops the task."
default = true
}

variable "vpc_id" {}

variable "sha_htpasswd_hash" {
Expand Down

0 comments on commit aebde4c

Please sign in to comment.