1. How to configure a typed object hierarchy in a project?

    TypeScript

    Your requirement seems to be about creating a hierarchical project configuration using Pulumi. You can structure your stack configurations hierarchically where each level in the hierarchy is typed.

    This provides a way to manage configurations for different environments (like staging, production) more effectively.

    Here's an illustration using TypeScript:

    import * as pulumi from "@pulumi/pulumi"; const config = new pulumi.Config(); // Define a hierarchy structure in configuration. // You can define it in Pulumi.<stack-name>.yaml file. // // config: // db: // username: pulumi // password: pulumi$1234 // Access the configuration using config object. const dbConfig = config.requireObject("db"); // At this point, the dbConfig is a plain JavaScript object. // To provide strong typings, define an interface matching the shape of the configuration. interface DbConfig { username: string; password: string; } // Cast the JavaScript object to the strongly typed interface. const typedDbConfig = dbConfig as DbConfig; // Use the typed configuration in your application. console.log(`Database username is ${typedDbConfig.username}`);

    In the Pulumi.<stack-name>.yaml file, you can add your configuration:

    config: db: username: pulumi password: pulumi$1234

    The username and password are then read from your stack configuration, and used in your Pulumi program. By defining the interface DbConfig, you ensure that the configuration object adheres to the structure you expect. This is how you model hierarchical and typed configurations in Pulumi.

    Remember to store sensitive data like password as secrets in your Pulumi stack configuration to avoid exposing them in plain text.

    Using these hierarchical and typed configurations, you can manage complex configurations cleanly and avoid potential runtime errors due to misconfigured properties.