-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinstance.tf
59 lines (52 loc) · 1.97 KB
/
instance.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
# EC2 instance with Wordpress installation
resource "aws_instance" "WordPress" {
depends_on = [aws_internet_gateway.public_internet_gw]
ami = "ami-0732b62d310b80e97"
instance_type = "t2.micro"
key_name = aws_key_pair.deployer.key_name
subnet_id = aws_subnet.public_subnet.id
vpc_security_group_ids = [aws_security_group.SG_public_subnet.id]
tags = {
Name = "WEB"
}
user_data = <<EOF
#! /bin/bash
sudo yum install httpd php php-mysql -y -q
sudo cd /var/www/html
echo "Welcome" > hi.html
sudo wget https://wordpress.org/wordpress-5.1.1.tar.gz
sudo tar -xzf wordpress-5.1.1.tar.gz
sudo cp -r wordpress/* /var/www/html/
sudo rm -rf wordpress
sudo rm -rf wordpress-5.1.1.tar.gz
sudo chmod -R 755 wp-content
sudo chown -R apache:apache wp-content
sudo wget https://s3.amazonaws.com/bucketforwordpresslab-donotdelete/htaccess.txt
sudo mv htaccess.txt .htaccess
sudo systemctl start httpd
sudo systemctl enable httpd
EOF
provisioner "local-exec" {
command = "echo ${aws_instance.WordPress.public_ip} > publicIP.txt"
}
}
# Launching RDS db instance
resource "aws_db_instance" "DataBase" {
allocated_storage = 20
max_allocated_storage = 100
storage_type = "gp2"
engine = "mysql"
engine_version = "5.7.22"
instance_class = "db.t2.micro"
name = "mydb"
username = "apeksh"
password = "apeksh1234"
parameter_group_name = "default.mysql5.7"
publicly_accessible = false
db_subnet_group_name = aws_db_subnet_group.db_subnet.name
vpc_security_group_ids = [aws_security_group.SG_private_subnet_.id]
skip_final_snapshot = true
provisioner "local-exec" {
command = "echo ${aws_db_instance.DataBase.endpoint} > DB_host.txt"
}
}