May 13, 2024

Generate Fernet key using Terraform

Fernet keys can be generated using Python or OpenSSL, but what if you want to manage the key as part of your infra in Terraform/OpenTofu?

resource "random_password" "fernet" {
  length = 32
}

resource "azurerm_key_vault_secret" "fernet" {

  value = base64encode(random_password.fernet.result)

  name  = "fernet-key"
  key_vault_id = azurerm_key_vault.key_vault.id
}

Blog by lent.ink