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

mysterious-australia-14256

06/09/2021, 12:10 PM
I'm having a bit of a struggle with the new AzureNative API and am presumably missing something obvious. I have created a new netcoreapp3.1 project and pasted the ServiceBus C# code from the Pulumi docs into the MyStack.cs file. I am presented with 2 errors, on the lines trying to set the Sku Name and Tier
Copy code
Sku = new AzureNative.ServiceBus.Inputs.SBSkuArgs
            {
                Name =  "Standard",
                Tier = "Standard",
            },
The error I get is of the type Cannot implicitly convert type 'string' to 'Pulumi.Input<Pulumi.AzureNative.ServiceBus.SkuName>' Can someone let me know what I am missing? Thanks Alan
t

tall-librarian-49374

06/09/2021, 12:14 PM
It looks like our example is wrong - you should pass an enum value instead of a plain string
SkuName.Standard
m

mysterious-australia-14256

06/09/2021, 1:21 PM
Ah thanks @tall-librarian-49374. How does this work with storing values in config files? Do the config class methods (e.g. RequireObject) support deserializing to an Enum or do I have to wrap things in an Enum.Parse?
I am a bit stuck here. Looking at the definition I see
Copy code
[EnumType]
public readonly struct SkuName : IEquatable<SkuName>
    {
        public static SkuName Basic { get; }
        public static SkuName Standard { get; }
        public static SkuName Premium { get; }
If I try to use Enum.Parse on this I get back an error saying "Type provided must be an Enum.". Do you know how I can convert the string "Standard" stored in a config file into something that SBSkuArgs will accept as a value for Name or Tier? I was trying
(SkuName)Enum.Parse(typeof(SkuName), "Standard")
This seems to work.. (configTier is a string variable read from the config file)
Tier = (SkuTier)(typeof(SkuTier).GetProperty(configTier )?.GetValue(null))!,
but is is a lot uglier than the AzureNextGen version which was simply
Tier = configTier
t

tall-librarian-49374

06/10/2021, 11:50 AM
That’s an interesting use case that we missed I’m afraid. I’m glad you found a workaround. Could you open an issue in https://github.com/pulumi/pulumi/issues describing this?
m

mysterious-australia-14256

06/10/2021, 12:12 PM
🙏 1