random_password generates a password through Terraform’s hashicorp/random provider. Unlike ordinary random values, it persists its result between runs and changes only when a keepers value changes. section 6.8.1
Generate and expose a password
A minimal resource sets a length and exposes its result through a sensitive output: resource "random_password" "new_password" { length = 12 } output "password" { value = random_password.new_password.result sensitive = true } The resource can be placed in a child module and consumed as module.my_password.password. Initialize and apply the configuration to create local state and inspect how Terraform records the resource and output. section 6.3.1
Account for these operational details:
- The result is marked sensitive, so Terraform should warn about or suppress it in displayed output; sensitivity does not remove it from state. section 6.8.1
- Protect the state file and restrict access when the generated value becomes a real credential. section 6.8.1
- Use keepers to deliberately rotate the password when selected input values change. section 6.8.1
