-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.tf
192 lines (156 loc) · 5.22 KB
/
main.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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
provider "digitalocean" {
}
provider "linuxbox" {
ssh_session_limit = 3
}
resource "digitalocean_droplet" "test" {
image = "ubuntu-18-04-x64"
name = "terraform-test-1"
region = "lon1"
size = "s-1vcpu-1gb"
private_networking = true
ssh_keys = [digitalocean_ssh_key.terraform.fingerprint]
}
resource "tls_private_key" "ssh_key" {
algorithm = "ECDSA"
ecdsa_curve = "P521"
}
resource "digitalocean_ssh_key" "terraform" {
name = "Terraform Test"
public_key = tls_private_key.ssh_key.public_key_openssh
}
resource "linuxbox_swap" "host_swap" {
host_address = digitalocean_droplet.test.ipv4_address
ssh_key = tls_private_key.ssh_key.private_key_pem
swap_size = "100m"
}
# resource "linuxbox_docker" "docker" {
# host_address = digitalocean_droplet.test.ipv4_address
# ssh_key = tls_private_key.ssh_key.private_key_pem
# }
resource "linuxbox_directory" "foo" {
host_address = digitalocean_droplet.test.ipv4_address
ssh_key = tls_private_key.ssh_key.private_key_pem
path = "/foo"
owner = 0
group = 0
}
resource "linuxbox_text_file" "test_file" {
host_address = digitalocean_droplet.test.ipv4_address
ssh_key = tls_private_key.ssh_key.private_key_pem
path = "${linuxbox_directory.foo.path}/this is a test"
content = "testesttest"
owner = 0
group = 0
}
resource "linuxbox_binary_file" "test_binfile" {
host_address = digitalocean_droplet.test.ipv4_address
ssh_key = tls_private_key.ssh_key.private_key_pem
path = "${linuxbox_directory.foo.path}/this is a test - binary%"
content_base64 = base64encode("test-binary")
owner = 0
group = 0
}
resource "linuxbox_run_setup" "install_docker" {
host_address = digitalocean_droplet.test.ipv4_address
ssh_key = tls_private_key.ssh_key.private_key_pem
setup = [
"apt update",
"apt install -y apt-transport-https ca-certificates curl software-properties-common",
"curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -",
"add-apt-repository \"deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable\"",
"apt update",
"apt install -y docker-ce",
]
}
resource "linuxbox_docker_network" "test_network" {
depends_on = [linuxbox_run_setup.install_docker]
host_address = digitalocean_droplet.test.ipv4_address
ssh_key = tls_private_key.ssh_key.private_key_pem
name = "test"
}
resource "linuxbox_docker_run" "test_run" {
depends_on = [linuxbox_run_setup.install_docker]
host_address = digitalocean_droplet.test.ipv4_address
ssh_key = tls_private_key.ssh_key.private_key_pem
image_id = "alpine:latest"
clear_entry_point = true
args = ["echo", "foo"]
}
resource "linuxbox_ssh_authorized_key" "docker" {
host_address = digitalocean_droplet.test.ipv4_address
ssh_key = tls_private_key.ssh_key.private_key_pem
key_to_add = file("~/.ssh/id_rsa.pub")
}
resource "linuxbox_docker_copy_image" "service" {
depends_on = [linuxbox_run_setup.install_docker]
host_address = digitalocean_droplet.test.ipv4_address
ssh_key = tls_private_key.ssh_key.private_key_pem
image_id = linuxbox_docker_build.sample_service.image_id
}
data "linuxbox_source_hash" "sample_service" {
sources = ["sample_service"]
}
resource "linuxbox_docker_build" "sample_service" {
source_dir = "${path.module}/sample_service"
source_hash = data.linuxbox_source_hash.sample_service.hash
}
resource "linuxbox_docker_container" "webpage" {
depends_on = [linuxbox_run_setup.install_docker]
ssh_key = tls_private_key.ssh_key.private_key_pem
image_id = linuxbox_docker_copy_image.service.image_id
host_address = digitalocean_droplet.test.ipv4_address
labels = {
"traefik.enable" = "true"
"traefik.port" = "80"
"traefik.frontend.rule" = "Host:${digitalocean_droplet.test.ipv4_address}.nip.io"
}
env = {
"foo" = "bar"
}
name = "nginx"
caps = ["IPC_LOCK"]
restart = "unless-stopped"
network = "bridge"
log_opts = {
"max-file" = 3
}
// 100 megs
memory = 104857600
}
resource "linuxbox_docker_container" "traefik" {
depends_on = [linuxbox_run_setup.install_docker]
ssh_key = tls_private_key.ssh_key.private_key_pem
image_id = "traefik:v1.7.19-alpine"
host_address = digitalocean_droplet.test.ipv4_address
ports = [
"127.0.0.1:80:80",
"443:443",
]
volumes = [
"/var/run/docker.sock:/var/run/docker.sock",
"/acme:/acme",
]
restart = "unless-stopped"
privileged = true
args = [
"--accesslog",
"--defaultentrypoints=http",
"--defaultentrypoints=http,https",
"--entrypoints=Name:http Address::80",
"--entryPoints=Name:https Address::443 TLS",
"--docker",
"--docker.watch",
"--docker.exposedbydefault", "false",
"--acme",
"--acme.entryPoint=https",
"--acme.httpChallenge.entryPoint=http",
"--acme.OnHostRule=true",
"--acme.onDemand=false",
"--acme.tlsconfig=true",
"--acme.storage=/acme/certs.json",
# "--providers.docker.endpoint=unix:///var/run/docker.sock",
]
name = "traefik"
}