-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathasg.tf
73 lines (66 loc) · 2.31 KB
/
asg.tf
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
####################################################################
# AutoSacling Group
####################################################################
module "wp-asg" {
source = "terraform-aws-modules/autoscaling/aws"
version = "6.3.0"
name = "${var.prefix}-${var.environment}-asg"
instance_name = "${var.prefix}-${var.environment}-web"
min_size = var.asg_min_size
max_size = var.asg_max_size
desired_capacity = var.asg_desired_capacity
wait_for_capacity_timeout = 0
health_check_type = "ELB"
vpc_zone_identifier = module.vpc.public_subnets
# Launch Template
launch_template_name = "${var.prefix}-${var.environment}-lt"
launch_template_description = var.asg_launch_template_description
update_default_version = true
image_id = data.aws_ami.amazon_linux.id
instance_type = var.asg_instance_type
target_group_arns = module.alb.target_group_arns
key_name = var.ssh_key_name
user_data = base64encode(templatefile("${path.module}/wordpress-init.sh",
{
vars = {
efs_dns_name = "${resource.aws_efs_file_system.efs.dns_name}"
}
}))
tag_specifications = [
{
resource_type = "instance"
tags = var.tags
}
]
network_interfaces = [
{
delete_on_termination = true
description = "eth0"
device_index = 0
security_groups = [module.ssh_sg.security_group_id]
associate_public_ip_address = true
}
]
scaling_policies = {
scale-up = {
policy_type = "SimpleScaling"
name = "${var.prefix}-${var.environment}-cpu-scale-up"
scaling_adjustment = 1
adjustment_type = "ChangeInCapacity"
cooldown = "500"
},
scale-down = {
policy_type = "SimpleScaling"
name = "${var.prefix}-${var.environment}-cpu-scale-down"
scaling_adjustment = "-1"
adjustment_type = "ChangeInCapacity"
cooldown = "500"
}
}
tags = var.tags
depends_on = [resource.aws_efs_mount_target.efs_target]
}
## Delay to allow time to initialize EC2
resource "time_sleep" "wait_180_seconds" {
create_duration = "180s"
}