-
Notifications
You must be signed in to change notification settings - Fork 0
/
challenge_lab_2.tf
134 lines (112 loc) · 2.53 KB
/
challenge_lab_2.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
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
Terraform_Challenge_2
1. Install terraform 1.1.5
wget https://releases.hashicorp.com/terraform/1.1.5/terraform_1.1.5_linux_amd64.zip
unzip terraform_1.1.5_linux_amd64.zip
mv terraform /usr/local/bin
terraform version
2. Check the docker provider
file: provide.tf
----------------
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "2.16.0"
}
}
}
provider "docker" {}
3. imgaes.tf
---------------
resource "docker_image" "php-httpd-image" {
name = "php-httpd:challenge"
build {
path = "/root/code/terraform-challenges/challenge2/lamp_stack/php_httpd/"
label = {
challenge : "second"
}
}
}
resource "docker_image" "mariadb-image" {
name = "mariadb:challenge"
build {
path = "/root/code/terraform-challenges/challenge2/lamp_stack/custom_db/"
label = {
challenge : "second"
}
}
}
4. volume.tf
----------------
resource "docker_volume" "mariadb_volume" {
name = "mariadb-volume"
}
5. network.tf
----------------
resource "docker_network" "private_network" {
name = "my_network"
}
6. container.tf
----------------
resource "docker_container" "php-httpd" {
name = "webserver"
image = docker_image.php-httpd-image.name
hostname = "php-httpd"
labels {
label = "challenge"
value = "second"
}
networks_advanced {
name = docker_network.private_network.name
}
ports {
internal = 80
external = 80
ip = "0.0.0.0"
}
volumes {
container_path = "/var/www/html"
host_path = "/root/code/terraform-challenges/challenge2/lamp_stack/website_content/"
}
}
resource "docker_container" "mariadb" {
name = "db"
image = docker_image.mariadb-image.name
hostname = "db"
labels {
label = "challenge"
value = "second"
}
networks_advanced {
name = docker_network.private_network.name
}
ports {
internal = 3306
external = 3306
ip = "0.0.0.0"
}
env = ["MYSQL_ROOT_PASSWORD=1234","MYSQL_DATABASE=simple-website"]
volumes {
container_path = "/var/lib/mysql"
volume_name = docker_volume.mariadb_volume.name
}
}
resource "docker_container" "phpmyadmin" {
name = "db_dashboard"
image = "phpmyadmin/phpmyadmin"
hostname = "phpmyadmin"
labels {
label = "challenge"
value = "second"
}
networks_advanced {
name = docker_network.private_network.name
}
ports {
internal = 80
external = 8081
ip = "0.0.0.0"
}
depends_on = [ docker_container.mariadb ]
links = [ docker_container.mariadb.name ]
}