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 a dedicated Terraform token. Create one on the token management page in the dashboard — for security it is shown only once, at the moment it is created. Pass it to the provider (typically via a variable or the FMAILER_TOKEN environment variable rather than hard-coding it).

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.