pulumi-azure-native icon indicating copy to clipboard operation
pulumi-azure-native copied to clipboard

Not updated example of the C# code for Azure API Management

Open paf-dev opened this issue 1 year ago • 5 comments

What happened?

There is documentation about the class that is responsible for Azure API Management. The link: https://www.pulumi.com/registry/packages/azure-native/api-docs/apimanagement/api/ The C# example has initialization of the Protocols property like that

    var api = new AzureNative.ApiManagement.Api("api", new()
    {
        ...
        Protocols = new[]
        {
            "https",
            "http",
        },
        ...
    });

The problem is that Protocols has type of List<Union<string, Pulumi.AzureNative.ApiManagement.Protocol>> Also, I can't find any documentation about the usage of the Union type.

Example

No

Output of pulumi about

No

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

paf-dev avatar Feb 28 '24 09:02 paf-dev

Hi @paf-dev, the Union type is defined in the shared dotnet SDK here

The reason the code example doesn't explicitly instantiate it is that Union provides implicit conversions link, so the compiler will automatically convert those Strings into Union<string, Pulumi.AzureNative.ApiManagement.Protocol>s

mjeffryes avatar Feb 28 '24 21:02 mjeffryes

The reason the code example doesn't explicitly instantiate it is that Union provides implicit conversions link, so the compiler will automatically convert those Strings into Union<string, Pulumi.AzureNative.ApiManagement.Protocol>s

I also thought about implicit conversion, but dotnet build still says the following

error CS0029: Cannot implicitly convert type 'string[]' to 'Pulumi.InputList<Pulumi.Union<string, Pulumi.AzureNative.ApiManagement.Protocol>>

paf-dev avatar Feb 29 '24 12:02 paf-dev

@paf-dev did you solve this? Getting the same issue. Do you really mean this Protocols = ["https"] or Protocols = new InputList<Union<string, Protocol>>() {"https"}

TheRubble avatar Mar 14 '24 13:03 TheRubble

@TheRubble Here is what I used in my code to make it work

Protocols = new Union<string, Protocol>[]
{
   Protocol.Https
},

Probably not the best, but at least it worked and I was not blocked by the service that actually takes my company's money for that

paf-dev avatar Mar 14 '24 14:03 paf-dev

["https"]

["https"] this will work then :-)

TheRubble avatar Mar 14 '24 14:03 TheRubble

Since there seems to be a working solution, I'll close this issue, but please feel free to re-open if necessary.

thomas11 avatar May 10 '24 10:05 thomas11