-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto_scaling.tf
71 lines (57 loc) · 2.09 KB
/
auto_scaling.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
# Get amazon linux 2 ami
data "aws_ami" "amazon_linux2" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["amzn2-ami-hvm-*-x86_64-gp2"]
}
}
# Autoscaling group
#----------------------------------------
module "wordpress_asg" {
depends_on = [aws_db_instance.wordpress]
source = "terraform-aws-modules/autoscaling/aws"
version = "6.9.0"
name = "${local.name_prefix}-${var.wordpress_server_name}-asg"
min_size = var.wordpress_asg_min_size
max_size = var.wordpress_asg_max_size
health_check_type = var.wordpress_asg_health_check_type
vpc_zone_identifier = module.network.public_subnets
target_group_arns = [aws_lb_target_group.web_alb_tg_http.arn]
# Launch template
launch_template_name = "${var.wordpress_server_name}-template"
launch_template_description = "WordPress instances"
image_id = data.aws_ami.amazon_linux2.id
instance_type = var.wordpress_template_instance_type
enable_monitoring = var.wordpress_template_enable_monitoring
security_groups = [aws_security_group.ssh_sg.id, aws_security_group.wordpress_ec2_sg.id]
key_name = var.key_name
user_data = base64encode(data.template_file.user_data.rendered)
scaling_policies = {
avg-cpu-policy-greater-than-75 = {
policy_type = var.wordpress_asg_scaling_policy_type
target_tracking_configuration = {
predefined_metric_specification = {
predefined_metric_type = var.wordpress_asg_scaling_policy_metric_type
}
target_value = var.wordpress_asg_scaling_policy_target_value
}
}
}
}
# user data wordpress script template
data "template_file" "user_data" {
template = file("${path.module}/install_wordpress.tpl")
vars = {
db_username = var.db_username
db_password = var.db_password
db_name = var.db_name
db_host = aws_db_instance.wordpress.address
wp_username = var.wp_username
wp_password = var.wp_password
wp_email = var.wp_email
wp_url = aws_lb.web_alb.dns_name
wp_title = var.app_name
}
}