Docs / Templates as code (Terraform)

Templates as code (Terraform)

The official Terraform provider lets you describe your email templates in code, keep them under version control, and ship changes through CI/CD instead of editing them by hand in the dashboard. The provider is published on the Terraform Registry as skymanrm/fmailer.

Provider on Terraform Registry

Authentication

The provider authenticates with your account token, on Dashboard → Profile in the Using Terraform card. It is shown in full whenever you open that page, and Generate New Token replaces it — the old value stops working immediately. Pass it to the provider (typically via a variable or the FMAILER_TOKEN environment variable rather than hard-coding it).

Despite the name, this token is not Terraform-specific: it is the credential for the whole account API, sent as a bare Authorization: <token> header — see Authenticating API calls. It carries everything your login can do, so treat it as a password. It is not the same thing as a domain token, which authenticates one domain for sending and SMTP only.

main.tf
terraform {
  required_providers {
    fmailer = {
      source = "skymanrm/fmailer"
    }
  }
}

provider "fmailer" {
  token = var.fmailer_token
}

Defining a template

Each fmailer_template resource maps to one template. Reference the body from a file so the markup lives next to the rest of your code, and list the locales you support for localized sends.

templates.tf
resource "fmailer_template" "welcome" {
  name    = "welcome"
  subject = "Welcome!"
  locales = ["ru", "en"]
  body    = file("templates/welcome.html")
}

Applying changes

Run terraform init once to download the provider, then terraform plan and terraform apply to push your templates to Postwing. Wire the same commands into your pipeline to deploy template changes automatically on merge.

bash
terraform init && terraform apply
Once a template is deployed, send it over the REST API or the Python SDK by referencing its name.