-
-
Notifications
You must be signed in to change notification settings - Fork 144
/
README.yaml
149 lines (134 loc) · 6.58 KB
/
README.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#
# This is the canonical configuration for the `README.md`
# Run `make readme` to rebuild the `README.md`
#
# Name of this project
name: terraform-aws-ec2-autoscale-group
# Logo for this project
#logo: docs/logo.png
# License of this project
license: "APACHE2"
# Canonical GitHub repo
github_repo: cloudposse/terraform-aws-ec2-autoscale-group
# Badges to display
badges:
- name: Latest Release
image: https://img.shields.io/github/release/cloudposse/terraform-aws-ec2-autoscale-group.svg?style=for-the-badge
url: https://github.com/cloudposse/terraform-aws-ec2-autoscale-group/releases/latest
- name: Last Updated
image: https://img.shields.io/github/last-commit/cloudposse/terraform-aws-ec2-autoscale-group.svg?style=for-the-badge
url: https://github.com/cloudposse/terraform-aws-ec2-autoscale-group/commits
- name: Slack Community
image: https://slack.cloudposse.com/for-the-badge.svg
url: https://slack.cloudposse.com
# List any related terraform modules that this module may be used with or that this module depends on.
related:
- name: "terraform-aws-ec2-instance"
description: "Terraform module for providing a general purpose EC2 instance"
url: "https://github.com/cloudposse/terraform-aws-ec2-instance"
- name: "terraform-aws-ec2-bastion-server"
description: "Terraform module to define a generic bastion host with parameterized user data"
url: "https://github.com/cloudposse/terraform-aws-ec2-bastion-server"
- name: "terraform-aws-ec2-admin-server"
description: "Terraform module for providing an EC2 instance capable of running admin tasks"
url: "https://github.com/cloudposse/terraform-aws-ec2-admin-server"
- name: "terraform-aws-ec2-instance-group"
description: "Terraform module for provisioning multiple general purpose EC2 hosts for stateful applications"
url: "https://github.com/cloudposse/terraform-aws-ec2-instance-group"
- name: "terraform-aws-ec2-ami-snapshot"
description: "Terraform module to easily generate AMI snapshots to create replica instances"
url: "https://github.com/cloudposse/terraform-aws-ec2-ami-snapshot"
# Short description of this project
description: |-
Terraform module to provision [Auto Scaling Group](https://www.terraform.io/docs/providers/aws/r/autoscaling_group.html) and [Launch Template](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-launch-templates.html) on AWS.
The module also creates AutoScaling Policies and CloudWatch Metric Alarms to monitor CPU utilization on the EC2 instances and scale the number of instance in the AutoScaling Group up or down.
If you don't want to use the provided functionality, or want to provide your own policies, disable it by setting the variable `autoscaling_policies_enabled` to `false`.
At present, although you can set the created AutoScaling Policy type to any legal value, in practice [only `SimpleScaling` is supported](https://github.com/cloudposse/terraform-aws-ec2-autoscale-group/issues/55).
To use a `StepScaling` or `TargetTrackingScaling` policy, create it yourself and then pass it in the `alarm_actions` field of `custom_alarms`.
# How to use this project
usage: |2-
```hcl
locals {
userdata = <<-USERDATA
#!/bin/bash
cat <<"__EOF__" > /home/ec2-user/.ssh/config
Host *
StrictHostKeyChecking no
__EOF__
chmod 600 /home/ec2-user/.ssh/config
chown ec2-user:ec2-user /home/ec2-user/.ssh/config
USERDATA
}
module "autoscale_group" {
source = "cloudposse/ec2-autoscale-group/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"
namespace = var.namespace
stage = var.stage
environment = var.environment
name = var.name
image_id = "ami-08cab282f9979fc7a"
instance_type = "t2.small"
security_group_ids = ["sg-xxxxxxxx"]
subnet_ids = ["subnet-xxxxxxxx", "subnet-yyyyyyyy", "subnet-zzzzzzzz"]
health_check_type = "EC2"
min_size = 2
max_size = 3
wait_for_capacity_timeout = "5m"
associate_public_ip_address = true
user_data_base64 = base64encode(local.userdata)
# All inputs to `block_device_mappings` have to be defined
block_device_mappings = [
{
device_name = "/dev/sda1"
no_device = "false"
virtual_name = "root"
ebs = {
encrypted = true
volume_size = 200
delete_on_termination = true
iops = null
kms_key_id = null
snapshot_id = null
volume_type = "standard"
}
}
]
tags = {
Tier = "1"
KubernetesCluster = "us-west-2.testing.cloudposse.co"
}
# Auto-scaling policies and CloudWatch metric alarms
autoscaling_policies_enabled = true
cpu_utilization_high_threshold_percent = "70"
cpu_utilization_low_threshold_percent = "20"
}
```
To enable custom_alerts the map needs to be defined like so :
```hlc
alarms = {
alb_scale_up = {
alarm_name = "${module.default_label.id}-alb-target-response-time-for-scale-up"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = var.alb_target_group_alarms_evaluation_periods
metric_name = "TargetResponseTime"
namespace = "AWS/ApplicationELB"
period = var.alb_target_group_alarms_period
statistic = "Average"
threshold = var.alb_target_group_alarms_response_time_max_threshold
dimensions_name = "LoadBalancer"
dimensions_target = data.alb.arn_suffix
treat_missing_data = "missing"
ok_actions = var.alb_target_group_alarms_ok_actions
insufficient_data_actions = var.alb_target_group_alarms_insufficient_data_actions
alarm_description = "ALB Target response time is over ${var.alb_target_group_alarms_response_time_max_threshold} for more than ${var.alb_target_group_alarms_period}"
alarm_actions = [module.autoscaling.scale_up_policy_arn]
}
}
```
All those keys are required to be there so if the alarm you are setting does not requiere one or more keys you can just set to empty but do not remove the keys otherwise you could get a weird merge error due to the maps being of different sizes.
include:
- "docs/targets.md"
- "docs/terraform.md"
# Contributors to this project
contributors: []