Passwords/Sensitive data in TfState files

Hi @adi658,

Whether a value is stored in the state depends on how it is used rather than how it is passed in to Terraform. Any value you use in the arguments inside a resource or data block, along with any values exported by the resource type or data source, will always be in the state, so that they can be used for planning on future runs.

There are some specific places you can use values where they will not appear in the state:

  • Inside provider blocks
  • Inside provisioner blocks within resource blocks
  • Inside connection blocks within resource or provisioner blocks

As long as you only use var.password in one of the above contexts, it will not appear in the state snapshot.


Terraform Cloud offers free remote state storage, which is one free option though it does still require you to create a Terraform Cloud account.

There are several remote backends that can be used with infrastructure you run yourself, such as http, consul, and pg. The http backend gives the most flexibility since you can implement a custom HTTP application that recieves and stores the state snapshots however you like, including using your own encryption keys for encryption at rest.