pulumi / pulumi

Pulumi - Infrastructure as Code in any programming language šŸš€
https://www.pulumi.com
Apache License 2.0
20.49k stars 1.06k forks source link

Setting default values on non-primitive types does not fail schema validation. #16497

Open iwahbe opened 1 week ago

iwahbe commented 1 week ago

What happened?

This was raised internally: https://pulumi.slack.com/archives/C045N7FDGHW/p1719386921192569.

Example

To summarize:

A bridged provider maintainer set a default value (via env) for a provider configuration value.

                "defaultInfo": {
                    "environment": [
                        "GRAFANA_CLOUD_ACCESS_POLICY_TOKEN"
                    ]
                },

At minimum, this generates invalid C# code:

https://github.com/pulumiverse/pulumi-grafana/pull/175/files#diff-95b29f66b24fa6371a2f80b462b9bf6222b7ae1a30b703b88d47d207b2c49e2aR119

The code doesn't type check:

Error: /home/runner/work/pulumi-grafana/pulumi-grafana/sdk/dotnet/Config/Config.cs(119,127): error CS0019: Operator '??' cannot be applied to operands of type 'ImmutableArray<string>' and 'string' [/home/runner/work/pulumi-grafana/pulumi-grafana/sdk/dotnet/Pulumiverse.Grafana.csproj]

Output of pulumi about

NA. Codegen was on v3.118.0.

Additional context

Waiting until we check if SDKs compile is confusing to users and might not catch the bug until runtime for a python based provider. Pulumi should fail fast when invalid default values are supplied and give the user an actionable error message.

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

justinvp commented 6 days ago

For better or worse, we should start with a warning. We've run into issues when we immediately made things stricter with an error (e.g. https://github.com/pulumi/pulumi/issues/14631).