https://pulumi.com logo
Title
s

stocky-butcher-62635

04/08/2022, 3:26 PM
I added this to the
yml
file for the environment
RwbPulumiProject:ApplicationName: rwb
(Apparently each setting key must be of the form
a:b
The documentation page https://www.pulumi.com/docs/intro/concepts/config/ implies that the first bit is not required but apparently this is untrue.) Then I try to use it
Config config = new Pulumi.Config();
        string applicationName = config.Require("RwbPulumiProject:ApplicationName");
(Is is possible to rename the class from
MyStack
? My* really makes my skin crawl.) But then
C:\Work\Azure\RwbPulumiProject>pulumi up
Previewing update (dev)

View Live: <https://app.pulumi.com/jayallcock/RwbPulumiProject/dev/previews/a321fb21-a32a-4b5d-bd30-61c0e6e68c94>

     Type                 Name                  Plan       Info
 +   pulumi:pulumi:Stack  RwbPulumiProject-dev  create     1 error

Diagnostics:
  pulumi:pulumi:Stack (RwbPulumiProject-dev):
    error: Running program 'C:\Work\Azure\RwbPulumiProject\bin\Debug\netcoreapp3.1\RwbPulumiProject.dll' failed with an unhandled exception:
    System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
       at object RuntimeTypeHandle.CreateInstance(RuntimeType type, bool publicOnly, bool wrapExceptions, ref bool canBeCached, ref RuntimeMethodHandleInternal ctor, ref bool hasNoDefaultCtor)
       at object RuntimeType.CreateInstanceDefaultCtorSlow(bool publicOnly, bool wrapExceptions, bool fillCache)
       at object RuntimeType.CreateInstanceDefaultCtor(bool publicOnly, bool skipCheckThis, bool fillCache, bool wrapExceptions)
       at T Activator.CreateInstance<T>()
       at Task<int> Pulumi.Deployment+Runner.Pulumi.IRunner.RunAsync<TStack>(IServiceProvider serviceProvider)+() => { }
       at Task<int> Pulumi.Deployment+Runner.RunAsync<TStack>(Func<TStack> stackFactory) ---> Pulumi.Config+ConfigMissingException: Missing Required configuration variable 'RwbPulumiProject:RwbPulumiProject:ApplicationName'
        please set a value using the command `pulumi config set RwbPulumiProject:RwbPulumiProject:ApplicationName <value>`
       at string Pulumi.Config.RequireImpl(string key, string use, string insteadOf)
       at string Pulumi.Config.Require(string key)
       at new MyStack() in C:/Work/Azure/RwbPulumiProject/MyStack.cs:line 17
       --- End of inner exception stack trace ---



C:\Work\Azure\RwbPulumiProject>
b

billowy-army-68599

04/08/2022, 3:38 PM
@stocky-butcher-62635 the error is in the output, your config is reading:
string applicationName = config.Require("RwbPulumiProject:ApplicationName");
which means it needs to be set as:
pulumi config set RwbPulumiProject:RwbPulumiProject:ApplicationName
If you change your code to:
string applicationName = config.Require("ApplicationName");
it should work
regarding:
Is is possible to rename the class from MyStack? My* really makes my skin crawl.
Yes, of course it's possible. You'd just need to modify the async call
s

stocky-butcher-62635

04/08/2022, 3:42 PM
There's also an
azure-native:location: uksouth
but that appears to be impossible to read either with or without the prefix
g

great-queen-39697

04/08/2022, 3:54 PM
It's better to set the config values with the
pulumi config set
terminal command versus writing them in the YAML file directly. it's of the form
pulumi config set <key> <value>
. So, for your example, you would run
pulumi config set azure-native:location uksouth
(as an example, here's how someone set up an Azure Native C# Pulumi program)
s

stocky-butcher-62635

04/08/2022, 4:00 PM
but I can
but I can't read that value because it's not in the namespace of the project?
g

great-queen-39697

04/08/2022, 4:27 PM
You can set it in the YAML file, but the command line call ensures that it's formatted as expected, which is why I recommend it. In terms of not being able to read the value, how are you calling it?
b

billowy-army-68599

04/08/2022, 5:17 PM
@stocky-butcher-62635 you can read the provider config with this:
string awsNative = config.Require("aws-native");