-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
71 lines (60 loc) · 1.84 KB
/
main.py
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
# Provider configuration for AWS
provider "aws" {
region = "us-west-2"
}
# Create an RDS MySQL database
resource "aws_db_instance" "wordpress_db" {
allocated_storage = 20
engine = "mysql"
engine_version = "5.7"
instance_class = "db.t2.micro"
name = "wordpress_db"
username = "wordpress"
password = "password"
}
# Create a security group to allow access to the database
resource "aws_security_group" "wordpress_db_sg" {
name_prefix = "wordpress_db_sg"
ingress {
from_port = 3306
to_port = 3306
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
# Create a WordPress EC2 instance
resource "aws_instance" "wordpress" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
key_name = "my_key_pair"
vpc_security_group_ids = [aws_security_group.wordpress_sg.id]
user_data = <<-EOF
#!/bin/bash
yum update -y
yum install -y httpd php php-mysql
# Download and install WordPress
cd /var/www/html
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
cp -r wordpress/* .
rm -rf wordpress latest.tar.gz
# Configure WordPress
cp wp-config-sample.php wp-config.php
sed -i 's/database_name_here/wordpress_db/g' wp-config.php
sed -i 's/username_here/wordpress/g' wp-config.php
sed -i 's/password_here/password/g' wp-config.php
EOF
tags = {
Name = "wordpress"
}
}
# Create a security group to allow access to the EC2 instance
resource "aws_security_group" "wordpress_sg" {
name_prefix = "wordpress_sg"
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}