1. Answers
  2. Debugging 'Missing Required Configuration Variable' Error in Pulumi

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:

  1. Your code uses Config.require() to get a configuration value
  2. The specified configuration key hasn’t been set for your stack

Step 2: Identify the Missing Configuration

  1. 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
  1. List your current configuration values:
pulumi config

Step 3: Set the Missing Configuration

  1. Use the Pulumi CLI to set the required configuration value:
pulumi config set myKey myValue
  1. 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

  1. Use Default Values: When appropriate, use Config.get() with a default value instead of Config.require():
const config = new pulumi.Config();
const timeout = config.getNumber("timeout") ?? 30;
  1. Document Required Configuration: Maintain a README with all required configuration values for your project.

  2. 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 up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up