Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PulumiFn.Create<TStack>() only accepts empty constructor stacks #374

Open
dsarosi opened this issue Nov 11, 2024 · 2 comments
Open

PulumiFn.Create<TStack>() only accepts empty constructor stacks #374

dsarosi opened this issue Nov 11, 2024 · 2 comments
Labels
area/automation-api kind/enhancement Improvements or new features

Comments

@dsarosi
Copy link

dsarosi commented Nov 11, 2024

Hello!

  • Vote on this issue by adding a 👍 reaction
  • If you want to implement this feature, comment to let us know (we'll work with you on design, scheduling, etc.)

Issue details

PulumiFn.Create() only works with empty Constructors. However, I wish to implement a web service that creates a stack per user. Thus the web app needs to pass parameters to the Stack via the constructor.

public class MyCustomStack: Stack
{
    public MyCustomStack(string parameter1, string parameter2)
    {
      ....
    }
}

var program = PulumiFn<MyCustomStack>("param1", "param2");

I cannot do the following as PulumiFn is marked as an internal class.

new PulumiFn<MyCustomStack>(() =>
            new MyCustomStack("param1", "param2"));

Affected area/feature

Automation API, but could also be implemented for the CLI.

@dsarosi dsarosi added kind/enhancement Improvements or new features needs-triage Needs attention from the triage team labels Nov 11, 2024
@justinvp justinvp added area/automation-api and removed needs-triage Needs attention from the triage team labels Nov 16, 2024
@justinvp
Copy link
Member

Thanks for the suggestion!

Seems reasonable to provide an overload of Create that could enable that, something like:

public static PulumiFn Create<TStack>(Func<TStack> stackFactory)
    where TStack : Stack

Usage:

var program = PulumiFn.Create(() => MyCustomStack("param1", "param2"));

In the meantime, as a workaround, you could use other overloads of PulumiFn.Create that aren't based on Pulumi.Stack.

@justinvp justinvp self-assigned this Nov 16, 2024
@justinvp justinvp added this to the 0.113 milestone Nov 16, 2024
@JasonWhall
Copy link
Contributor

@dsarosi - This works for me:

PulumiFn.Create(() => new MyCustomStack("param1", "param2");
Full example for completeness
  using System.Collections;
  using Pulumi.Automation;
  using Pulumi.Random;
  
  var program = PulumiFn.Create(() => new MyCustomStack("test", "example"));
  
  var programArgs = new InlineProgramArgs("test", "test-random", program)
  {
      EnvironmentVariables = new Dictionary<string, string?>
      {
          { "PULUMI_CONFIG_PASSPHRASE", "supersecret" }
      }
  };
  
  var stack = await LocalWorkspace.CreateOrSelectStackAsync(programArgs);
  
  await stack.UpAsync(new UpOptions
  {
      OnStandardOutput = Console.WriteLine,
      OnStandardError = Console.WriteLine
  });
  
  public class MyCustomStack : Stack
  {
      public MyCustomStack(string param1, string param2)
      {
          _ = new RandomPet($"{param1}-{param2}");
      }
  }  

@justinvp justinvp modified the milestones: 0.113, 0.114 Dec 3, 2024
@justinvp justinvp removed their assignment Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/automation-api kind/enhancement Improvements or new features
Projects
None yet
Development

No branches or pull requests

3 participants