Browse Source

deploy wordpress sample

master
Vladimir Smagin 5 months ago
commit
7abdb27f6a
Signed by: Vladimir Smagin <21h@blindage.org> GPG Key ID: 29AE91B1A37721C3
4 changed files with 56 additions and 0 deletions
  1. 3
    0
      .gitignore
  2. 42
    0
      docker.tf
  3. 7
    0
      images.tf
  4. 4
    0
      network.tf

+ 3
- 0
.gitignore View File

@@ -0,0 +1,3 @@
1
+.terraform
2
+*.tfstate*
3
+

+ 42
- 0
docker.tf View File

@@ -0,0 +1,42 @@
1
+provider "docker" {
2
+  host = "unix:///run/docker.sock"
3
+}
4
+
5
+output "address_wp" {
6
+  value = "${docker_container.wordpress.ip_address}"
7
+}
8
+
9
+output "address_my" {
10
+  value = "${docker_container.mysql.ip_address}"
11
+}
12
+
13
+resource "docker_container" "wordpress" {
14
+  image    = "${docker_image.wordpress.latest}"
15
+  restart = "always"
16
+  networks = ["${docker_network.private_network.id}"]
17
+  name     = "wordpress"
18
+  env = [
19
+    "MYSQL_ROOT_PASSWORD=bubukaka", 
20
+    "WORDPRESS_DB_NAME=wordpress",
21
+    "WORDPRESS_DB_USER=wordpress",
22
+    "WORDPRESS_DB_PASSWORD=wordpress",
23
+    "WORDPRESS_DB_HOST=${docker_container.mysql.domainname}:3306"
24
+  ]
25
+  network_mode = "bridge"
26
+}
27
+
28
+resource "docker_container" "mysql" {
29
+  image    = "${docker_image.mysql.latest}"
30
+  restart = "always"
31
+  networks = ["${docker_network.private_network.id}"]
32
+  hostname = "mysql"
33
+  domainname = "mysql"
34
+  name     = "mysql"
35
+  env = [
36
+    "MYSQL_ROOT_PASSWORD=bubukaka", 
37
+    "MYSQL_DATABASE=wordpress",
38
+    "MYSQL_USER=wordpress",
39
+    "MYSQL_PASSWORD=wordpress"
40
+  ]
41
+  network_mode = "bridge"
42
+  }

+ 7
- 0
images.tf View File

@@ -0,0 +1,7 @@
1
+resource "docker_image" "mysql" {
2
+  name = "mysql:latest"
3
+}
4
+
5
+resource "docker_image" "wordpress" {
6
+  name = "wordpress:latest"
7
+}

+ 4
- 0
network.tf View File

@@ -0,0 +1,4 @@
1
+resource "docker_network" "private_network" {
2
+  name = "private-network"
3
+}
4
+

Loading…
Cancel
Save