diff --git a/_asg.tf b/_asg.tf index 72282ff..8b0db36 100644 --- a/_asg.tf +++ b/_asg.tf @@ -2,7 +2,7 @@ # 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 : ""}" @@ -10,6 +10,10 @@ resource "aws_launch_configuration" "launch_config" { 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 @@ -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 diff --git a/examples/engagement-app/README.md b/examples/engagement-app/README.md new file mode 100644 index 0000000..d5d5ffe --- /dev/null +++ b/examples/engagement-app/README.md @@ -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 + ``` + + diff --git a/examples/engagement-app/main.tf b/examples/engagement-app/main.tf index 73e416f..486dbaa 100644 --- a/examples/engagement-app/main.tf +++ b/examples/engagement-app/main.tf @@ -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"] +# } \ No newline at end of file