Page MenuHomeDevCentral

Manage properly Terraform states
Closed, ResolvedPublic

Description

Currently, Terraform states are on-disk. They will soon contain credentials with D4206.

Could we avoid to store those credentials on disk?

  • At software level. OpenTofu supports openbao as encryption backend, but Terraform doesn't
  • At provider level. With Vault provider 5.0+ can use a block json_data_wo to avoid to store in the Vault, but OVH doesn't have that.
  • At stanza level. Terraform suggests ephemeral blocks for that kind of use, but OVH provider doesn't support it
  • null_resource + local-exec. We could replace Terraform providers logic by a script to run locally to use OVH API and Vault CLI client. Works, but the Terraform point was to avoid that (if not, we would have done everything in Salt + salt-cloud).

On FreeBSD, we got good results with PEFS on devserver role.
So could we keep states on disk, but with encryption-at-rest?


Relevant links:

Event Timeline

dereckson triaged this task as High priority.
dereckson created this task.
dereckson added projects: security, Salt, Vault.
dereckson moved this task from Backlog to Servers config on the Salt board.
dereckson moved this task from Backlog to Working on on the Servers board.

Terraform state files can contain both personal information (ovh/ovh) or credentials (ovh/ovh, hashicorp/vault).
As such, they'll benefit to be stored locally and encrypted as rest.

Terraform files are now organized in several directories:

  • /opt/terraform is a ZFS dataset optimized for Go providers code
  • /opt/terraform.enc is a ZFS dataset as underlying storage for encrypted state
  • /opt/terraform/encrypted will be mounted on the fly, then unmounted after terraform/opentofu operation

We tested a simpler "everything encrypted", but PEFS doesn't cope well with executables and doesn't support mv.

A wrapper /usr/local/bin/tf takes care of all of that transparently:

  • pick appropriate terraform or tofu command
  • mount the PEFS volume, unmount it as exit (regular or error)
  • pass arguments

Back-end paths have been added to current terraform {} blocks.

Documentation at https://agora.nasqueron.org/Operations_grimoire/Deploy_with_Terraform has been updated.