Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ajbrown committed Jun 29, 2019
2 parents 1c900ad + 4a41e9c commit 6d02bdb
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repos:
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.8.1
hooks:
- id: terraform_fmt
- id: terraform_docs
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v2.1.0
hooks:
- id: check-merge-conflict
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ extra_tags = [
- `ami` - A specific AMI image to use, eg `ami-95f8d2f3`. Defaults to the latest ECS optimized Amazon Linux AMI.
- `ami_version` - Specific version of the Amazon ECS AMI to use (e.g. `2016.09`). Defaults to `*`. Ignored if `ami` is specified.
- `heartbeat_timeout` - Heartbeat Timeout setting for how long it takes for the graceful shutdown hook takes to timeout. This is useful when deploying clustered applications like consul that benifit from having a deploy between autoscaling create/destroy actions. Defaults to 180"
- `asg_delete_extra_timeout` - Extra time that `terraform apply` will wait for ASG deletion (default 600). This is added on top of `heartbeat_timeout`. This variable is customizable for when the instances take longer than 600sec to shut down once shutdown is initiated.
- `security_group_ids` - a list of security group IDs to apply to the launch configuration
- `user_data` - The instance user data (e.g. a `cloud-init` config) to use in the `aws_launch_configuration`
- custom_iam_policy - JSON containing the custom IAM policy for ECS nodes. Will overwrite the default one if set.
Expand All @@ -59,6 +60,7 @@ extra_tags = [
- `enable_agents` - Enable Consul Agent and Registrator tasks on each ECS Instance. Defaults to false
- `spot_bid_price` - Use spot instances and request this bid price. Note that with this option you risk your instances
shutting down if the market price rises above your bid price.
- `enabled_metrics` - A list of metrics to collect.

Usage
-----
Expand Down Expand Up @@ -127,6 +129,8 @@ Outputs
- `cluster_id` - _(String)_ ECS Cluster id for use in ECS task and service definitions.
- `cluster_name` - (String) ECS Cluster name that can be used for CloudWatch app autoscaling policy resource_id.
- `autoscaling_group` _(Map)_ A map with keys `id`, `name`, and `arn` of the `aws_autoscaling_group` created.
- `iam_role` _(Map)_ A map with keys `arn` and `name` of the `iam_role` created.
- `security_group` _(Map)_ A map with keys `id`, `name`, and `arn` of the `aws_security_group` created.

Authors
=======
Expand Down
11 changes: 6 additions & 5 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
data "aws_ami" "ecs_ami" {
most_recent = true

filter {
name = "owner-alias"
values = ["amazon"]
}
owners = ["amazon"]

filter {
name = "name"
Expand Down Expand Up @@ -61,6 +57,7 @@ resource "aws_autoscaling_group" "ecs" {
desired_capacity = "${var.servers}"
termination_policies = ["OldestLaunchConfiguration", "ClosestToNextInstanceHour", "Default"]
load_balancers = ["${var.load_balancers}"]
enabled_metrics = ["${var.enabled_metrics}"]

tags = [{
key = "Name"
Expand All @@ -73,6 +70,10 @@ resource "aws_autoscaling_group" "ecs" {
lifecycle {
create_before_destroy = true
}

timeouts {
delete = "${var.heartbeat_timeout + var.asg_delete_extra_timeout}s"
}
}

resource "aws_security_group" "ecs" {
Expand Down
23 changes: 23 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,33 @@ output "cluster_name" {
value = "${aws_ecs_cluster.cluster.name}"
}

output "instance_role_arn" {
value = "${aws_iam_role.ecs_role.arn}"
}

output "instance_role_id" {
value = "${aws_iam_role.ecs_role.id}"
}

output "autoscaling_group" {
value = {
id = "${aws_autoscaling_group.ecs.id}"
name = "${aws_autoscaling_group.ecs.name}"
arn = "${aws_autoscaling_group.ecs.arn}"
}
}

output "iam_role" {
value = {
name = "${aws_iam_role.ecs_role.name}"
arn = "${aws_iam_role.ecs_role.arn}"
}
}

output "security_group" {
value = {
id = "${aws_security_group.ecs.id}"
name = "${aws_security_group.ecs.name}"
arn = "${aws_security_group.ecs.arn}"
}
}
11 changes: 11 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ variable "heartbeat_timeout" {
default = "180"
}

variable "asg_delete_extra_timeout" {
description = "Extra time that `terraform apply` will wait for ASG deletion (default 600). This is added on top of `heartbeat_timeout`. This variable is customizable for when the instances take longer than 600sec to shut down once shutdown is initiated."
default = "600"
}

variable "iam_path" {
default = "/"
description = "IAM path, this is useful when creating resources with the same name across multiple regions. Defaults to /"
Expand Down Expand Up @@ -156,3 +161,9 @@ variable "user_data" {
variable "vpc_id" {
description = "The AWS VPC ID which you want to deploy your instances"
}

variable "enabled_metrics" {
description = "A list of metrics to collect"
type = "list"
default = []
}

0 comments on commit 6d02bdb

Please sign in to comment.