Terraform is used to manage resources that have lifecycles, configurations, to sum it up.
That is the case of CTFd: it handles challenges that could be created, modified and deleted. With some work to leverage the unsteady CTFd's API, Terraform is now able to manage them as cloud resources bringing you to opportunity of CTF as Code.
With a paradigm-shifting vision of setting up CTFs, the Terraform Provider for CTFd avoid shitty scripts, ctfcli and other tools that does not solve the problem of reproductibility, ease of deployment and resiliency.
Install the Terraform Provider for CTFd by setting the following in your main.tf file.
terraform {
required_providers {
ctfd = {
source = "registry.terraform.io/ctfer-io/ctfd"
}
}
}
provider "ctfd" {
url = "https://my-ctfd.lan"
}We recommend setting the environment variable CTFD_API_KEY to enable the provider to communicate with your CTFd instance.
Then, you could use a ctfd_challenge_standard resource to setup your CTFd challenges, with for instance the following configuration.
resource "ctfd_challenge_standard" "my_challenge" {
name = "My Challenge"
category = "Some category"
description = <<-EOT
My superb description !
And it's multiline :o
EOT
state = "visible"
value = 500
}Understanding what is going on under the hood or what could fail throughout the CTF lifecycle remains an important concern, even with such provider. For better understandability, we ship support for OpenTelemetry.
You can configure it using the SDK environment variables.
Note that CTFd does not support it natively, you may want to use our instrumented and packaged CTFd or proceed similarly for auto-instrumentation.
Also, the provider uses the always sampler hence we recommend you use a Collector probability sampler. An example follows, with arbitrary values.
processors:
probabilistic_sampler:
hash_seed: 22
sampling_percentage: 22
service:
pipelines:
traces:
receivers: [...]
processors: [probabilistic_sampler, ...]
exporters: [...]A more complete example is available here.