Skip to content

Commit

Permalink
Setup proxy module
Browse files Browse the repository at this point in the history
  • Loading branch information
Taucher2003 committed Jul 13, 2024
1 parent 5777c84 commit 55b3f2b
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
67 changes: 67 additions & 0 deletions modules/docker/proxy/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "3.0.2"
}
cloudflare = {
source = "cloudflare/cloudflare"
version = "4.37.0"
}
}
}

resource "docker_image" "proxy" {
name = "jwilder/nginx-proxy:1.2.1"
}

resource "docker_network" "proxy" {
name = "proxy"
attachable = true
}

module "certificates" {
source = "../../cloudflare/certificate"
hostname = each.value
for_each = var.certificate_hostnames
}

resource "docker_container" "proxy" {
//noinspection HILUnresolvedReference
image = docker_image.proxy.image_id
name = "proxy"
restart = "always"

ports {
internal = 443
external = 443
}

network_mode = "bridge"

networks_advanced {
name = docker_network.proxy.id
}

volumes {
container_path = "/tmp/docker.sock"
host_path = "/var/run/docker.sock"
read_only = true
}

dynamic "upload" {
for_each = module.certificates
content {
file = "/etc/nginx/certs/${upload.value["hostname"]}.crt"
content = upload.value["certificate"]
}
}

dynamic "upload" {
for_each = module.certificates
content {
file = "/etc/nginx/certs/${upload.value["hostname"]}.key"
content = upload.value["private_key"]
}
}
}
3 changes: 3 additions & 0 deletions modules/docker/proxy/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "docker_proxy_network_id" {
value = docker_network.proxy.id
}
3 changes: 3 additions & 0 deletions modules/docker/proxy/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variable "certificate_hostnames" {
type = set(string)
}

0 comments on commit 55b3f2b

Please sign in to comment.