forked from colinwilson/terraform-docker-traefik-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.tf
147 lines (123 loc) · 3.48 KB
/
service.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
# Create Traefik Docker service
resource "docker_service" "traefik" {
name = "traefik"
task_spec {
container_spec {
image = "traefik:${var.traefik_version}"
env = {
# Cloudflare API Tokens for Let's Encrypt DNS Challange
CF_DNS_API_TOKEN = var.cloudflare_dns_token
CF_ZONE_API_TOKEN = var.cloudflare_zone_token
CF_API_EMAIL = var.cloudflare_email
CF_API_KEY = var.cloudflare_api_key
}
labels {
label = "traefik.enable"
value = true
}
labels {
label = "traefik.http.routers.http_catchall.rule"
value = "HostRegexp(`{any:.+}`)"
}
labels {
label = "traefik.http.routers.http_catchall.entrypoints"
value = "http"
}
labels {
label = "traefik.http.routers.http_catchall.middlewares"
value = "https_redirect"
}
labels {
label = "traefik.http.middlewares.https_redirect.redirectscheme.scheme"
value = "https"
}
labels {
label = "traefik.http.middlewares.https_redirect.redirectscheme.permanent"
value = true
}
labels {
label = "traefik.http.routers.traefik.rule"
value = "Host(`${var.hostname}`)"
}
labels {
label = "traefik.http.routers.traefik.entrypoints"
value = "https"
}
labels {
label = "traefik.http.routers.traefik.tls.certresolver"
value = var.live_cert == false ? "letsEncryptStaging" : "letsEncrypt"
}
labels {
label = "traefik.http.middlewares.traefik-basic-auth.basicauth.users"
value = "admin:${bcrypt(var.password)}"
}
labels {
label = "traefik.http.middlewares.traefik-basic-auth.basicauth.removeheader"
value = true
}
labels {
label = "traefik.http.routers.traefik.middlewares"
value = "traefik-basic-auth"
}
labels {
label = "traefik.http.routers.traefik.service"
value = "api@internal"
}
# Promerheus Metrics config
labels {
label = "traefik.http.routers.metrics.rule"
value = "Host(`traefik`) && PathPrefix(`/metrics`)"
}
labels {
label = "traefik.http.routers.metrics.entrypoints"
value = "http"
}
labels {
label = "traefik.http.routers.metrics.service"
value = "prometheus@internal"
}
labels {
label = "traefik.http.routers.metrics.middlewares"
value = "traefik-basic-auth"
}
configs {
config_id = docker_config.traefik-yaml.id
config_name = docker_config.traefik-yaml.name
file_name = "/traefik.yaml"
}
mounts {
target = "/var/run/docker.sock"
source = "/var/run/docker.sock"
type = "bind"
read_only = true
}
mounts {
source = docker_volume.traefik_acme.name
target = "/etc/traefik/acme"
type = "volume"
read_only = false
}
}
networks_advanced {
name = docker_network.traefik.name
}
dynamic "networks_advanced" {
for_each = values(data.docker_network.additional_networks).*.id
content {
name = networks_advanced.key
}
}
}
endpoint_spec {
ports {
target_port = "80"
published_port = "80"
publish_mode = "host"
}
ports {
target_port = "443"
published_port = "443"
publish_mode = "host"
}
}
}