Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Commit

Permalink
Improve EC2 tagging and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelmarques7 authored Jan 30, 2019
1 parent 55d042d commit f20badc
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 17 deletions.
16 changes: 15 additions & 1 deletion _asg.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
# Configures the machines that are deployed
#
resource "aws_launch_configuration" "launch_config" {
name = "${var.launch-config-name}"
name_prefix = "${var.launch-config-name}"
image_id = "${var.instance-ami}"
instance_type = "${var.instance-type}"
iam_instance_profile = "${var.iam-role-name != "" ? var.iam-role-name : ""}"
key_name = "${var.instance-key-name != "" ? var.instance-key-name : ""}"
user_data = "${var.user-data-script != "" ? file("${var.user-data-script}") : ""}"
associate_public_ip_address = "${var.instance-associate-public-ip == "true" ? true : false}"
security_groups = ["${aws_security_group.sg.id}"]

lifecycle = {
create_before_destroy = true
}
}

# AutoScaling Group
Expand All @@ -26,6 +30,16 @@ resource "aws_autoscaling_group" "asg" {
health_check_grace_period = 300
health_check_type = "EC2"
force_delete = true

lifecycle = {
create_before_destroy = true
}

tag = {
key = "Name"
value = "${var.instance-tag-name}"
propagate_at_launch = true
}
}

# AutoScaling Attachment
Expand Down
17 changes: 17 additions & 0 deletions examples/engagement-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Deploy private AWS app

This example launches an Auto-Scaling group and runs multiple dockers app inside each machine.

## Deployment

setup:
```
terraform init; terraform apply --auto-approve
```

teardown:
```
terraform init; terraform destroy --auto-approve
```


62 changes: 46 additions & 16 deletions examples/engagement-app/main.tf
Original file line number Diff line number Diff line change
@@ -1,19 +1,49 @@
module "asg" {
// You can call the module 'asg' whatever you want
// This block uses the module from two directories above
module "asg-local" {
source = "../../"

aws-profile = "ds-web-products-staging"
aws-region = "eu-west-3"
instance-ami = "ami-0dd7e7ed60da8fb83"
user-data-script = "./user-data.sh"
asg-min-size = "2"
asg-max-size = "4"
asg-def-size = "2"
alb-name = "rafa-ian-alb"
placement-group-name = "rafa-ian-pg"
target-group-name = "rafa-ian-tg"
asg-name = "rafa-ian-asg"
launch-config-name = "rafa-ian-lc"
instance-associate-public-ip = "true"
iam-role-name = "engage-ECR-read"
ssh-allowed-ips = ["62.255.97.196/32", "62.6.58.84/32"]
aws-profile = "ds-web-products-staging"
aws-region = "eu-west-3"
instance-ami = "ami-0dd7e7ed60da8fb83"
user-data-script = "./user-data.sh"
asg-min-size = "2"
asg-max-size = "4"
asg-def-size = "2"
alb-name = "rafa-lizzie-alb"
instance-key-name = "engage-paris-key"
instance-type = "t2.medium"
instance-tag-name = "AMP-app-ec2-instance"
placement-group-name = "rafa-lizzie-pg"
target-group-name = "rafa-lizzie-tg"
asg-name = "rafa-lizzie-asg"
launch-config-name = "rafa-lizzie-lc"
iam-role-name = "engage-ECR-read"
ssh-allowed-ips = ["62.255.97.196/32", "62.255.97.197/32"]
}

// This is the exact same block,
// but uses the module from the terraform registry

# module "asg-registry" {
# source = "EconomistDigitalSolutions/asg/aws"
# version = "1.0.4"

# aws-profile = "ds-web-products-staging"
# aws-region = "eu-west-3"
# instance-ami = "ami-0dd7e7ed60da8fb83"
# user-data-script = "./user-data.sh"
# asg-min-size = "2"
# asg-max-size = "4"
# asg-def-size = "2"
# alb-name = "rafa-lizzie-alb"
# instance-key-name = "engage-paris-key"
# instance-type = "t2.medium"
# instance-tag-name = "AMP-app-ec2-instance"
# placement-group-name = "rafa-lizzie-pg"
# target-group-name = "rafa-lizzie-tg"
# asg-name = "rafa-lizzie-asg"
# launch-config-name = "rafa-lizzie-lc"
# iam-role-name = "engage-ECR-read"
# ssh-allowed-ips = ["62.255.97.196/32", "62.255.97.197/32"]
# }

0 comments on commit f20badc

Please sign in to comment.