https://pulumi.com logo
#dotnet
Title
# dotnet
b

breezy-salesmen-85534

11/19/2020, 8:05 AM
Hi Pulumi Community. I have a hard time testing Pulumi for C# and MS Azure. I have look at the unit testing example testing-unit-cs, but when I start debugging Pulumi is not able to read configuration for my pulumi stack. I am stuck in https://github.com/pulumi/pulumi/blob/394c91d7f6ab7a4096f4454827690a460f665433/sdk/dotnet/Pulumi/Deployment/Deployment_Config.cs#L33 because I have not set up environment variable PULUMI_CONFIG .How do I approach this?
I get an error saying
Copy code
Pulumi.RunException
Running program '/Applications/Rider.app/Contents/lib/ReSharperHost/TestRunner/netcoreapp2.0/ReSharperTestRunner64.dll' failed with an unhandled exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> Pulumi.Config+ConfigMissingException: Missing Required configuration variable 'Postrans:serviceBusSku'
	please set a value using the command `pulumi config set Postrans:serviceBusSku <value>`
   at Pulumi.Config.Require(String key)
   at Vipps.Postrans.Configuration.EnvironmentParameterProvider.ParseStackYaml() in /Users/andreas.dreyer.hysing/code/postrans-infra/src/Postrans.Infra/Postrans/Configuration/EnvironmentParameterProvider.cs:line 49
   at Vipps.Postrans.Configuration.EnvironmentParameterProvider.Create() in /Users/andreas.dreyer.hysing/code/postrans-infra/src/Postrans.Infra/Postrans/Configuration/EnvironmentParameterProvider.cs:line 27
   at Vipps.Postrans.Stacks.Postrans..ctor() in /Users/andreas.dreyer.hysing/code/postrans-infra/src/Postrans.Infra/Postrans/Postrans.cs:line 26
   --- End of inner exception stack trace ---
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean wrapExceptions, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& hasNoDefaultCtor)
   at System.RuntimeType.CreateInstanceDefaultCtorSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, Boolean wrapExceptions)
   at System.Activator.CreateInstance[T]()
   at Pulumi.Deployment.Runner.RunAsync[TStack]()
   at Pulumi.Deployment.TestAsync[TStack](IMocks mocks, TestOptions options)
   at Vipps.Postrans.Stacks.Tests.Configuration.EnvironmentParameterProviderTests.Test_DeserializeLAB() in /Users/andreas.dreyer.hysing/code/postrans-infra/src/Postrans.Infra/Postrans.Infra.Tests/Configuration/EnvironmentParameterProviderTests.cs:line 36
   at Xunit.Sdk.TestInvoker`1.<>c__DisplayClass48_1.<<InvokeTestMethodAsync>b__1>d.MoveNext() in C:\Dev\xunit\xunit\src\xunit.execution\Sdk\Frameworks\Runners\TestInvoker.cs:line 264
--- End of stack trace from previous location where exception was thrown ---
   at Xunit.Sdk.ExecutionTimer.AggregateAsync(Func`1 asyncAction) in C:\Dev\xunit\xunit\src\xunit.execution\Sdk\Frameworks\ExecutionTimer.cs:line 48
   at Xunit.Sdk.ExceptionAggregator.RunAsync(Func`1 code) in C:\Dev\xunit\xunit\src\xunit.core\Sdk\ExceptionAggregator.cs:line 90
t

tall-librarian-49374

11/19/2020, 8:11 AM
I think you’ll have pass the config if it’s required
b

breezy-salesmen-85534

11/19/2020, 8:25 AM
Thank you for Mikhail for an answer on such a short notice. 🙂 I was able to set up the variable for unit tests in C# code. I do
Copy code
string currentDirectory = System.Environment.CurrentDirectory;
string pulumiConfigAt = Path.GetFullPath(Path.Combine(currentDirectory, "..", "..", "..", "..", projectName));
            System.Environment.SetEnvironmentVariable("PULUMI_CONFIG", pulumiConfigAt);
It seems super manual, and prone for errors. but if it helps me with testing from Jetbrains rider then it is OK for me.
t

tall-librarian-49374

11/19/2020, 8:33 AM
You could also hard-code config values instead of reading from disk. We are tracking this in https://github.com/pulumi/pulumi/issues/4472 so feel free to add your API suggestions there.
b

breezy-salesmen-85534

11/19/2020, 8:35 AM
I will follow up on that thread…
Reading further down that function I can see Pulumi code reading as JSON. However my pulumi configuration is a different format; YAML. This leads me to think I misunderstood something.
Here is a short update. I was able to read Pulumi configuration, convert it to JSON and set PULUMI_CONFIG to the content of the JSON document. That solves the problem for me.
3 Views