-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.tf
108 lines (87 loc) · 2.91 KB
/
main.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
### Deploys WordPress according to AWS best practice
### Deploys: EC2 instance, ELB, ASG, RDS, EFS and CloudFront(future)
# To SSH to your EC2 instance use its public ip make sure to set admin_vm_ip to your bastion/jumpbox
# Bitnami default values on the AMI, used while creating RDS to mirror settings on local mySql
# Could have worked on changing it, but there is justification.
# --------------------------------------------------------
### Variables
locals {
db_name = "bitnami_wordpress"
db_username = "bn_wordpress"
}
# --------------------------------------------------------
### Deploy ELB pointing to EC2
resource "aws_elb" "wordpress" {
name = "wordpress-elb"
instances = ["${aws_instance.wordpress.id}"]
cross_zone_load_balancing = true
idle_timeout = 300
connection_draining = true
connection_draining_timeout = 300
security_groups = ["${aws_security_group.wordpress_elb.id}"]
subnets = ["${data.aws_subnet.wordpress.id}"]
access_logs {
bucket = "${aws_s3_bucket.elb_logs.bucket}"
bucket_prefix = ""
interval = 60
}
listener {
instance_port = 80
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
# ELB with SSL certificate configured
# listener {
# instance_port = 443
# instance_protocol = "http"
# lb_port = 443
# lb_protocol = "https"
# ssl_certificate_id = "${var.elb_ssl_cert}"
# }
health_check {
healthy_threshold = 2
unhealthy_threshold = 2
timeout = 3
target = "HTTP:80/"
interval = 30
}
tags = "${var.tags}"
}
# --------------------------------------------------------
### Deploy automatic scaling group for EC2 instance
module "asg" {
name = "wordpress_asg"
source = "terraform-aws-modules/autoscaling/aws"
asg_name = "wordpress"
lc_name = "wordpresslc"
instance_type = "t2.micro"
image_id = "${lookup(var.ami_images, var.region)}"
vpc_zone_identifier = ["${aws_instance.wordpress.subnet_id}"]
health_check_type = "EC2"
min_size = 1
max_size = 1
desired_capacity = 1
wait_for_capacity_timeout = 0
security_groups = [
"${aws_security_group.wordpress.id}",
]
root_block_device = [
{
volume_type = "gp2"
volume_size = "8"
},
]
}
# --------------------------------------------------------
### Deploy elastic file system
module "efs" {
name = "efs"
source = "cloudposse/efs/aws"
availability_zones = ["${var.availability_zone}"]
aws_region = "${var.region}"
security_groups = ["${aws_security_group.wordpress_efs.id}"]
subnets = ["${data.aws_subnet.wordpress.id}"]
vpc_id = "${data.aws_subnet.wordpress.vpc_id}"
zone_id = "${aws_route53_record.wordpress.zone_id}"
}