How Do I Debug the Error: 'Missing Required Configuration Variable' in Pulumi?
Introduction
When working with Pulumi, you might encounter the error “Missing required configuration variable.” This error occurs when your Pulumi program tries to access a configuration value that hasn’t been set for your stack. In this guide, we’ll explain how to identify and resolve this common issue.
Step-by-Step Resolution
Step 1: Understand the Error
The error typically appears when:
- Your code uses
Config.require()
to get a configuration value - The specified configuration key hasn’t been set for your stack
Step 2: Identify the Missing Configuration
- Check your code for
Config.require()
calls:
const config = new pulumi.Config();
const requiredValue = config.require("myKey"); // This will throw an error if "myKey" isn't set
- List your current configuration values:
pulumi config
Step 3: Set the Missing Configuration
- Use the Pulumi CLI to set the required configuration value:
pulumi config set myKey myValue
- For configuration values in a specific namespace:
pulumi config set aws:region us-west-2
Common Scenarios and Solutions
Scenario 1: Provider Configuration
You are using the AWS provider and need to set the region.
Solution:
pulumi config set aws:region us-west-2
Scenario 2: Project Configuration
// This requires myapp:database to be set
const config = new pulumi.Config();
const dbName = config.require("database");
Solution:
pulumi config set database my-database-name
Scenario 3: Secret Configuration
// This requires myapp:dbPassword to be set as a secret
const config = new pulumi.Config();
const dbPassword = config.requireSecret("dbPassword");
Solution:
pulumi config set dbPassword mypassword --secret
Best Practices
- Use Default Values: When appropriate, use
Config.get()
with a default value instead ofConfig.require()
:
const config = new pulumi.Config();
const timeout = config.getNumber("timeout") ?? 30;
Document Required Configuration: Maintain a README with all required configuration values for your project.
Check Configuration Early: Validate all required configuration values at the start of your program to fail fast.
Summary
The “Missing required configuration variable” error is straightforward to resolve once you understand Pulumi’s configuration system. By following this guide, you can quickly identify missing configuration values and set them appropriately for your stack.
For more details, refer to:
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.