docs icon indicating copy to clipboard operation
docs copied to clipboard

Update Pulumi configuration page to show simple but complete examples

Open toriancrane opened this issue 1 year ago • 0 comments

Specifically referring to the "Accessing Configuration from Code" section, unless you are familiar with a specific programming language, it is not very clear how to actually do this in code. For example, the C# code example shows the following:

var config = new Pulumi.Config();
var name = config.Require("name");
var lucky = config.GetInt32("lucky") ?? 42;
var secret = config.RequireSecret("secret")

When what it should really show is something like this:

using Pulumi;
using System.Threading.Tasks;
using System.Collections.Generic;

class Program
{
    static async Task<int> Main(string[] args)
    {
        return await Deployment.RunAsync(() =>
        {
            // Import the configuration values
            var config = new Config();

            // Retrieve the value of "myEnvironment"
            var myValue = config.Get("myEnvironment") ?? "default-value";

            // Return a dictionary of outputs
            return new Dictionary<string, object?>
            {
                ["Value"] = myValue
            };
        });
    }
}

toriancrane avatar Jan 31 '24 13:01 toriancrane