pulumi / pulumi-dotnet

.NET support for Pulumi
Apache License 2.0
26 stars 23 forks source link

Adding stack resource transformation to named value causes update to stop without returning error #291

Closed pierskarsenbarg closed 2 months ago

pierskarsenbarg commented 3 months ago

Describe what happened

When I add a resource transformation to a stack involving a NamedValue resource, it updates all the other resources in the stack, but just stops working. No error message, no panic and doesn't exit.

Sample program

using System;
using System.Collections.Generic;
using Pulumi;
using Pulumi.AzureNative.ApiManagement;
using Pulumi.AzureNative.ApiManagement.Inputs;
using Pulumi.AzureNative.Resources;

class MyStack : Stack
{
    public MyStack() : base(new StackOptions{ResourceTransformations = {MyTransformation}})
    {

        var resourceGroup = new ResourceGroup("apigmg-rg");

        var apimgm = new ApiManagementService("apimgm", new()
        {
            PublisherEmail = "piers@pulumi.com",
            PublisherName = "Piers",
            ResourceGroupName = resourceGroup.Name,
            Sku = new ApiManagementServiceSkuPropertiesArgs
            {
                Capacity = 0,
                Name = SkuType.Consumption
            },
            Tags = new InputMap<string>
            {
                {
                    "foo", "bar"
                }
            }
        });

        var nv = new NamedValue("nv", new()
        {
            DisplayName = "tenantNamedValueName",
            ResourceGroupName = resourceGroup.Name,
            ServiceName = apimgm.Name,
            Secret = false,
            Value = "tenantId"
        });
    }

    public static ResourceTransformationResult? MyTransformation(ResourceTransformationArgs args)
    {
        var tagProperty = args.Args.GetType().GetProperty("Tags");
        if (tagProperty != null) {
            var currentResourceTags = (InputMap<string>)tagProperty.GetValue(args.Args, null) ?? new InputMap<string>();
            currentResourceTags["env"] = "production";
            tagProperty.SetValue(args.Args, currentResourceTags, null);
            return new ResourceTransformationResult(args.Args, (CustomResourceOptions)args.Options);
        }
        return null;
    }

}

Log output

Logs here: https://gist.github.com/pierskarsenbarg/774a2f184f0abc33e52cfeaa98baeeff

I actually waited until 11:33 to hit cancel so the time gap between 11:27 and 11:33 is the program just hanging

Affected Resource(s)

No response

Output of pulumi about

CLI
Version      3.121.0
Go Version   go1.22.4
Go Compiler  gc

Plugins
KIND      NAME          VERSION
resource  azure-native  2.48.0
language  dotnet        unknown

Host
OS       darwin
Version  14.5
Arch     arm64

This project is written in dotnet: executable='/usr/local/share/dotnet/dotnet' version='8.0.201'

Current Stack: pierskarsenbarg/azure-namedvalue/dev

TYPE                                             URN
pulumi:pulumi:Stack                              urn:pulumi:dev::azure-namedvalue::pulumi:pulumi:Stack::azure-namedvalue-dev
pulumi:providers:azure-native                    urn:pulumi:dev::azure-namedvalue::pulumi:providers:azure-native::default_2_48_0
azure-native:resources:ResourceGroup             urn:pulumi:dev::azure-namedvalue::azure-native:resources:ResourceGroup::apigmg-rg
azure-native:apimanagement:ApiManagementService  urn:pulumi:dev::azure-namedvalue::azure-native:apimanagement:ApiManagementService::apimgm

Found no pending operations associated with dev

Backend
Name           pulumi.com
URL            https://app.pulumi.com/pierskarsenbarg
User           pierskarsenbarg
Organizations  pierskarsenbarg, karsenbarg, team-ce, gitlab-test-piers, demo
Token type     personal

Dependencies:
NAME                VERSION
Pulumi              3.64.0
Pulumi.AzureNative  2.48.0

Pulumi locates its logs in /var/folders/x8/cdd9j87s607fwpy0q62mfmmw0000gn/T/ by default

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

pierskarsenbarg commented 3 months ago

To add context, the Tag input is of type InputList<string> not InputMap<string> (the above code is taken from a customer), so there might be some deserialisation error that's being swallowed up

danielrbradley commented 3 months ago

Agreed, this looks most likely to be an issue in the runtime. Transferring to the platform team.

justinvp commented 2 months ago

To add context, the Tag input is of type InputList<string> not InputMap<string> (the above code is taken from a customer), so there might be some deserialisation error that's being swallowed up

Haven't dug into the details that causes it to "hang" when a value of the wrong type is specified. But I'd recommend guarding against this in any case, e.g. change:

if (tagProperty != null) {

to

if (tagProperty != null && tagProperty.PropertyType == typeof(InputMap<string>)) {