Table of Contents
- Overview
- Configuration Management
- Managing Secrets
- Best Practices
- Troubleshooting
- Example: YAML Stack File
- Security Recommendations
- Conclusion
Pulumi: Configuration & Secrets — Overview
What Is Pulumi Configuration & Secrets?
Pulumi's configuration and secrets system is a foundational part of how Pulumi manages infrastructure-as-code projects. It provides a structured, secure way to supply your stacks and deployments with values—like regions, endpoints, resource sizes, and highly sensitive data such as passwords, tokens, or API keys—without hardcoding them directly in your codebase.
Configuration in Pulumi refers to key/value pairs that parameterize how your infrastructure gets deployed. These can be general (applied to all stacks) or specific (tailored per environment, like development, staging, or production).
Secrets are a special subset of configuration values that are encrypted and protected using configurable encryption backends (such as a passphrase, cloud KMS, or a vault), ensuring sensitive information never appears in plain text in files, logs, or code.
Why Is Pulumi Configuration & Secrets Important?
- Security: It provides mandatory encryption for secrets so that credentials and sensitive values stay protected, even if stack files are checked into source control.
- Separation of Concerns: Keeps dynamic or environment-specific information out of code, making infrastructure easier to reuse and reason about.
- Auditability and Automation: Enables safe automation across different environments (dev, prod, test) and ensures all changes to configuration or secrets are deliberate and logged.
- Collaboration: Allows teams to share code while keeping sensitive values and environment-specific overrides out of code repositories.
How Does It Work?
- Configuration and secrets are stored in stack files in YAML format, which Pulumi manages automatically. Regular values are stored as plaintext, while secrets are stored as encrypted blobs.
- You use the Pulumi CLI (e.g.,
pulumi config set
,pulumi config set --secret
) to define, update, or remove configuration values—never editing YAML by hand. - In your Pulumi code, you retrieve config using the SDK's
Config
object (e.g.,config.require("region")
for plain values,config.requireSecret("apiKey")
for secrets). This pattern makes code environment-agnostic and secure. - The secrets provider used for encryption can be a simple passphrase (good for local/test usage) or an enterprise-ready solution like AWS KMS, Azure Key Vault, or GCP KMS—ensuring compliance and strong protection for production or team environments.
In summary: Pulumi Configuration & Secrets enables you to securely, flexibly, and efficiently parameterize infrastructure deployments, automate across environments, and keep sensitive data safe—all critical for modern cloud, DevOps, and network automation workflows.
Configuration Management
Pulumi's configuration system allows you to manage settings, parameters, and secrets for different environments, such as development, staging, and production. Here’s a step-by-step guide on managing configuration in Pulumi:
-
Initialize Your Project:
Runpulumi new
to bootstrap a new Pulumi project. Choose a template that matches your tech stack (e.g., AWS, Azure, Kubernetes). -
Understand Project vs. Stack Configuration:
- Project-level config applies to all stacks in the project.
- Stack-level config is unique to each stack (like dev, staging, prod).
-
Set a Configuration Value:
Usepulumi config set <key> <value>
to define a value. For example:pulumi config set region us-west-2
. -
List All Configurations:
See all config values for the current stack by runningpulumi config
. -
Retrieve Config Values in Code:
Access configuration inside your program using the SDK’s config module. Example (TypeScript):
const config = new pulumi.Config();
const region = config.require("region"); -
Remove a Configuration Value:
Clear an unused or incorrect config withpulumi config rm <key>
. -
Work With Secrets:
Add a sensitive value like a password usingpulumi config set --secret <key> <value>
. This ensures the value is encrypted and not readable in plain text. -
Review Configuration in Stack YAML:
Your Pulumi stack YAML includes config values. Secret values are stored under asecure:
field and remain encrypted. -
Best Practices:
- Use
--secret
for anything sensitive. - Never edit stack YAML files directly to avoid malformed config or secret leakage.
- Store non-sensitive, environment-specific values as plain config; reserve secrets for credentials, tokens, etc.
- Use
Managing configuration effectively ensures safe, repeatable deployments and helps keep sensitive data secure.
Managing Secrets
Pulumi makes it simple to securely manage secrets, such as API keys and passwords, across your infrastructure deployments. Below is a step-by-step guide to managing secrets in Pulumi:
-
Initialize or Select a Stack:
Start withpulumi stack init <stack-name>
or select an existing stack usingpulumi stack select <stack-name>
. -
Choose a Secrets Provider (Optional):
By default, Pulumi encrypts secrets using its built-in provider. For enhanced security, you can specify a cloud-based provider or passphrase:
pulumi stack init dev --secrets-provider="passphrase"
Or for AWS KMS, Azure Key Vault, GCP KMS, etc. -
Set a Secret Configuration Value:
Use the--secret
flag to store sensitive data encrypted.
pulumi config set --secret dbPassword <your-password>
-
View All Configurations (Including Secrets):
Runpulumi config
to see all configuration values. Usepulumi config --show-secrets
to see decrypted values, if needed and you have access. -
Access Secrets in Your Program Code:
Use Pulumi's SDK to retrieve secrets safely in code. For example, in TypeScript:
const config = new pulumi.Config();
const dbPassword = config.requireSecret("dbPassword"); -
Rotate or Update Secrets:
When a secret changes, simply runpulumi config set --secret <key> <new-value>
to update. -
Remove a Secret:
Usepulumi config rm <key>
to delete a secret or configuration value from the stack. -
Review Secrets Storage in Stack Files:
In your stack's YAML file, encrypted secrets appear with asecure:
field, never as plain text. -
Best Practices:
- Always use
--secret
for sensitive data to ensure encryption. - Avoid putting secrets in version control.
- Rotate secrets regularly and restrict stack file access.
- Prefer cloud secrets managers for production environments.
- Always use
-
Troubleshooting Tip:
If you forget to mark a value as secret, overwrite it using--secret
and rotate credentials if necessary.
Securing secrets with Pulumi helps ensure safe deployments and simplified compliance audits.
Best Practices
Following best practices for Pulumi configuration and secrets ensures secure, maintainable, and scalable infrastructure deployment. Here’s a step-by-step approach:
-
Always Use the Pulumi CLI for Config & Secrets:
Set, modify, or remove configuration and secrets usingpulumi config
commands, not by manually editing YAML files. This helps prevent errors and unintentional leaks. -
Mark Sensitive Values as Secrets:
Any value containing credentials, tokens, or sensitive data must be set with--secret
to ensure encryption. For example:pulumi config set --secret dbPassword <value>
. -
Avoid Committing Secrets to Source Control:
Do not put plaintext secrets or credentials in your code or configuration files tracked by version control systems. -
Use Stacks to Separate Environments:
Create individual stacks (e.g.,dev
,staging
,prod
) for each deployment environment to keep resources and configurations isolated. -
Organize Configuration Access in Code:
Centralize configuration access in dedicated modules or functions. Avoid spreadingconfig.get()
andconfig.require()
calls throughout the codebase for cleaner, safer code. -
Utilize Refresh and State Management:
Regularly usepulumi refresh
or the-r
flag withpulumi up
to synchronize Pulumi’s state with real-world cloud resources, preventing drift between deployed and tracked infrastructure. -
Rotate and Audit Secrets Regularly:
Update secrets periodically and audit who has access to stack state files, encryption keys, and secrets managers. -
Leverage Cloud Secrets Managers for Production:
For production or team environments, consider using a cloud-backed secrets provider (like AWS KMS, Azure Key Vault, or GCP KMS) rather than Pulumi’s default passphrase provider. -
Restrict and Monitor Access:
Limit file and backend access to only those needing it. Set strong permissions on stack state storage, secrets manager credentials, and CI/CD service accounts. -
Keep Configuration Structured:
Use Pulumi’s--path
flag to maintain structured, object-like configuration values for cleaner code and easier management.
Adhering to these best practices reduces risk and helps ensure repeatable, secure Pulumi deployments across all your environments.
Troubleshooting
Even with careful configuration, you may encounter issues while using Pulumi for configuration and secrets management. Here’s a step-by-step guide to help identify and resolve common problems:
-
Diagnose Common Configuration Errors:
If you see “Missing required configuration variable” errors, check your Pulumi code forconfig.require()
orconfig.requireSecret()
calls. Usepulumi config
to list the current values, then set any missing configs with:
pulumi config set <key> <value>
For secrets, add--secret
. -
Invalid or Unknown Keys:
This happens if your configuration uses a key not recognized by Pulumi or your chosen provider. Double-check your spelling, namespaces, and formatting withpulumi config
and verify the key names in your Pulumi code and YAML files. -
Resolving Provider Plugin Issues:
If you encounter plugin version errors or “could not load plugin” messages, ensure that the required provider plugin version is installed. Run:
pulumi plugin install resource <provider> <version>
In CI environments, cache your plugins or install the required versions before running updates. -
Secrets Not Decrypting or “Decryption Failed”:
If secrets can’t be decrypted, your secrets provider’s credentials may be missing or incorrect. Ensure you’re using the same provider, passphrase, or configuration as when the secret was created. Change or recover your secrets provider settings if needed. -
Stack State Drifts or Stale Resources:
If Pulumi’s view of your infrastructure is out of sync with reality (for example, due to manual changes on the cloud provider), run:
pulumi refresh
This updates Pulumi’s state to match your actual resources. -
Troubleshooting Failed Resource Deletions:
If resources aren't deleted (like VPCs with dependencies), review the output for the specific errors. Manually remove external dependencies (e.g., attached resources) and try runningpulumi destroy
again, or remove resources manually in your cloud provider console followed bypulumi refresh
. -
Recover from Interrupted Updates:
If an update is interrupted (such as a CLI crash), you may see warnings about pending operations. First, runpulumi cancel
to clear any running tasks, thenpulumi refresh
to clean up and synchronize stack state. -
Fixing Invalid Configuration Format:
Typos or incorrect YAML formatting can cause configuration errors. Simplify your config file and re-introduce sections incrementally to pinpoint problems. Always ensure your configuration keys and types follow Pulumi’s standards. -
Best Practices for Prevention:
- Document required config variables in your README.
- Validate configuration values at program startup for early detection.
- Limit manual editing of stack YAML files to avoid syntax errors.
Systematic troubleshooting and good configuration hygiene will help you avoid and swiftly resolve most Pulumi issues.
Example: YAML Stack File
Pulumi stacks store configuration and secret values in YAML files. Understanding the structure of these files is crucial for properly managing both plain configuration and sensitive secrets. Here’s a step-by-step walkthrough:
-
Create or Locate Your Stack File:
Pulumi automatically creates a YAML stack file for each stack, named in the format<project>.<stack>.yaml
. For example:myproject.dev.yaml
. -
Understand the Structure:
The YAML file contains aconfig
section where key-value pairs are listed for all configuration and secrets:
config: myproject:region: us-west-2 myproject:dbPassword: secure: v1:uY1O8K...
-
Recognize Encrypted Secrets:
Values that appear as objects with asecure:
key are encrypted secrets. Regular values are stored as plain text. -
Edit with CLI, Not by Hand:
You should always set, update, or remove configuration values using the Pulumi CLI commands (likepulumi config set
), not by manually editing the YAML to prevent formatting issues and accidental exposure of secrets. -
Example Configuration Explained:
myproject:region: us-west-2
— a plain text configuration key and value.myproject:dbPassword:
withsecure:
— an encrypted secret value, unreadable until decrypted by Pulumi.
These YAML files provide a clear snapshot of your stack’s settings—but always interact with them through the Pulumi CLI for safe and secure configuration management.
Security Recommendations
Keeping your Pulumi configuration and secrets secure is critical for safe and compliant infrastructure-as-code management. Follow these step-by-step security recommendations:
-
Always Use the
--secret
Flag for Sensitive Data:
When storing passwords, API keys, or tokens, usepulumi config set --secret <key> <value>
to ensure encryption. -
Select a Trusted Secrets Provider:
Use cloud-backed secrets providers like AWS KMS, Azure Key Vault, or GCP KMS for production environments instead of the default passphrase provider where possible. -
Never Hardcode or Expose Secrets:
Avoid printing secrets to logs or storing them in source control, scripts, or stack files in plain text. -
Limit Access to Stack Files and State Storage:
Set strict permissions on where stack YAML and Pulumi state are stored. Restrict access to only necessary users and service accounts. -
Store Passphrases and Credentials Securely:
Save encryption passphrases or cloud secrets manager credentials in your organization’s dedicated secrets manager or CI/CD environment, not within code repositories. -
Regularly Rotate and Audit Secrets:
Change sensitive values periodically and review who can access stack files, encryption keys, and cloud provider secrets management consoles. -
Use Structured Configuration for Clarity:
Leverage Pulumi’s configuration paths and structured objects to keep secrets and config easily manageable but separate. -
Avoid Manual Edits:
Use Pulumi CLI commands for setting and updating configuration. Avoid hand-editing YAML files to prevent errors or data exposure. -
Monitor for Accidental Exposure:
Periodically scan your source code, stack files, and CI/CD logs for accidental leakage of secrets or configuration values. -
Document Your Security Practices:
Maintain clear internal documentation of how secrets and configuration should be managed and accessed in your organization.
Implementing these security recommendations will help you build a resilient and trustworthy automation pipeline with Pulumi.
Conclusion
Managing infrastructure securely and efficiently requires more than just automation — it demands a thoughtful approach to configuration and secrets handling. In this blog post, we walked through the Pulumi configuration system step by step, covering everything from setting up plain values to securely managing sensitive secrets across multiple environments.
Key Takeaways:
- Pulumi Configurations help you define environment-specific variables that drive dynamic and reusable infrastructure definitions.
- Secrets Management in Pulumi ensures you can encrypt and protect sensitive values like passwords, tokens, and API keys.
- Best Practices include using the CLI for secret management, separating stacks by environment, auto-rotating secrets, and limiting access to state files.
- Troubleshooting common errors like config mismatches, plugin issues, and failed decryptions can help keep your workflows clean and reliable.
- The YAML stack file represents a complete picture of your environment’s config and secrets — but should be modified with care.
- Following strong Security Recommendations promotes resilient deployments, minimizes risk, and ensures compliance with industry standards.
By taking full advantage of Pulumi's capabilities for configuration and secrets management, you empower your teams to build secure, auditable, and scalable infrastructure-as-code projects.
Thanks for joining us on this deep dive into Pulumi Configuration & Secrets. Happy automating, and may your environments stay secure and your deployments smooth!