pulumi / pulumi-azure-native

Azure Native Provider
Apache License 2.0
129 stars 35 forks source link

cdn.SecurityPolicyTypeWebApplicationFirewall can't be directly used in corresponding field #3433

Open devnev opened 4 months ago

devnev commented 4 months ago

What happened?

Defining a cdn.SecurityPolicy, the Parameters.Type field (type StringInput) should be populated with the value "WebApplicationFirewall", for which there is a const cdn.SecurityPolicyTypeWebApplicationFirewall - however this has type cdn.SecurityPolicyType which doesn't implement the methods for a StringInput - as far as I can tell this is something most other enums do. As an aside, having fields with enum-y values be StringInputs instead of the enum type makes it hard to discover that there is an enum type.

Example

resourceGroup, err := resources.NewResourceGroup(ctx, "resource-group", &resources.ResourceGroupArgs{
    ResourceGroupName: pulumi.StringPtr("rg1"),
    Location: pulumi.StringPtr("westus2"),
})
cdnProfile, err := cdn.NewProfile(ctx, "cdn-profile", &cdn.ProfileArgs{
    ResourceGroupName: resourceGroup.Name,
    ProfileName:       pulumi.String("cdnprofile"),
    Location:          pulumi.String("global"),
    Sku: cdn.SkuArgs{Name: cdn.SkuName_Standard_AzureFrontDoor},
})
securityPolicy, err := cdn.NewSecurityPolicy(ctx, "security-policy", &cdn.SecurityPolicyArgs{
    ResourceGroupName:  resourceGroup.Name,
    ProfileName:        cdnProfile.Name,
    SecurityPolicyName: pulumi.String("securitypolicy"),
    Parameters: cdn.SecurityPolicyWebApplicationFirewallParametersArgs{
        Type: pulumi.String(cdn.SecurityPolicyTypeWebApplicationFirewall), //<--
    },
})

The pulumi.String() call in the above example seems like it shouldn't be necessary

Output of pulumi about

CLI
Version      3.122.0
Go Version   go1.22.4
Go Compiler  gc

Host
OS       darwin
Version  14.5
Arch     x86_64

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).

mikhailshilkov commented 2 months ago

This is what we call "a relaxed enum", Azure specs define it like this:

        "type": {
          "description": "The type of the Security policy to create.",
          "enum": [
            "WebApplicationFirewall"
          ],
          "type": "string",
          "x-ms-enum": {
            "name": "SecurityPolicyType",
            "modelAsString": true
          }
        }

You can see that they instruct us to accept any string in this property with "modelAsString": true. We generate a helper enum, but don't require its usage.