Skip to content

You are viewing documentation for Instruqt 2.0 Labs - our upcoming product releasing in September 2026. For current Tracks documentation, please visitdocs.instruqt.com.

Random Password


Defined insandbox.hcl

The random_password resource generates cryptographically secure random passwords with configurable character sets and constraints. It supports customizable requirements for uppercase, lowercase, numeric, and special characters.

As a lab author, you can use random_password resources to:

  • Credential Generation: Generate secure, unique credentials for databases, services, and applications to avoid hardcoded passwords

Random password resources provide cryptographically secure credential generation with customizable complexity requirements.

resource "random_password" "name" {
length = 16
}
resource "random_password" "name" {
length = 32
# Character set options
special = true
numeric = true
lower = true
upper = true
# Minimum requirements
min_special = 2
min_numeric = 2
min_lower = 2
min_upper = 2
# Custom special characters
override_special = "!@#$%^&*"
}

Fields

FieldTypeRequiredDescription
lengthnumberTotal number of characters in the generated password
ConstraintsPassword length must be at least 1
specialboolWhen enabled, the password can contain special characters like !@#$%^&*(). Defaults to true if not specified.
Defaulttrue
numericboolWhen enabled, the password can contain digits 0-9. Defaults to true if not specified.
Defaulttrue
lowerboolWhen enabled, the password can contain lowercase letters. Defaults to true if not specified.
Defaulttrue
upperboolWhen enabled, the password can contain uppercase letters. Defaults to true if not specified.
Defaulttrue
override_specialstringProvide your own special characters to use in the password. If not specified, uses the default set of special characters.
min_specialnumberEnsures the password contains at least this many special characters. Defaults to 0.
Default0
ConstraintsMinimum special characters must be non-negative
min_numericnumberEnsures the password contains at least this many digits. Defaults to 0.
Default0
ConstraintsMinimum numeric characters must be non-negative
min_lowernumberEnsures the password contains at least this many lowercase letters. Defaults to 0.
Default0
ConstraintsMinimum lowercase characters must be non-negative
min_uppernumberEnsures the password contains at least this many uppercase letters. Defaults to 0.
Default0
ConstraintsMinimum uppercase characters must be non-negative

Computed Attributes

These attributes are set by the system and are read-only.

AttributeTypeDescription
valuestringThe generated password
resource "random_password" "admin" {
length = 12
}
output "admin_password" {
value = resource.random_password.admin.value
sensitive = true
}
resource "random_password" "db_password" {
length = 24
min_upper = 2
min_lower = 2
min_numeric = 2
min_special = 2
}
resource "container" "database" {
image {
name = "postgres:15"
}
environment = {
POSTGRES_PASSWORD = resource.random_password.db_password.value
}
}
resource "random_password" "api_key" {
length = 32
special = false # Only alphanumeric
}
resource "template" "config" {
source = <<-EOF
api:
key: "${resource.random_password.api_key.value}"
timeout: 30
EOF
destination = "./config/api.yaml"
}
resource "random_password" "secure_token" {
length = 20
override_special = "!@#$%" # Only these special chars
min_special = 3
min_numeric = 3
min_upper = 3
min_lower = 3
}
# Database password
resource "random_password" "postgres_password" {
length = 16
min_upper = 1
min_numeric = 2
min_special = 1
}
# Redis password
resource "random_password" "redis_password" {
length = 20
special = false # Redis doesn't handle some special chars well
}
# Application secret
resource "random_password" "app_secret" {
length = 32
min_special = 4
override_special = "@#$%^&*"
}
resource "template" "env_file" {
source = <<-EOF
# Database
POSTGRES_PASSWORD=${resource.random_password.postgres_password.value}
# Redis
REDIS_PASSWORD=${resource.random_password.redis_password.value}
# Application
APP_SECRET=${resource.random_password.app_secret.value}
EOF
destination = "./.env"
}
resource "random_password" "pin" {
length = 6
# Only numbers
special = false
upper = false
lower = false
numeric = true
}
resource "random_id" "username_suffix" {
byte_length = 4
}
resource "random_password" "user_password" {
length = 14
min_upper = 2
min_lower = 2
min_numeric = 2
min_special = 1
}
resource "template" "user_credentials" {
source = <<-EOF
username: user_${resource.random_id.username_suffix.hex}
password: ${resource.random_password.user_password.value}
EOF
destination = "./credentials.yaml"
}

Always mark password outputs as sensitive:

output "database_password" {
value = resource.random_password.db.value
sensitive = true
}
# Good: Use in environment variables or config files
resource "container" "app" {
environment = {
DB_PASSWORD = resource.random_password.db.value
}
}
# Avoid: Don't log or output passwords directly
resource "exec" "bad_example" {
script = "echo 'Password: ${resource.random_password.db.value}'" # DON'T DO THIS
}
  1. Length: Use at least 12 characters for production passwords
  2. Complexity: Include multiple character types for stronger passwords
  3. Minimums: Set minimum requirements for critical applications
  4. Special Characters: Consider target system limitations when choosing special chars
  5. Sensitive Data: Always mark password outputs as sensitive
  6. Rotation: Generate new passwords by changing resource names or recreating resources
  7. Documentation: Document password requirements and usage