liveBook · Manning

Random_password

As explained in Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu

random_password is a Terraform resource type from the hashicorp/random provider that generates a random password value and treats it as sensitive.

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

How Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu covers it

How deep it goes
Explains configuration, persistence, cryptographic randomness, sensitive state storage, and controlled regeneration through keepers.
Examples
Uses twelve- and sixteen-character configurations, a child module, sensitive outputs, state JSON, and character-class constraints.
What you can do after
Build it from scratch with Terraform, expose the result safely, inspect its state representation, and configure deliberate rotation.
How it connects
Connects random_password to the random provider, Terraform state, modules, outputs, sensitive values, and keepers.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu. The section links point to the parts of the book it draws on.