Pulumi Secret Stored as Plaintext in State
In this tutorial, you'll learn about Pulumi Secret Stored as Plaintext in State. We cover key concepts, practical examples, and best practices.
Pulumi secret values are stored in plaintext in the state file despite using the --secret flag.
Wrong ❌
// Wrong: passing sensitive values without the secret flag
import * as pulumi from "@pulumi/pulumi";
const config = new pulumi.Config();
const dbPassword = config.require("dbPassword"); // plaintext config
new aws.rds.Instance("db", {
password: dbPassword, // stored as plaintext in state
// ...
});
Wrong Output
Previewing update:
+ aws:rds:Instance "db" {
+ password : "my-plaintext-password" # Visible in state!
...
}
Right ✅
// Right: use secret configuration and secret outputs
import * as pulumi from "@pulumi/pulumi";
const config = new pulumi.Config();
const dbPassword = config.requireSecret("dbPassword"); // encrypted config
// Or set via: pulumi config set --secret dbPassword <value>
new aws.rds.Instance("db", {
password: dbPassword.apply(p => p), // stays encrypted in state
// ...
});
// Also mark outputs as secret
export const connectionString = pulumi.secret(
pulumi.interpolate`postgres://user:${dbPassword}@host:5432/db`
);
Right Output
Previewing update:
+ aws:rds:Instance "db" {
+ password : [secret] # Encrypted in state
...
}
Outputs:
connectionString: [secret]
Prevention
- Use config.requireSecret() instead of config.require() for sensitive configuration values.
- Set secret values with: pulumi config set --secret
. - Mark sensitive output values with pulumi.secret() to prevent leaks in the CLI output.
- Enable automatic secret encryption in the backend by configuring the Pulumi Cloud or self-managed backend with encryption.
- Audit state files periodically to ensure no plaintext secrets are exposed.
DodaTech applies similar defensive patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro infrastructure for production reliability.
Common Mistakes with secret encrypt
- Forgetting
deriving (Show, Eq)on custom data types needed for debugging - Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
- Using
headandtailinstead of pattern matching, causing runtime errors on empty lists
These mistakes appear frequently in real-world PULUMI code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
This quick fix is part of the DodaTech infrastructure engineering series. Learn more at DodaTech tutorials.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro