Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tf_mod_aws_asg
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
steamhaus
tf_mod_aws_asg
Commits
cfa1d35f
Commit
cfa1d35f
authored
Sep 19, 2016
by
A-Gordon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial commit
parents
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
177 additions
and
0 deletions
+177
-0
.gitlab-ci.yml
.gitlab-ci.yml
+12
-0
README.md
README.md
+24
-0
main.tf
main.tf
+141
-0
No files found.
.gitlab-ci.yml
0 → 100644
View file @
cfa1d35f
image
:
alpine:latest
variables
:
TERRAFORM_URL
:
"
https://releases.hashicorp.com/terraform/0.7.1/terraform_0.7.1_linux_amd64.zip"
before_script
:
-
apk update && apk add ca-certificates && update-ca-certificates && apk add openssl
-
wget -O /tmp/terraform.zip $TERRAFORM_URL
-
unzip /tmp/terraform.zip -d /usr/local/bin
test
:
script
:
terraform validate
README.md
0 → 100644
View file @
cfa1d35f
tf_mod_aws_asg
==============
A Terraform module for creating an auto scaling group and it's dependencies.
The module generates the launch configuration, the auto scaling group and two autoscaling policies.
1.
) Adding a module resource to your template, e.g.
`main.tf`
```
module "asg" {
source = "../../../../steamhaus/tf_mod_aws_ec2"
lc_name = "${var.name}-app-lc-"
ami_id = "${data.aws_ami.app.id}"
iam_instance_profile = "${module.cloudwatch_logs.profile_id}"
key_name = "Bastion"
security_groups = ["${aws_security_group.app.id}"]
user_data = "${data.template_file.userdata_app.rendered}"
asg_name = "${var.name}-app"
load_balancers = ["${module.elb.elb_id}"]
vpc_zone_identifier = ["${module.vpc.private_subnets}"]
}
```
\ No newline at end of file
main.tf
0 → 100644
View file @
cfa1d35f
#############################################################################################################
# Variables
#############################################################################################################
# Launch Configuration Variables
variable
"lc_name"
{}
variable
"ami_id"
{
description
=
"The AMI to use with the launch configuration"
}
variable
"instance_type"
{
default
=
"m3.medium"
}
variable
"iam_instance_profile"
{
description
=
"The IAM role the launched instance will use"
}
variable
"key_name"
{
description
=
"The SSH public key name (in EC2 key-pairs) to be injected into instances"
default
=
"Bastion"
}
variable
"security_groups"
{
description
=
"ID of SG the launched instance will use"
type
=
"list"
}
variable
"user_data"
{
description
=
"The path to a file with user_data for the instances"
}
# Auto-Scaling Group
variable
"asg_name"
{}
variable
"asg_minimum_number_of_instances"
{
description
=
"The minimum number of instances we want in the ASG"
default
=
"2"
}
variable
"asg_maximum_number_of_instances"
{
description
=
"The maximum number of instances we want in the ASG"
default
=
"2"
}
variable
"asg_desired_number_of_instances"
{
description
=
"The desired number of instances we want in the ASG"
default
=
"2"
}
variable
"health_check_grace_period"
{
description
=
"Number of seconds for a health check to time out"
default
=
300
}
variable
"health_check_type"
{
description
=
"The health check used by the ASG to determine health"
default
=
"ELB"
}
variable
"load_balancers"
{
description
=
"A list of ELB names the ASG should associate instances with"
type
=
"list"
}
variable
"vpc_zone_identifier"
{
type
=
"list"
}
# Auto-Scaling policies
variable
"scale_up_scaling_adjsutment"
{
default
=
"100"
}
variable
"scale_up_cooldown"
{
default
=
"60"
}
variable
"scale_down_scaling_adjsutment"
{
default
=
"-50"
}
variable
"scale_down_cooldown"
{
default
=
"120"
}
resource
"aws_launch_configuration"
"default"
{
lifecycle
{
create_before_destroy
=
true
}
name_prefix
=
"
${
var
.
lc_name
}
"
image_id
=
"
${
var
.
ami_id
}
"
instance_type
=
"
${
var
.
instance_type
}
"
key_name
=
"
${
var
.
key_name
}
"
iam_instance_profile
=
"
${
var
.
iam_instance_profile
}
"
security_groups
=
[
"
${
var
.
security_groups
}
"
]
user_data
=
"
${
var
.
user_data
}
"
}
resource
"aws_autoscaling_group"
"default"
{
lifecycle
{
create_before_destroy
=
true
}
name
=
"
${
var
.
asg_name
}
"
launch_configuration
=
"
${
aws_launch_configuration
.
default
.
name
}
"
load_balancers
=
[
"
${
var
.
load_balancers
}
"
]
vpc_zone_identifier
=
[
"
${
var
.
vpc_zone_identifier
}
"
]
min_elb_capacity
=
"
${
var
.
asg_minimum_number_of_instances
}
"
min_size
=
"
${
var
.
asg_minimum_number_of_instances
}
"
max_size
=
"
${
var
.
asg_maximum_number_of_instances
}
"
desired_capacity
=
"
${
var
.
asg_desired_number_of_instances
}
"
health_check_grace_period
=
"
${
var
.
health_check_grace_period
}
"
health_check_type
=
"
${
var
.
health_check_type
}
"
tag
{
key
=
"Name"
value
=
"
${
var
.
asg_name
}
"
propagate_at_launch
=
true
}
tag
{
key
=
"Launch config"
value
=
"
${
aws_launch_configuration
.
default
.
name
}
"
propagate_at_launch
=
true
}
}
resource
"aws_autoscaling_policy"
"scale-up"
{
name
=
"
${
var
.
asg_name
}
-scale-up"
adjustment_type
=
"PercentChangeInCapacity"
scaling_adjustment
=
"
${
var
.
scale_up_scaling_adjsutment
}
"
cooldown
=
"
${
var
.
scale_up_cooldown
}
"
autoscaling_group_name
=
"
${
aws_autoscaling_group
.
default
.
name
}
"
}
resource
"aws_autoscaling_policy"
"scale-down"
{
name
=
"
${
var
.
asg_name
}
-scale-down"
adjustment_type
=
"PercentChangeInCapacity"
scaling_adjustment
=
"
${
var
.
scale_down_scaling_adjsutment
}
"
cooldown
=
"
${
var
.
scale_down_cooldown
}
"
autoscaling_group_name
=
"
${
aws_autoscaling_group
.
default
.
name
}
"
}
#############################################################################################################
# Outputs
#############################################################################################################
output
"launch_config_id"
{
value
=
"
${
aws_launch_configuration
.
default
.
id
}
"
}
output
"asg_id"
{
value
=
"
${
aws_autoscaling_group
.
default
.
id
}
"
}
output
"asg_name"
{
value
=
"
${
aws_autoscaling_group
.
default
.
name
}
"
}
output
"autoscaling_policy_scale_up_arn"
{
value
=
"
${
aws_autoscaling_policy
.
scale-up
.
arn
}
"
}
output
"autoscaling_policy_scale_down_arn"
{
value
=
"
${
aws_autoscaling_policy
.
scale-down
.
arn
}
"
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment