Recipes
Short, practical setups. Every sample works with Terraform and with OpenTofu 1.11 or later. Replace the names with your own.
Set up a tenant from zero
The tenant already exists, because it comes from sign-up. This recipe fills it with access, a secret, a task, its code and a hook. Use two root modules, so the daily job never holds the owner key.
1 · Access, with the owner key
Apply this once, by hand. It makes a user, a group and a key for CI.
terraform {
required_version = ">= 1.11"
required_providers {
ignitify = { source = "ignitify-dev/ignitify" }
}
}
provider "ignitify" {}
resource "ignitify_user" "ci" {
name = "ci"
}
resource "ignitify_group" "deployers" {
name = "deployers"
permissions = [
"tasks.read", "tasks.write",
"deployments.read", "deployments.write",
"secrets.read", "secrets.write",
"hooks.read", "hooks.write",
"runs.read",
# Add "runs.write" when CI also starts runs (ignitify task:run).
# Add "schedules.read" and "schedules.write" when CI also manages ignitify_schedule
# (provider 0.5.0 or later).
]
members = [ignitify_user.ci.name]
}
resource "ignitify_api_key" "ci" {
user = ignitify_user.ci.name
label = "ci-pipeline"
}
output "ci_key" {
value = ignitify_api_key.ci.raw_key
sensitive = true
}$ IGNITIFY_API_KEY=<owner key> terraform applyRead the key once with terraform output -raw ci_key and put it in the secret store of your CI system. Do not print it to a log.
2 · The app, with the user key
CI applies this with the user key from step 1.
terraform {
required_version = ">= 1.11"
required_providers {
ignitify = { source = "ignitify-dev/ignitify" }
}
}
provider "ignitify" {}
variable "db_password" {
type = string
sensitive = true
ephemeral = true
}
resource "ignitify_secret" "db_password" {
name = "DB_PASSWORD"
value_wo = var.db_password
value_wo_version = 1
}
resource "ignitify_task" "report" {
slug = "report"
}
resource "ignitify_deployment" "report" {
task = ignitify_task.report.slug
source_dir = "${path.module}/report"
}
resource "ignitify_hook" "report" {
task = ignitify_task.report.slug
}
output "hook_url" {
value = ignitify_hook.report.url
}$ IGNITIFY_API_KEY=<user key> TF_VAR_db_password=<value> terraform applyThe apply makes the secret, the task, uploads and builds the code, then makes the hook. The report folder holds a task config with slug: report and a task that reads DB_PASSWORD. See Your first task.
Roll a code update
Change a file in the task folder, then plan and apply.
$ terraform plan # ignitify_deployment.report will be updated in-place ~ resource "ignitify_deployment" "report" { ~ deployment_id = "<old id>" -> (known after apply) ~ source_hash = "<old hash>" -> "<new hash>" }Plan: 0 to add, 1 to change, 0 to destroy.
- The apply builds the new deployment first. It deletes the old one only when the new one is READY.
- The hook keeps its URL and its secret.
- A failed build keeps the old deployment live. Fix the code and apply again.
- Runs that are still running on the old deployment end, and its run history is deleted. Apply when no run you need is in flight.
Rotate a secret
Terraform cannot see a write-only value, so a new value needs a new version number.
resource "ignitify_secret" "db_password" {
name = "DB_PASSWORD"
value_wo = var.db_password
value_wo_version = 2 # was 1
}$ TF_VAR_db_password=<new value> terraform applyA task reads the new value on its next run. A VM that is already running keeps the value it started with.
Rotate a user key or a hook
Replace the resource. The new one has a new value, and the old one stops working.
$ terraform apply -replace=ignitify_api_key.ci$ terraform apply -replace=ignitify_hook.reportAfter a key replace, put the new key in your CI store. After a hook replace, give the new URL and secret to the sender.
Bring existing objects under Terraform
You made a task, a secret or a user with the CLI, and now you want Terraform to own it. Write the resource, then import it. The plan must show no change before you apply.
resource "ignitify_task" "report" {
slug = "report"
}
resource "ignitify_secret" "db_password" {
name = "DB_PASSWORD"
value_wo = var.db_password
}$ terraform import ignitify_task.report report$ terraform import ignitify_secret.db_password DB_PASSWORD- Import a task before its deployment and its hook.
- After an import of a key or a hook, the raw key or secret is empty. Replace the resource to get a new one.
- A secret with no version in your code is not sent. Set
value_wo_versiononly when you want the first apply to write your value.
Each resource page lists its import id.
Use it from CI
A CI job needs the provider, the user key, the secret values and a state backend.
- Key. Store the user key in the secret store of your CI system. Expose it to the job as
IGNITIFY_API_KEY. - Values. Expose each secret value as
TF_VAR_<name>, for anephemeralvariable. - State. Use an encrypted backend with limited access. The state holds hook secrets and user keys.
- Steps. Run
init, thenplan -out, thenapplyof that plan file. Apply only from your main branch. - Time. A deployment waits for the build, which can take minutes. Set
timeoutson the deployment, and a job timeout above it.
terraform init -input=false
terraform plan -input=false -out=tfplan
terraform apply -input=false tfplan