Last week I got tired of how I configured my VPS. My nginx config got confusing and I had random servers running in tmux everywhere, and some left over docker containers I didn’t realise were running.
This leads me to this submission! I decided to reinstall the os and terraform the entire thing, and I opted to use caddy for my routing. I couldn’t find a terraform provider for caddy already, but I did find the admin API, so I decided to write my own.
I really like how it came out and it works really well.
resource "caddy_server" "https" {
name = "https"
listen = [":443"]
route {
match {
host = ["first.example.com"]
}
handle {
static_response {
body = "hello world"
}
}
}
route {
match {
host = ["second.example.com"]
}
handle {
static_response {
body = "goodbye world"
}
}
}
}
On my own server, I combine this with the docker terraform provider with a config like this
I hope someone else finds this interesting or useful. The provider is definitely still in beta, and the documentation is a bit sparse, but I intend to keep adding more docs/features as I get the time. This is also my first time with caddy, feedback appreciated
Apologies from taking this project away from you, but I’ll happily help you get set up if you have any issues, as well as accepting PRs you may want to contribute
I see you intend to you Caddy with Consul for certificate storage. I haven’t yet implemented storage configuration options in the terraform provider, although it won’t be too hard. I was thinking for a while about what to do with regards to non-standard caddy configurations. I think that it’s OK to have the terraform schema contain the non-standard definitions. Caddy will just error if I try to load an invalid config (for example if I tried to configure consul without the module built into my caddy server - will need testing to see how it reacts exactly though). The non-standard schema definitions will just be documented non-standard, like how caddy represents non standard json configs: JSON Config Structure - Caddy Documentation