-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflex_drupal_instance.yaml
161 lines (150 loc) · 5.66 KB
/
flex_drupal_instance.yaml
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
heat_template_version: 2018-08-31
description: >
This Heat template provisions a virtual machine on OpenStack with a specified flavor, image, and SSH key, sets up a private network and subnet, configures routing to an external network, installs a LAMP stack (Linux, Apache, MySQL, PHP) on the instance, and installs a ready-to-use Drupal 10 installation. It includes security group rules to allow SSH, HTTP, and HTTPS access and assigns a floating IP to the instance for public accessibility. The user can specify the domain name for the Drupal site.
parameters:
flavor:
type: string
description: Flavor of the instance
default: $FLAVOR_NAME
image:
type: string
description: Image to use for the instance
default: $IMAGE_ID
key_name:
type: string
description: Name of the SSH key to use
default: $KEY_NAME
public_net_id:
type: string
description: ID of the public network
default: $PUBLICNET_ID
domain_name:
type: string
description: Domain name for the Drupal site
resources:
private_net:
type: OS::Neutron::Net
properties:
name: private_net
private_subnet:
type: OS::Neutron::Subnet
properties:
network_id: { get_resource: private_net }
cidr: "192.168.0.0/24"
gateway_ip: "192.168.0.1"
ip_version: 4
dns_nameservers:
- "8.8.8.8"
- "8.8.4.4"
router:
type: OS::Neutron::Router
properties:
name: router
external_gateway_info:
network: { get_param: public_net_id }
router_interface:
type: OS::Neutron::RouterInterface
properties:
router_id: { get_resource: router }
subnet_id: { get_resource: private_subnet }
instance_port:
type: OS::Neutron::Port
properties:
network_id: { get_resource: private_net }
security_groups: [{ get_resource: instance_security_group }]
instance_security_group:
type: OS::Neutron::SecurityGroup
properties:
name: instance_security_group
description: Security group for the instance
rules:
- direction: ingress
ethertype: IPv4
protocol: tcp
port_range_min: 22
port_range_max: 22
- direction: ingress
ethertype: IPv4
protocol: icmp
- direction: ingress
ethertype: IPv4
protocol: tcp
port_range_min: 80
port_range_max: 80
- direction: ingress
ethertype: IPv4
protocol: tcp
port_range_min: 443
port_range_max: 443
floating_ip:
type: OS::Neutron::FloatingIP
properties:
floating_network_id: { get_param: public_net_id }
port_id: { get_resource: instance_port }
instance:
type: OS::Nova::Server
properties:
flavor: { get_param: flavor }
image: { get_param: image }
key_name: { get_param: key_name }
networks:
- port: { get_resource: instance_port }
user_data:
str_replace:
template: |
#!/bin/bash
# Update and install Apache
apt-get update -y
apt-get install -y apache2
# Start Apache service
systemctl start apache2
systemctl enable apache2
# Install MySQL
debconf-set-selections <<< 'mysql-server mysql-server/root_password password root'
debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password root'
apt-get install -y mysql-server
# Install PHP and additional modules required for Drupal
apt-get install -y php libapache2-mod-php php-mysql php-gd php-xml php-mbstring php-zip php-curl
# Restart Apache to load PHP
systemctl restart apache2
# Download and install Drupal
apt-get install -y wget
cd /var/www/html
wget https://www.drupal.org/download-latest/tar.gz -O drupal.tar.gz
tar -xzvf drupal.tar.gz
mv drupal-* drupal
chown -R www-data:www-data drupal
chmod -R 755 drupal
# Set up Drupal database
mysql -uroot -proot -e "CREATE DATABASE drupal; GRANT ALL PRIVILEGES ON drupal.* TO 'drupaluser'@'localhost' IDENTIFIED BY 'drupalpass'; FLUSH PRIVILEGES;"
# Create settings.php
cp drupal/sites/default/default.settings.php drupal/sites/default/settings.php
chown www-data:www-data drupal/sites/default/settings.php
# Configure Apache VirtualHost
echo "<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/drupal
ServerName $DOMAIN_NAME
<Directory /var/www/html/drupal>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog \${APACHE_LOG_DIR}/error.log
CustomLog \${APACHE_LOG_DIR}/access.log combined
</VirtualHost>" > /etc/apache2/sites-available/drupal.conf
a2ensite drupal.conf
a2enmod rewrite
systemctl restart apache2
# Finalize installation
echo "Drupal installation completed. Please complete the installation through the web interface at http://$DOMAIN_NAME."
params:
"$FLAVOR_NAME": { get_param: flavor }
"$IMAGE_ID": { get_param: image }
"$KEY_NAME": { get_param: key_name }
"$PUBLICNET_ID": { get_param: public_net_id }
"$DOMAIN_NAME": { get_param: domain_name }
outputs:
instance_ip:
description: IP address of the instance
value: { get_attr: [floating_ip, floating_ip_address] }