-
Notifications
You must be signed in to change notification settings - Fork 13
/
compute.tf
80 lines (62 loc) · 2.08 KB
/
compute.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
#--------------------------------------------------------
### EC2
resource "aws_eip" "wordpress" {
instance = "${aws_instance.wordpress.id}"
vpc = false
}
resource "aws_route53_record" "wordpress" { #EC2 public ip a record, used with EFS' dns
zone_id = "${var.route53_zone_id}"
name = "${var.route53_record_name}"
type = "A"
ttl = "60"
records = ["${aws_instance.wordpress.public_ip}"]
}
resource "aws_key_pair" "wordpress" {
key_name = "${var.ec2_key_name}"
public_key = "${var.ec2_public_key}"
}
#--------------------------------------------------------
### EC2
resource "aws_instance" "wordpress" {
ami = "${lookup(var.ami_images, var.region)}"
key_name = "${aws_key_pair.wordpress.key_name}"
instance_type = "${var.ec2_instance_type}"
subnet_id = "${data.aws_subnet.wordpress.id}"
iam_instance_profile = "${aws_iam_instance_profile.wordpress.name}"
vpc_security_group_ids = [
"${aws_security_group.wordpress.id}",
]
availability_zone = "${data.aws_subnet.wordpress.availability_zone}"
associate_public_ip_address = true
root_block_device = {
"volume_type" = "standard"
"volume_size" = 40
"delete_on_termination" = false
}
tags = "${var.tags}"
}
resource "null_resource" "bootstrap_ec2" {
# EC2 Must be configured externally as the EC2<>RDS security groups
# must be created before, for communication
depends_on = ["aws_security_group_rule.rds_ingress_mysql"]
triggers = {
ec2_instances = "${aws_instance.wordpress.private_ip}"
}
connection {
host = "${aws_eip.wordpress.public_ip}"
type = "ssh"
user = "bitnami" # Default username of the AMI
private_key = "${var.ec2_private_key}"
}
provisioner "file" {
source = "${path.module}/ec2-scripts/bootstrap.sh"
destination = "/tmp/bootstrap.sh"
}
provisioner "remote-exec" {
inline = [
"chmod +x /tmp/bootstrap.sh",
"/tmp/bootstrap.sh ${local.db_username} ${var.db_password} ${local.db_name} ${aws_db_instance.wordpress.address}",
"rm /tmp/bootstrap.sh"
]
}
}