https://pulumi.com logo
Title
w

worried-city-86458

05/13/2021, 9:22 AM
The automation api equivalent of the
pulumi up
cli seems to be roughly: • var stack = LocalWorkspace.CreateOrSelectStackAsync • stack.Workspace.InstallPluginAsync • stack.SetAllConfigAsync • stack.RefreshAsync // needed? • stack.UpAsync Would the equivalent of the
pulumi preview
cli be the following? (Not really in any examples?) • var stack = LocalWorkspace.CreateOrSelectStackAsync • stack.Workspace.InstallPluginAsync • stack.SetAllConfigAsync • stack.RefreshAsync // needed? • stack.PreviewAsync Are any of these steps not really needed like the refresh?
b

broad-dog-22463

05/13/2021, 10:16 AM
Hey @worried-city-86458 So Refresh is optional and at your discretion incase there are external changes - I usually run a refresh by habit as part of my workflow but I don't make changes outside of Pulumi - the preview steps look correct!
👍 1
w

worried-city-86458

05/13/2021, 10:39 AM
Not sure if I'm doing something wrong but I can't get preview to work:
Outputs:
  + ClusterName: "alpha-aws-eks-cluster-7f7a93a"
  + KubeConfig : output<string>

Resources:
    + 2 to create
    8 unchanged

System.NotSupportedException: Deserialization of types without a parameterless constructor, a singular parameterized constructor, or a parameterized constructor annotated with 'JsonConstructorAttribute' is not supported. Type
'Pulumi.Automation.Events.CancelEvent'. Path: $.cancelEvent | LineNumber: 0 | BytePositionInLine: 54.
     System.NotSupportedException: Deserialization of types without a parameterless constructor, a singular parameterized constructor, or a parameterized constructor annotated with 'JsonConstructorAttribute' is not supported. Type
     'Pulumi.Automation.Events.CancelEvent'.
     .
  at System.Text.Json.ThrowHelper.ThrowNotSupportedException(ReadStack& state, Utf8JsonReader& reader, NotSupportedException ex)
  at System.Text.Json.ThrowHelper.ThrowNotSupportedException_DeserializeNoConstructor(Type type, Utf8JsonReader& reader, ReadStack& state)
  at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
  at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
  at System.Text.Json.JsonPropertyInfo`1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
  at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
  at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
  at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
  at System.Text.Json.JsonSerializer.ReadCore[[TValue]](JsonConverter jsonConverter, Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
  at System.Text.Json.JsonSerializer.ReadValueCore[[TValue]](JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& state)
  at System.Text.Json.JsonSerializer.Deserialize[[TValue]](Utf8JsonReader& reader, JsonSerializerOptions options)
  at Pulumi.Automation.Serialization.Json.MapToModelJsonConverter`2.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options) in MapToModelJsonConverter.cs:16
  at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
  at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
  at System.Text.Json.JsonSerializer.ReadCore[[TValue]](JsonConverter jsonConverter, Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
  at System.Text.Json.JsonSerializer.ReadCore[[TValue]](Utf8JsonReader& reader, Type returnType, JsonSerializerOptions options)
  at System.Text.Json.JsonSerializer.Deserialize[[TValue]](String json, Type returnType, JsonSerializerOptions options)
  at System.Text.Json.JsonSerializer.Deserialize[[TValue]](String json, JsonSerializerOptions options)
  at Pulumi.Automation.Serialization.LocalSerializer.DeserializeJson[[T]](String content) in LocalSerializer.cs:30
  at Pulumi.Automation.Events.EventLogWatcher.ReadEventsOnce() in EventLogWatcher.cs:107
  at Pulumi.Automation.Events.EventLogWatcher.PollForEvents(CancellationToken externalCancellationToken) in EventLogWatcher.cs:82
  at Pulumi.Automation.Events.EventLogWatcher.AwaitPollingTask() in EventLogWatcher.cs:65
  at Pulumi.Automation.Events.EventLogWatcher.Stop() in EventLogWatcher.cs:40
  at Pulumi.Automation.Commands.LocalPulumiCmd.RunAsync(IEnumerable`1 args, String workingDir, IDictionary`2 additionalEnv, Action`1 onStandardOutput, Action`1 onStandardError, Action`1 onEngineEvent, CancellationToken cancellationToken)
     in LocalPulumiCmd.cs:40
  at Pulumi.Automation.Workspace.RunStackCommandAsync(String stackName, IEnumerable`1 args, Action`1 onStandardOutput, Action`1 onStandardError, Action`1 onEngineEvent, CancellationToken cancellationToken) in Workspace.cs:288
  at Pulumi.Automation.WorkspaceStack.RunCommandAsync(IEnumerable`1 args, Action`1 onStandardOutput, Action`1 onStandardError, Action`1 onEngineEvent, CancellationToken cancellationToken) in WorkspaceStack.cs:627
  at Pulumi.Automation.WorkspaceStack.PreviewAsync(PreviewOptions options, CancellationToken cancellationToken) in WorkspaceStack.cs:393
  at Pulumi.Automation.WorkspaceStack.PreviewAsync(PreviewOptions options, CancellationToken cancellationToken) in WorkspaceStack.cs:413
  at Pharos.Gemini.DeployCommand.OnExecuteAsync(CommandContext context, Settings settings) in DeployCommand.cs:80
  at Pharos.Gemini.AsyncCommandBase`1.ExecuteAsync(CommandContext context, TSettings settings) in AsyncCommandBase.cs:22
This is my dotnet/c# command handler:
protected override async Task<int> OnExecuteAsync(CommandContext context, Settings settings)
{
    var deployedResources = OrderedResources.Where(resource => settings.Resources.HasFlag(resource));
    foreach (var resource in deployedResources)
    {
        var info = ResourceInfoMap[resource];
        Logger.LogDebug($"Deploying {info.ProjectName}...");

        var stackName = $"{settings.Organization.ToLower()}/{settings.Environment.ToString().ToLower()}";
        var stackArgs = new InlineProgramArgs(info.ProjectName, stackName, PulumiFn.Create(ServiceProvider, info.StackType));
        var stack = await LocalWorkspace.CreateOrSelectStackAsync(stackArgs);

        foreach (var plugin in info.Plugins)
        {
            var pluginArgs = plugin.Split(" ");
            await stack.Workspace.InstallPluginAsync(pluginArgs[0], pluginArgs[1]);
        }

        var config = Config.ToTokens()
            .ToDictionary(entry => $"Gemini:{entry.Key}", entry => new ConfigValue(entry.Value?.ToString() ?? string.Empty));
        await stack.SetAllConfigAsync(config);

        if (settings.Refresh)
        {
            await stack.RefreshAsync(new RefreshOptions { OnStandardOutput = AnsiConsole.WriteLine });
        }

        if (settings.Preview)
        {
            var result = await stack.PreviewAsync(new PreviewOptions { OnStandardOutput = AnsiConsole.WriteLine });
            AnsiConsole.WriteLine("Summary:");
            foreach (var (key, value) in result.ChangeSummary)
            {
                AnsiConsole.WriteLine($"    {key}: {value}");
            }
        }
        else
        {
            var result = await stack.UpAsync(new UpOptions { OnStandardOutput = AnsiConsole.WriteLine });
            if (result.Summary.ResourceChanges != null)
            {
                AnsiConsole.WriteLine("Summary:");
                foreach (var (key, value) in result.Summary.ResourceChanges)
                {
                    AnsiConsole.WriteLine($"    {key}: {value}");
                }
            }
        }

        Logger.LogDebug($"Deployed {info.ProjectName}");
    }
    return 0;
}
b

bored-oyster-3147

05/13/2021, 1:24 PM
That looks like a bug. Though I'm surprised you're seeing it when you aren't subscribing to the
OnEngineEvent
delegate. Let me take a look
b

broad-dog-22463

05/13/2021, 1:50 PM
thanks @bored-oyster-3147!!!
🍻 1
b

bored-oyster-3147

05/13/2021, 2:57 PM
@worried-city-86458 mind sharing what version of automation API you're using? Are you by chance running on .NET 5?
b

broad-dog-22463

05/13/2021, 5:16 PM
(he's in NZ so it will be a wee while yet)
🙃 1
b

bored-oyster-3147

05/13/2021, 5:20 PM
Ha well I think I know what the issue is. If I'm right it will affect everyone that takes a dependency on
Pulumi.Automation
that is targetting .NET 5
w

worried-city-86458

05/13/2021, 6:18 PM
@bored-oyster-3147 Yes, I'm using dotnet 5.
Latest alpha of automation api
b

bored-oyster-3147

05/13/2021, 6:35 PM
Thanks for confirmation. I made an issue for this here: https://github.com/pulumi/pulumi/issues/7047 I'm busy today but can either get to it later or tomorrow
👍 1
p

prehistoric-coat-10166

05/14/2021, 5:05 AM
Hope you don't mind @bored-oyster-3147, had some free time so went ahead and created https://github.com/pulumi/pulumi/pull/7051 to fix this
🍺 2
w

worried-city-86458

05/14/2021, 5:21 AM
Might be worth bumping the dotnet sdk used to build to the latest (5.0.203)
b

broad-dog-22463

05/14/2021, 8:47 AM
We use 3.1 as that's the LTS atm @worried-city-86458
b

bored-oyster-3147

05/14/2021, 12:15 PM
Thanks @prehistoric-coat-10166 !
w

worried-city-86458

05/14/2021, 9:30 PM
@broad-dog-22463 fair enough; although my understanding is you can / should use the latest dotnet sdk to build things, since it has the latest sdk related fixes etc, but can still target previous frameworks with it. Normally you'd still install multiple runtimes to make sure you test with the required target runtime, so for example you could install dotnet 3.1 (separately) and dotnet 5.0 (via sdk) runtimes. Then your tests could multi-target dotnet 3.1/5.0 and issues like the above would be flushed out for users of dotnet 5.0.
b

broad-dog-22463

05/14/2021, 9:33 PM
I agree with you @worried-city-86458 and I’m in the middle of some improvements here
🍺 1